modx.grid.tv.template.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * Loads a grid of TVs assigned to the Template.
  3. *
  4. * @class MODx.grid.TemplateVarTemplate
  5. * @extends MODx.grid.Grid
  6. * @param {Object} config An object of options.
  7. * @xtype modx-grid-tv-template
  8. */
  9. MODx.grid.TemplateVarTemplate = function(config) {
  10. config = config || {};
  11. var tt = new Ext.ux.grid.CheckColumn({
  12. header: _('access')
  13. ,dataIndex: 'access'
  14. ,width: 50
  15. ,sortable: true
  16. });
  17. Ext.applyIf(config,{
  18. id: 'modx-grid-tv-template'
  19. ,url: MODx.config.connector_url
  20. ,fields: ['id','templatename','category','category_name','description','access','menu']
  21. ,baseParams: {
  22. action: 'element/tv/template/getList'
  23. ,tv: config.tv
  24. }
  25. ,saveParams: {
  26. tv: config.tv
  27. }
  28. ,width: 800
  29. ,paging: true
  30. ,plugins: tt
  31. ,remoteSort: true
  32. ,columns: [{
  33. header: _('name')
  34. ,dataIndex: 'templatename'
  35. ,width: 150
  36. ,sortable: true
  37. },{
  38. header: _('category')
  39. ,dataIndex: 'category_name'
  40. ,width: 300
  41. },{
  42. header: _('description')
  43. ,dataIndex: 'description'
  44. ,width: 300
  45. },tt]
  46. ,tbar: ['->',{
  47. xtype: 'modx-combo-category'
  48. ,name: 'filter_category'
  49. ,hiddenName: 'filter_category'
  50. ,id: 'modx-tvtemp-filter-category'
  51. ,emptyText: _('filter_by_category')
  52. ,value: ''
  53. ,allowBlank: true
  54. ,width: 150
  55. ,listeners: {
  56. 'select': {fn: this.filterByCategory, scope:this}
  57. }
  58. },'-',{
  59. xtype: 'textfield'
  60. ,name: 'query'
  61. ,id: 'modx-tvtemp-search'
  62. ,emptyText: _('search_ellipsis')
  63. ,listeners: {
  64. 'change': {fn: this.search, scope: this}
  65. ,'render': {fn: function(cmp) {
  66. new Ext.KeyMap(cmp.getEl(), {
  67. key: Ext.EventObject.ENTER
  68. ,fn: this.blur
  69. ,scope: cmp
  70. });
  71. },scope:this}
  72. }
  73. },{
  74. xtype: 'button'
  75. ,id: 'modx-filter-clear'
  76. ,text: _('filter_clear')
  77. ,listeners: {
  78. 'click': {fn: this.clearFilter, scope: this},
  79. 'mouseout': { fn: function(evt){
  80. this.removeClass('x-btn-focus');
  81. }
  82. }
  83. }
  84. }]
  85. });
  86. MODx.grid.TemplateVarTemplate.superclass.constructor.call(this,config);
  87. };
  88. Ext.extend(MODx.grid.TemplateVarTemplate,MODx.grid.Grid,{
  89. filterByCategory: function(cb,rec,ri) {
  90. this.getStore().baseParams['category'] = cb.getValue();
  91. this.getBottomToolbar().changePage(1);
  92. //this.refresh();
  93. }
  94. ,search: function(tf,newValue,oldValue) {
  95. var nv = newValue || tf;
  96. this.getStore().baseParams.query = Ext.isEmpty(nv) || Ext.isObject(nv) ? '' : nv;
  97. Ext.getCmp('modx-tvtemp-filter-category').setValue('');
  98. this.getBottomToolbar().changePage(1);
  99. //this.refresh();
  100. return true;
  101. }
  102. ,clearFilter: function() {
  103. this.getStore().baseParams = {
  104. action: 'element/tv/template/getList'
  105. };
  106. Ext.getCmp('modx-tvtemp-filter-category').reset();
  107. Ext.getCmp('modx-tvtemp-search').setValue('');
  108. this.getBottomToolbar().changePage(1);
  109. //this.refresh();
  110. }
  111. });
  112. Ext.reg('modx-grid-tv-template',MODx.grid.TemplateVarTemplate);