PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/ext-4.0.7/examples/ux/grid/filter/BooleanFilter.js

https://bitbucket.org/srogerf/javascript
JavaScript | 115 lines | 31 code | 9 blank | 75 comment | 2 complexity | c20c61320656d0268c4ec858a69678d1 MD5 | raw file
  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. /**
  10. * @class Ext.ux.grid.filter.BooleanFilter
  11. * @extends Ext.ux.grid.filter.Filter
  12. * Boolean filters use unique radio group IDs (so you can have more than one!)
  13. * <p><b><u>Example Usage:</u></b></p>
  14. * <pre><code>
  15. var filters = Ext.create('Ext.ux.grid.GridFilters', {
  16. ...
  17. filters: [{
  18. // required configs
  19. type: 'boolean',
  20. dataIndex: 'visible'
  21. // optional configs
  22. defaultValue: null, // leave unselected (false selected by default)
  23. yesText: 'Yes', // default
  24. noText: 'No' // default
  25. }]
  26. });
  27. * </code></pre>
  28. */
  29. Ext.define('Ext.ux.grid.filter.BooleanFilter', {
  30. extend: 'Ext.ux.grid.filter.Filter',
  31. alias: 'gridfilter.boolean',
  32. /**
  33. * @cfg {Boolean} defaultValue
  34. * Set this to null if you do not want either option to be checked by default. Defaults to false.
  35. */
  36. defaultValue : false,
  37. /**
  38. * @cfg {String} yesText
  39. * Defaults to 'Yes'.
  40. */
  41. yesText : 'Yes',
  42. /**
  43. * @cfg {String} noText
  44. * Defaults to 'No'.
  45. */
  46. noText : 'No',
  47. /**
  48. * @private
  49. * Template method that is to initialize the filter and install required menu items.
  50. */
  51. init : function (config) {
  52. var gId = Ext.id();
  53. this.options = [
  54. Ext.create('Ext.menu.CheckItem', {text: this.yesText, group: gId, checked: this.defaultValue === true}),
  55. Ext.create('Ext.menu.CheckItem', {text: this.noText, group: gId, checked: this.defaultValue === false})];
  56. this.menu.add(this.options[0], this.options[1]);
  57. for(var i=0; i<this.options.length; i++){
  58. this.options[i].on('click', this.fireUpdate, this);
  59. this.options[i].on('checkchange', this.fireUpdate, this);
  60. }
  61. },
  62. /**
  63. * @private
  64. * Template method that is to get and return the value of the filter.
  65. * @return {String} The value of this filter
  66. */
  67. getValue : function () {
  68. return this.options[0].checked;
  69. },
  70. /**
  71. * @private
  72. * Template method that is to set the value of the filter.
  73. * @param {Object} value The value to set the filter
  74. */
  75. setValue : function (value) {
  76. this.options[value ? 0 : 1].setChecked(true);
  77. },
  78. /**
  79. * @private
  80. * Template method that is to get and return serialized filter data for
  81. * transmission to the server.
  82. * @return {Object/Array} An object or collection of objects containing
  83. * key value pairs representing the current configuration of the filter.
  84. */
  85. getSerialArgs : function () {
  86. var args = {type: 'boolean', value: this.getValue()};
  87. return args;
  88. },
  89. /**
  90. * Template method that is to validate the provided Ext.data.Record
  91. * against the filters configuration.
  92. * @param {Ext.data.Record} record The record to validate
  93. * @return {Boolean} true if the record is valid within the bounds
  94. * of the filter, false otherwise.
  95. */
  96. validateRecord : function (record) {
  97. return record.get(this.dataIndex) == this.getValue();
  98. }
  99. });