1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    16
    Vote Rating
    0
    corneadoug is on a distinguished road

      0  

    Default Conditional configuration for Components

    Conditional configuration for Components


    Hi,

    I'm creating this thread to talk about conditional configuration for components.

    Even if in someway it breaks a bit the MVC style, I think being able to do something like:

    {
    xtype: 'label',
    if (case) {text: 'MycaseText'}
    else {text: 'MycaseText'}
    }

    would be freaking awesome!

    The reason is:

    When you build your UI, you end up with a big stack of components, all of them in a specific order and in specific containers.

    It may happen sometimes that you have restrictions modifying your component needs.

    I will take my case: User restrictions

    An administrator can update, but not a basic User for example. Of course it is simple to hide some button, but when it comes to: not have a specific column in a grid, not have the editcell plugin of the grid, change a component type for that user etc....

    It become quite difficult to have components using xtype in one another, and we finish creating most of them before with the conditions, and in the end a lot of copy of the same code with few changes.

    Now let's see what you thinks, and if some of you have some tricks or good ideas

  2. #2
    Sencha User existdissolve's Avatar
    Join Date
    Jan 2010
    Location
    Kansas
    Posts
    522
    Vote Rating
    85
    existdissolve is just really nice existdissolve is just really nice existdissolve is just really nice existdissolve is just really nice existdissolve is just really nice

      0  

    Default


    For your first example, you could easily do that anyway with a ternary operator.

    PHP Code:
    {
       
    xtype'label',
       
    text: case=='something' 'MycaseText' 'Some other text'

    More more intricate stuff, what I've done before is to do conditional stuff in initComponent. For example, with grid columns, sometimes I'll do this:

    PHP Code:
    Ext.define('MyGrid', {
       
    extend'Ext.grid.Panel',
       
    title'My Grid',
       
    initComponent: function() {
          var 
    me this
                
    columns = [],
                
    column;
          switch( 
    somevalue ) {
              case 
    'condition1'
                 
    column = { ... };
                 
    columns.pushcolumn );
                 ...
                 break;
              case 
    'condition2':
                 
    column = { ... };
                 
    columns.pushcolumn );
                 ...
          }
          
    Ext.applyIf(me, {
             
    columnscolumns
          
    });
          
    me.callParentarguments )
       }

    Of course, in the case of really specific grid configurations, it's probably a lot easier to build the correct config outside of the grid definition, and then just reconfigure it with the correct one.

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi