Plugin Directory

Changeset 1777230


Ignore:
Timestamp:
11/28/2017 08:18:00 PM (8 years ago)
Author:
MaartenM
Message:
  • UI: created function for loading param related data into condition
File:
1 edited

Legend:

Unmodified
Added
Removed
  • widget-display-conditions/trunk/js/main.js

    r1777132 r1777230  
    8282            var $condition = jQuery( this ).closest( '.condition' );
    8383
    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 );
    10785        });
    10886
     
    233211     *
    234212     * @param jQuery|DOMObject elem The <select> or <optgroup> element.
    235      * @param array items
     213     * @param array|object items
    236214     *
    237215     * Creates 2 options
     
    296274
    297275    /**
    298      * @param string
     276     * @param string Param name.
    299277     */
    300278    WDC.getParamItems = function( param, complete )
     
    319297
    320298    /**
    321      * @param string|object
     299     * @param string|array One param or multiple params.
    322300     */
    323301    WDC.loadParamItems = function( param, complete )
     
    347325    WDC.prototype.getConditionGroup = function( id )
    348326    {
    349         return  this.$elem.find( '.condition-group' ).filter( function()
     327        return this.$elem.find( '.condition-group' ).filter( function()
    350328        {
    351329            return jQuery( this ).data( 'id' ) == id;
     
    405383    WDC.prototype.getCondition = function( id )
    406384    {
    407         return  this.$elem.find( '.condition' ).filter( function()
     385        return this.$elem.find( '.condition' ).filter( function()
    408386        {
    409387            return jQuery( this ).data( 'id' ) == id;
     
    448426        $condition.addClass( 'loading' );
    449427
     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
    450491        WDC.getParamItems( $param.val(), function( items )
    451492        {
    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 );
    454495
    455496            if ( $value.next( '.select2' ).length )
     
    465506            $condition.removeClass( 'loading' );
    466507        });
    467 
    468         // Adds to group
    469 
    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         else
    488         {
    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 ] );
    509508    };
    510509
Note: See TracChangeset for help on using the changeset viewer.