/hippo/src/main/webapp/ext/src/widgets/grid/CheckboxSelectionModel.js

http://hdbc.googlecode.com/ · JavaScript · 103 lines · 54 code · 9 blank · 40 comment · 9 complexity · f396836209e141152352fd15a9e57e2c MD5 · raw file

  1. /*!
  2. * Ext JS Library 3.0.0
  3. * Copyright(c) 2006-2009 Ext JS, LLC
  4. * licensing@extjs.com
  5. * http://www.extjs.com/license
  6. */
  7. /**
  8. * @class Ext.grid.CheckboxSelectionModel
  9. * @extends Ext.grid.RowSelectionModel
  10. * A custom selection model that renders a column of checkboxes that can be toggled to select or deselect rows.
  11. * @constructor
  12. * @param {Object} config The configuration options
  13. */
  14. Ext.grid.CheckboxSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
  15. /**
  16. * @cfg {Boolean} checkOnly <tt>true</tt> if rows can only be selected by clicking on the
  17. * checkbox column (defaults to <tt>false</tt>).
  18. */
  19. /**
  20. * @cfg {String} header Any valid text or HTML fragment to display in the header cell for the
  21. * checkbox column. Defaults to:<pre><code>
  22. * '&lt;div class="x-grid3-hd-checker">&#38;#160;&lt;/div>'</tt>
  23. * </code></pre>
  24. * The default CSS class of <tt>'x-grid3-hd-checker'</tt> displays a checkbox in the header
  25. * and provides support for automatic check all/none behavior on header click. This string
  26. * can be replaced by any valid HTML fragment, including a simple text string (e.g.,
  27. * <tt>'Select Rows'</tt>), but the automatic check all/none behavior will only work if the
  28. * <tt>'x-grid3-hd-checker'</tt> class is supplied.
  29. */
  30. header: '<div class="x-grid3-hd-checker">&#160;</div>',
  31. /**
  32. * @cfg {Number} width The default width in pixels of the checkbox column (defaults to <tt>20</tt>).
  33. */
  34. width: 20,
  35. /**
  36. * @cfg {Boolean} sortable <tt>true</tt> if the checkbox column is sortable (defaults to
  37. * <tt>false</tt>).
  38. */
  39. sortable: false,
  40. // private
  41. menuDisabled:true,
  42. fixed:true,
  43. dataIndex: '',
  44. id: 'checker',
  45. constructor: function(){
  46. Ext.grid.CheckboxSelectionModel.superclass.constructor.apply(this, arguments);
  47. if(this.checkOnly){
  48. this.handleMouseDown = Ext.emptyFn;
  49. }
  50. },
  51. // private
  52. initEvents : function(){
  53. Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
  54. this.grid.on('render', function(){
  55. var view = this.grid.getView();
  56. view.mainBody.on('mousedown', this.onMouseDown, this);
  57. Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);
  58. }, this);
  59. },
  60. // private
  61. onMouseDown : function(e, t){
  62. if(e.button === 0 && t.className == 'x-grid3-row-checker'){ // Only fire if left-click
  63. e.stopEvent();
  64. var row = e.getTarget('.x-grid3-row');
  65. if(row){
  66. var index = row.rowIndex;
  67. if(this.isSelected(index)){
  68. this.deselectRow(index);
  69. }else{
  70. this.selectRow(index, true);
  71. }
  72. }
  73. }
  74. },
  75. // private
  76. onHdMouseDown : function(e, t){
  77. if(t.className == 'x-grid3-hd-checker'){
  78. e.stopEvent();
  79. var hd = Ext.fly(t.parentNode);
  80. var isChecked = hd.hasClass('x-grid3-hd-checker-on');
  81. if(isChecked){
  82. hd.removeClass('x-grid3-hd-checker-on');
  83. this.clearSelections();
  84. }else{
  85. hd.addClass('x-grid3-hd-checker-on');
  86. this.selectAll();
  87. }
  88. }
  89. },
  90. // private
  91. renderer : function(v, p, record){
  92. return '<div class="x-grid3-row-checker">&#160;</div>';
  93. }
  94. });