Filter.js
上传用户:dawnssy
上传日期:2022-08-06
资源大小:9345k
文件大小:6k
源码类别:

JavaScript

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.1.0  * Copyright(c) 2006-2009 Ext JS, LLC  * licensing@extjs.com  * http://www.extjs.com/license  */ Ext.namespace('Ext.ux.grid.filter');
  2. /** 
  3.  * @class Ext.ux.grid.filter.Filter
  4.  * @extends Ext.util.Observable
  5.  * Abstract base class for filter implementations.
  6.  */
  7. Ext.ux.grid.filter.Filter = Ext.extend(Ext.util.Observable, {
  8.     /**
  9.      * @cfg {Boolean} active
  10.      * Indicates the initial status of the filter (defaults to false).
  11.      */
  12.     active : false,
  13.     /**
  14.      * True if this filter is active.  Use setActive() to alter after configuration.
  15.      * @type Boolean
  16.      * @property active
  17.      */
  18.     /**
  19.      * @cfg {String} dataIndex 
  20.      * The {@link Ext.data.Store} dataIndex of the field this filter represents.
  21.      * The dataIndex does not actually have to exist in the store.
  22.      */
  23.     dataIndex : null,
  24.     /**
  25.      * The filter configuration menu that will be installed into the filter submenu of a column menu.
  26.      * @type Ext.menu.Menu
  27.      * @property
  28.      */
  29.     menu : null,
  30.     /**
  31.      * @cfg {Number} updateBuffer
  32.      * Number of milliseconds to wait after user interaction to fire an update. Only supported 
  33.      * by filters: 'list', 'numeric', and 'string'. Defaults to 500.
  34.      */
  35.     updateBuffer : 500,
  36.     constructor : function (config) {
  37.         Ext.apply(this, config);
  38.             
  39.         this.addEvents(
  40.             /**
  41.              * @event activate
  42.              * Fires when an inactive filter becomes active
  43.              * @param {Ext.ux.grid.filter.Filter} this
  44.              */
  45.             'activate',
  46.             /**
  47.              * @event deactivate
  48.              * Fires when an active filter becomes inactive
  49.              * @param {Ext.ux.grid.filter.Filter} this
  50.              */
  51.             'deactivate',
  52.             /**
  53.              * @event serialize
  54.              * Fires after the serialization process. Use this to attach additional parameters to serialization
  55.              * data before it is encoded and sent to the server.
  56.              * @param {Array/Object} data A map or collection of maps representing the current filter configuration.
  57.              * @param {Ext.ux.grid.filter.Filter} filter The filter being serialized.
  58.              */
  59.             'serialize',
  60.             /**
  61.              * @event update
  62.              * Fires when a filter configuration has changed
  63.              * @param {Ext.ux.grid.filter.Filter} this The filter object.
  64.              */
  65.             'update'
  66.         );
  67.         Ext.ux.grid.filter.Filter.superclass.constructor.call(this);
  68.         this.menu = new Ext.menu.Menu();
  69.         this.init(config);
  70.         if(config && config.value){
  71.             this.setValue(config.value);
  72.             this.setActive(config.active !== false, true);
  73.             delete config.value;
  74.         }
  75.     },
  76.     /**
  77.      * Destroys this filter by purging any event listeners, and removing any menus.
  78.      */
  79.     destroy : function(){
  80.         if (this.menu){
  81.             this.menu.destroy();
  82.         }
  83.         this.purgeListeners();
  84.     },
  85.     /**
  86.      * Template method to be implemented by all subclasses that is to
  87.      * initialize the filter and install required menu items.
  88.      * Defaults to Ext.emptyFn.
  89.      */
  90.     init : Ext.emptyFn,
  91.     
  92.     /**
  93.      * Template method to be implemented by all subclasses that is to
  94.      * get and return the value of the filter.
  95.      * Defaults to Ext.emptyFn.
  96.      * @return {Object} The 'serialized' form of this filter
  97.      * @methodOf Ext.ux.grid.filter.Filter
  98.      */
  99.     getValue : Ext.emptyFn,
  100.     
  101.     /**
  102.      * Template method to be implemented by all subclasses that is to
  103.      * set the value of the filter and fire the 'update' event.
  104.      * Defaults to Ext.emptyFn.
  105.      * @param {Object} data The value to set the filter
  106.      * @methodOf Ext.ux.grid.filter.Filter
  107.      */
  108.     setValue : Ext.emptyFn,
  109.     
  110.     /**
  111.      * Template method to be implemented by all subclasses that is to
  112.      * return <tt>true</tt> if the filter has enough configuration information to be activated.
  113.      * Defaults to <tt>return true</tt>.
  114.      * @return {Boolean}
  115.      */
  116.     isActivatable : function(){
  117.         return true;
  118.     },
  119.     
  120.     /**
  121.      * Template method to be implemented by all subclasses that is to
  122.      * get and return serialized filter data for transmission to the server.
  123.      * Defaults to Ext.emptyFn.
  124.      */
  125.     getSerialArgs : Ext.emptyFn,
  126.     /**
  127.      * Template method to be implemented by all subclasses that is to
  128.      * validates the provided Ext.data.Record against the filters configuration.
  129.      * Defaults to <tt>return true</tt>.
  130.      * @param {Ext.data.Record} record The record to validate
  131.      * @return {Boolean} true if the record is valid within the bounds
  132.      * of the filter, false otherwise.
  133.      */
  134.     validateRecord : function(){
  135.         return true;
  136.     },
  137.     /**
  138.      * Returns the serialized filter data for transmission to the server
  139.      * and fires the 'serialize' event.
  140.      * @return {Object/Array} An object or collection of objects containing
  141.      * key value pairs representing the current configuration of the filter.
  142.      * @methodOf Ext.ux.grid.filter.Filter
  143.      */
  144.     serialize : function(){
  145.         var args = this.getSerialArgs();
  146.         this.fireEvent('serialize', args, this);
  147.         return args;
  148.     },
  149.     /** @private */
  150.     fireUpdate : function(){
  151.         if (this.active) {
  152.             this.fireEvent('update', this);
  153.         }
  154.         this.setActive(this.isActivatable());
  155.     },
  156.     
  157.     /**
  158.      * Sets the status of the filter and fires the appropriate events.
  159.      * @param {Boolean} active        The new filter state.
  160.      * @param {Boolean} suppressEvent True to prevent events from being fired.
  161.      * @methodOf Ext.ux.grid.filter.Filter
  162.      */
  163.     setActive : function(active, suppressEvent){
  164.         if(this.active != active){
  165.             this.active = active;
  166.             if (suppressEvent !== true) {
  167.                 this.fireEvent(active ? 'activate' : 'deactivate', this);
  168.             }
  169.         }
  170.     }    
  171. });