Changeset 1777230
- Timestamp:
- 11/28/2017 08:18:00 PM (8 years ago)
- File:
-
- 1 edited
-
widget-display-conditions/trunk/js/main.js (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
widget-display-conditions/trunk/js/main.js
r1777132 r1777230 82 82 var $condition = jQuery( this ).closest( '.condition' ); 83 83 84 $param = $condition.find( '.param select' ); 85 $operator = $condition.find( '.operator select' ); 86 $value = $condition.find( '.value select' ); 87 88 $condition.addClass( 'loading' ); 89 90 WDC.getParamItems( $param.val(), function( items ) 91 { 92 WDC.populateDropdown( $operator.empty(), items.operators ); 93 WDC.populateDropdown( $value.empty(), items.values ); 94 95 if ( $value.next( '.select2' ).length ) 96 { 97 $value.select2( 'destroy' ); 98 } 99 100 if ( $value.find( 'option' ).length >= _this.options.applySearchOptionLength ) 101 { 102 $value.select2(); 103 } 104 105 $condition.removeClass( 'loading' ); 106 }); 84 _this.setParamItems( $condition ); 107 85 }); 108 86 … … 233 211 * 234 212 * @param jQuery|DOMObject elem The <select> or <optgroup> element. 235 * @param array items213 * @param array|object items 236 214 * 237 215 * Creates 2 options … … 296 274 297 275 /** 298 * @param string 276 * @param string Param name. 299 277 */ 300 278 WDC.getParamItems = function( param, complete ) … … 319 297 320 298 /** 321 * @param string| object299 * @param string|array One param or multiple params. 322 300 */ 323 301 WDC.loadParamItems = function( param, complete ) … … 347 325 WDC.prototype.getConditionGroup = function( id ) 348 326 { 349 return this.$elem.find( '.condition-group' ).filter( function()327 return this.$elem.find( '.condition-group' ).filter( function() 350 328 { 351 329 return jQuery( this ).data( 'id' ) == id; … … 405 383 WDC.prototype.getCondition = function( id ) 406 384 { 407 return this.$elem.find( '.condition' ).filter( function()385 return this.$elem.find( '.condition' ).filter( function() 408 386 { 409 387 return jQuery( this ).data( 'id' ) == id; … … 448 426 $condition.addClass( 'loading' ); 449 427 428 this.setParamItems( $condition, condition ); 429 430 // Adds to group 431 432 var $group = this.getConditionGroup( groupId ); 433 434 if ( typeof index === 'undefined' ) 435 { 436 index = $group.find( '.condition' ).length; 437 }; 438 439 if ( index <= 0 ) 440 { 441 $group.find( '.conditions' ).prepend( $condition ); 442 } 443 444 else if ( index >= $group.find( '.condition' ).length ) 445 { 446 $group.find( '.conditions' ).append( $condition ); 447 } 448 449 else 450 { 451 $condition.insertBefore( $group.find( '.condition' ).eq( index ) ); 452 }; 453 454 this.$elem.trigger( 'wdc/conditionAdded', [ $condition ] ); 455 }; 456 457 WDC.prototype.removeCondition = function( conditionId ) 458 { 459 var $condition = this.$elem.find( '.condition' ).filter( function() 460 { 461 return jQuery( this ).data( 'id' ) == conditionId; 462 }); 463 464 var $group = $condition.closest( '.condition-group' ); 465 466 var index = $condition.index(); 467 468 $condition.remove(); 469 470 this.$elem.trigger( 'wdc/conditionRemoved', [ $condition, index, $group ] ); 471 }; 472 473 WDC.prototype.setParamItems = function( $condition, data ) 474 { 475 data = jQuery.extend( 476 { 477 operator : '', 478 value : '' 479 }, data ); 480 481 // Loads param related data 482 483 $param = $condition.find( '.param select' ); 484 $operator = $condition.find( '.operator select' ); 485 $value = $condition.find( '.value select' ); 486 487 $condition.addClass( 'loading' ); 488 489 var _this = this; 490 450 491 WDC.getParamItems( $param.val(), function( items ) 451 492 { 452 WDC.populateDropdown( $operator.empty(), items.operators, condition.operator );453 WDC.populateDropdown( $value.empty(), items.values, condition.value );493 WDC.populateDropdown( $operator.empty(), items.operators, data.operator ); 494 WDC.populateDropdown( $value.empty(), items.values, data.value ); 454 495 455 496 if ( $value.next( '.select2' ).length ) … … 465 506 $condition.removeClass( 'loading' ); 466 507 }); 467 468 // Adds to group469 470 var $group = this.getConditionGroup( groupId );471 472 if ( typeof index === 'undefined' )473 {474 index = $group.find( '.condition' ).length;475 };476 477 if ( index <= 0 )478 {479 $group.find( '.conditions' ).prepend( $condition );480 }481 482 else if ( index >= $group.find( '.condition' ).length )483 {484 $group.find( '.conditions' ).append( $condition );485 }486 487 else488 {489 $condition.insertBefore( $group.find( '.condition' ).eq( index ) );490 };491 492 this.$elem.trigger( 'wdc/conditionAdded', [ $condition ] );493 };494 495 WDC.prototype.removeCondition = function( conditionId )496 {497 var $condition = this.$elem.find( '.condition' ).filter( function()498 {499 return jQuery( this ).data( 'id' ) == conditionId;500 });501 502 var $group = $condition.closest( '.condition-group' );503 504 var index = $condition.index();505 506 $condition.remove();507 508 this.$elem.trigger( 'wdc/conditionRemoved', [ $condition, index, $group ] );509 508 }; 510 509
Note: See TracChangeset
for help on using the changeset viewer.