Advertisement
Guest User

Ext.ux.grid.FlagMark

a guest
Jul 24th, 2014
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Ext.ux.grid.FlagMark
  3.  * This little column component will allow the addition of marker flags in grid rows. Pass in an array of flag definitions including their dataIcon, iconCls, and a hideIndex and they will configure themselves
  4.  *
  5.  * Example:
  6.  *    ...
  7.  *    columns: [
  8.  *
  9.  *    ...
  10.  *  {
  11.  *      xtype: 'gridflagcol',
  12.  *      flags: [{
  13.  *          dataIcon : '*',
  14.  *          iconCls  : 'favourite',
  15.  *          hideIndex: 'hideFavouriteFlag',
  16.  *              qtip  : 'Marked as a favourite'
  17.  *      },{
  18.  *          dataIcon : 'x',
  19.  *          iconCls  : 'flag',
  20.  *          hideIndex: 'hideFlaggedFlag',
  21.  *          qtip  : 'Marked as flagged'
  22.  *      }]
  23.  *  }
  24.  *    ...
  25.  *    ]
  26.  *    ...
  27.  *
  28.  */
  29. Ext.define( 'Ext.ux.grid.FlagMark', {
  30.     extend       : 'Ext.grid.column.Column',
  31.     alias        : 'widget.gridflagcol',
  32.     eventPrefix  : 'flag',
  33.     eventSelector: '.' + Ext.baseCSSPrefix + 'grid-flag-hd',
  34.     bodySelector : '.' + Ext.baseCSSPrefix + 'grid-flag-body',
  35.     isColumn     : true,
  36.     menuDisabled : true,
  37.     sortable     : false,
  38.     width        : 0,
  39.     align        : 'right',
  40.     cls          : 'grid-flag-col',
  41.     hideMode     : 'display',
  42.     /**
  43.      * @cfg {String} tplRow Template for flags
  44.      * @private
  45.      */
  46.     tplRow       : '\
  47.         <tpl for="flags">\
  48.             <div class="ux-row-flag-item {cls} <tpl if="text">ux-row-flag-text</tpl>" style="{hide}{style}">\
  49.                 <span class="ux-flag-cell-triangle"><i <tpl if="qtip">data-tooltip="{qtip}"</tpl> data-icon="{dataIcon}"></i></span>\
  50.             </div>\
  51.         </tpl>',
  52.     init         : function(){
  53.         var me = this;
  54.  
  55.         me.callParent( arguments );
  56.     },
  57.  
  58.     initRenderData: function(){
  59.  
  60.         var me = this;
  61.  
  62.         me.grid = me.up( 'gridpanel' );
  63.         me.tpl = me.tpl || me.processFlags( me.flags );
  64.  
  65.         me.grid.on( 'destroy', me.clearListeners, me );
  66.  
  67.         // setup renderer
  68.         if (!me.renderer){
  69.             me.renderer = Ext.bind( function( value, cell, record, row, col, store ){
  70.                 cell.tdCls += (cell.tdCls ? ' ' : '') + 'ux-grid-flag';
  71.                 return this.tpl.apply( this.getData( value, cell, record, row, col, store ) );
  72.             }, me );
  73.         }
  74.  
  75.         // cancel click
  76.         if (true === me.keepSelection){
  77.             me.grid.on( 'beforeitemmousedown', function( view, record, item, index, e, options ){
  78.                 return !this.getAction( e );
  79.             }, me );
  80.         }
  81.  
  82.         return this.callParent( arguments );
  83.  
  84.     },
  85.  
  86.     /**
  87.      * Returns data to apply to template. Override this if needed.
  88.      * @param {Mixed} value
  89.      * @param {Object} cell object to set some attributes of the grid cell
  90.      * @param {Ext.data.Record} record from which the data is extracted
  91.      * @param {Number} row row index
  92.      * @param {Number} col col index
  93.      * @param {Ext.data.Store} store object from which the record is extracted
  94.      * @return {Object} data to apply to template
  95.      */
  96.     getData: function( value, cell, record, row, col, store ){
  97.         return record.data || {};
  98.     },
  99.  
  100.     processFlags: function( flags, template ){
  101.         var fls = [], me = this;
  102.  
  103.         // actions loop
  104.         Ext.each( flags, function( f, i ){
  105.  
  106.             if (f.flagId && 'function' === typeof (f.callback || f.cb)){
  107.                 me.callbacks = me.callbacks || {};
  108.                 me.callbacks[f.flagId] = f.callback || f.cb;
  109.             }
  110.  
  111.             // data for intermediate template
  112.             var o = {
  113.                 cls     : f.iconIndex ? '{' + f.iconIndex + '}' : (f.iconCls ? f.iconCls : ''),
  114.                 dataIcon: f.iconIndex ? '{' + f.iconIndex + '}' : (f.dataIcon ? f.dataIcon : ''),
  115.                 qtip    : f.qtipIndex ? '{' + f.qtipIndex + '}' : (f.tooltip || f.qtip ? f.tooltip || f.qtip : ''),
  116.                 text    : f.textIndex ? '{' + f.textIndex + '}' : (f.text ? f.text : ''),
  117.                 hide    : f.hideIndex ? '<tpl if="' + f.hideIndex + '">' + ('display' === this.hideMode ? 'display:none' : 'visibility:hidden') + ';</tpl>' : (f.hide ? ('display' === this.hideMode ? 'display:none' : 'visibility:hidden;') : ''), align: f.align || 'right',
  118.                 style   : f.style ? f.style : ''
  119.             };
  120.             fls.push( o );
  121.  
  122.         }, me );
  123.  
  124.         var xt = new Ext.XTemplate( template || me.tplRow );
  125.         return new Ext.XTemplate( xt.apply( {flags: fls} ) );
  126.  
  127.     }
  128. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement