Skip to content

Commit

Permalink
Filter Persistence: TV Templates Grid
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Graham committed Feb 1, 2023
1 parent 8ad4f5a commit dad52e3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* This file is part of the MODX Revolution package.
*
Expand All @@ -10,7 +11,6 @@

namespace MODX\Revolution\Processors\Element\TemplateVar\Template;


use MODX\Revolution\modCategory;
use MODX\Revolution\Processors\Processor;
use MODX\Revolution\modTemplate;
Expand Down Expand Up @@ -82,10 +82,11 @@ public function getData()

/* query for templates */
$c = $this->modx->newQuery(modTemplate::class);
$query = $this->getProperty('query');
$query = $this->getProperty('query', '');
if (!empty($query)) {
$c->where([
'templatename:LIKE' => "%$query%",
'templatename:LIKE' => '%' . $query . '%',
'OR:description:LIKE' => '%' . $query . '%'
]);
}
$c->leftJoin(modCategory::class, 'Category');
Expand All @@ -107,8 +108,12 @@ public function getData()
$c->select([
'category_name' => 'Category.category',
]);
$c->select($this->modx->getSelectColumns(modTemplateVarTemplate::class, 'TemplateVarTemplates', '',
['tmplvarid']));
$c->select($this->modx->getSelectColumns(
modTemplateVarTemplate::class,
'TemplateVarTemplates',
'',
['tmplvarid']
));
$c->select(['access' => 'TemplateVarTemplates.tmplvarid']);
$c->sortby($this->getProperty('sort'), $this->getProperty('dir'));
if ($isLimit) {
Expand Down
94 changes: 31 additions & 63 deletions manager/assets/modext/widgets/element/modx.grid.tv.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,26 @@ MODx.grid.TemplateVarTemplate = function(config) {
var tt = new Ext.ux.grid.CheckColumn({
header: _('access')
,dataIndex: 'access'
,width: 50
,width: 60
,sortable: true
});
Ext.applyIf(config,{
id: 'modx-grid-tv-template'
,url: MODx.config.connector_url
,fields: ['id','templatename','category','category_name','description','access','menu']
,fields: [
'id',
'templatename',
'category',
'category_name',
'description',
'access',
'menu'
]
,showActionsColumn: false
,baseParams: {
action: 'Element/TemplateVar/Template/GetList'
,tv: config.tv
,category: MODx.request.category || null
}
,saveParams: {
tv: config.tv
Expand Down Expand Up @@ -50,69 +59,28 @@ MODx.grid.TemplateVarTemplate = function(config) {
,dataIndex: 'description'
,width: 300
},tt]
,tbar: ['->',{
xtype: 'modx-combo-category'
,name: 'filter_category'
,hiddenName: 'filter_category'
,id: 'modx-tvtemp-filter-category'
,emptyText: _('filter_by_category')
,value: ''
,allowBlank: true
,width: 150
,listeners: {
'select': {fn: this.filterByCategory, scope:this}
}
},'-',{
xtype: 'textfield'
,name: 'query'
,id: 'modx-tvtemp-search'
,emptyText: _('search')
,listeners: {
'change': {fn: this.search, scope: this}
,'render': {fn: function(cmp) {
new Ext.KeyMap(cmp.getEl(), {
key: Ext.EventObject.ENTER
,fn: this.blur
,scope: cmp
});
},scope:this}
}
},{
xtype: 'button'
,id: 'modx-filter-clear'
,text: _('filter_clear')
,listeners: {
'click': {fn: this.clearFilter, scope: this},
'mouseout': { fn: function(evt){
this.removeClass('x-btn-focus');
,tbar: [
'->',
{
xtype: 'modx-combo-category'
,itemId: 'filter-category'
,emptyText: _('filter_by_category')
,value: MODx.request.category || null
,width: 200
,listeners: {
select: {
fn: function (cmp, record, selectedIndex) {
this.applyGridFilter(cmp, 'category');
},
scope: this
}
}
}
}
}]
},
this.getQueryFilterField(),
this.getClearFiltersButton('filter-category, filter-query')
]
});
MODx.grid.TemplateVarTemplate.superclass.constructor.call(this,config);
};
Ext.extend(MODx.grid.TemplateVarTemplate,MODx.grid.Grid,{
filterByCategory: function(cb,rec,ri) {
this.getStore().baseParams['category'] = cb.getValue();
this.getBottomToolbar().changePage(1);
}

,search: function(tf,newValue,oldValue) {
var nv = newValue || tf;
this.getStore().baseParams.query = Ext.isEmpty(nv) || Ext.isObject(nv) ? '' : nv;
Ext.getCmp('modx-tvtemp-filter-category').setValue('');
this.getBottomToolbar().changePage(1);
return true;
}

,clearFilter: function() {
this.getStore().baseParams = {
action: 'Element/TemplateVar/Template/GetList'
};
Ext.getCmp('modx-tvtemp-filter-category').reset();
Ext.getCmp('modx-tvtemp-search').setValue('');
this.getBottomToolbar().changePage(1);
}
});
Ext.extend(MODx.grid.TemplateVarTemplate,MODx.grid.Grid);
Ext.reg('modx-grid-tv-template',MODx.grid.TemplateVarTemplate);

0 comments on commit dad52e3

Please sign in to comment.