Skip to content

Commit

Permalink
Add a gear icon to all grids by default to access the context menu [#…
Browse files Browse the repository at this point in the history
…14806]

Merge remote-tracking branch 'upstream/pr/14806' into 3.x
  • Loading branch information
Mark-H committed Nov 29, 2019
2 parents ee001e8 + d708d0c commit df8d2e9
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 2 deletions.
15 changes: 15 additions & 0 deletions _build/templates/default/sass/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,21 @@ a.x-grid-link:focus {
text-decoration: underline;
}

.x-grid-buttons {
text-align: center;
}
.x-grid-buttons li {
cursor: pointer;
display: inline-block;
font-size: 1.1em;
line-height: .7;
margin-right: 10px;
}

.x-grid-buttons li:last-child {
margin-right: 0;
}

/* panel stylings */
.modx-page-header,
.modx-page-header div {
Expand Down
1 change: 1 addition & 0 deletions core/docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ MODX Revolution 3.0.0-beta1 (TBD)
- Rename "Top Menu" to "Main Menu" now that it is no longer at the top [#14852]
- Change styling of resources in the tree: unpublished resources are now dimmed, with italics indicating menu visibility [#13969]
- Add name of edited media source, form customisation profile, dashboard, and dashboard widget to the title in the browser [#14830]
- Add a gear icon to all grids by default to access the context menu [#14806]

MODX Revolution 2.7.2-pl (TBD)
====================================
Expand Down
1 change: 1 addition & 0 deletions core/lexicon/en/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@
$_lang['newest'] = 'Newest';
$_lang['oldest'] = 'Oldest';
$_lang['constraints'] = 'Constraints';
$_lang['context_menu'] = 'Context Menu';

$_lang['january'] = 'January';
$_lang['february'] = 'February';
Expand Down
2 changes: 1 addition & 1 deletion manager/assets/modext/modx.jsgrps-min.js

Large diffs are not rendered by default.

149 changes: 149 additions & 0 deletions manager/assets/modext/widgets/core/modx.grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ MODx.grid.Grid = function(config) {
,preventSaveRefresh: true
,showPerPage: true
,stateful: false
,showActionsColumn: true
,actionsColumnWidth: 50
,disableContextMenuAction: false
,menuConfig: {
defaultAlign: 'tl-b?'
,enableScrolling: false
Expand Down Expand Up @@ -91,6 +94,23 @@ MODx.grid.Grid = function(config) {
if (!itm.scope) { itm.scope = this; }
}
}

if (config.showActionsColumn) {
if (config.columns && Array.isArray(config.columns)) {
config.columns.push({
width: config.actionsColumnWidth || 50
,renderer: this.actionsColumnRenderer.bind(this)
});
}

if (config.cm && config.cm.columns && Array.isArray(config.cm.columns)) {
config.cm.columns.push({
width: config.actionsColumnWidth || 50
,renderer: this.actionsColumnRenderer.bind(this)
});
}
}

MODx.grid.Grid.superclass.constructor.call(this,config);
this._loadMenu(config);
this.addEvents('beforeRemoveRow','afterRemoveRow','afterAutoSave');
Expand Down Expand Up @@ -574,6 +594,63 @@ Ext.extend(MODx.grid.Grid,Ext.grid.EditorGridPanel,{

return plugins[index];
}

,_getActionsColumnTpl: function () {
return new Ext.XTemplate('<tpl for=".">'
+ '<tpl if="actions !== null">'
+ '<ul class="x-grid-buttons">'
+ '<tpl for="actions">'
+ '<li><i class="x-grid-action icon icon-{icon:htmlEncode}" title="{text:htmlEncode}" data-action="{action:htmlEncode}"></i></li>'
+ '</tpl>'
+ '</ul>'
+ '</tpl>'
+ '</tpl>', {
compiled: true
});
}

,actionsColumnRenderer: function(value, metaData, record, rowIndex, colIndex, store) {
var actions = this.getActions.apply(this, [record, rowIndex, colIndex, store]);
if (this.config.disableContextMenuAction !== true) {
actions.push({
text: _('context_menu'),
action: 'contextMenu',
icon: 'gear'
});
}

return this._getActionsColumnTpl().apply({
actions: actions
});
}

,getActions: function(record, rowIndex, colIndex, store) {
return [];
}

,onClick: function(e) {
var target = e.getTarget();
if (!target.classList.contains('x-grid-action')) return;
if (!target.dataset.action) return;

var actionHandler = 'action' + target.dataset.action.charAt(0).toUpperCase() + target.dataset.action.slice(1);
if (!this[actionHandler] || (typeof this[actionHandler] !== 'function')) {
actionHandler = target.dataset.action;
if (!this[actionHandler] || (typeof this[actionHandler] !== 'function')) {
return;
}
}

var record = this.getSelectionModel().getSelected();
var recordIndex = this.store.indexOf(record);
this.menu.record = record.data;

this[actionHandler](record, recordIndex, e);
},

actionContextMenu: function(record, recordIndex, e) {
this._showMenu(this, recordIndex, e);
}
});

/* local grid */
Expand Down Expand Up @@ -611,6 +688,9 @@ MODx.grid.LocalGrid = function(config) {
,enableColumnMove: true
,header: false
,cls: 'modx-grid'
,showActionsColumn: true
,actionsColumnWidth: 50
,disableContextMenuAction: false
,viewConfig: {
forceFit: true
,enableRowBody: true
Expand All @@ -625,6 +705,17 @@ MODx.grid.LocalGrid = function(config) {
this.menu = new Ext.menu.Menu(config.menuConfig);
this.config = config;
this._loadColumnModel();

if (config.showActionsColumn && config.columns && Array.isArray(config.columns)) {
config.columns.push({
width: config.actionsColumnWidth || 50
,renderer: {
fn: this.actionsColumnRenderer,
scope: this
}
});
}

MODx.grid.LocalGrid.superclass.constructor.call(this,config);
this.addEvents({
beforeRemoveRow: true
Expand Down Expand Up @@ -910,6 +1001,64 @@ Ext.extend(MODx.grid.LocalGrid,Ext.grid.EditorGridPanel,{
}
return z;
}

,_getActionsColumnTpl: function () {
return new Ext.XTemplate('<tpl for=".">'
+ '<tpl if="actions !== null">'
+ '<ul class="x-grid-buttons">'
+ '<tpl for="actions">'
+ '<li><i class="x-grid-action icon icon-{icon:htmlEncode}" title="{text:htmlEncode}" data-action="{action:htmlEncode}"></i></li>'
+ '</tpl>'
+ '</ul>'
+ '</tpl>'
+ '</tpl>', {
compiled: true
});
}

,actionsColumnRenderer: function(value, metaData, record, rowIndex, colIndex, store) {
var actions = this.getActions.apply(this, arguments);

if (this.config.disableContextMenuAction !== true) {
actions.push({
text: _('context_menu'),
action: 'contextMenu',
icon: 'gear'
});
}

return this._getActionsColumnTpl().apply({
actions: actions
});
}

,getActions: function(value, metaData, record, rowIndex, colIndex, store) {
return [];
}

,onClick: function(e) {
var target = e.getTarget();
if (!target.classList.contains('x-grid-action')) return;
if (!target.dataset.action) return;

var actionHandler = 'action' + target.dataset.action.charAt(0).toUpperCase() + target.dataset.action.slice(1);
if (!this[actionHandler] || (typeof this[actionHandler] !== 'function')) {
actionHandler = target.dataset.action;
if (!this[actionHandler] || (typeof this[actionHandler] !== 'function')) {
return;
}
}

var record = this.getSelectionModel().getSelected();
var recordIndex = this.store.indexOf(record);
this.menu.record = record.data;

this[actionHandler](record, recordIndex, e);
},

actionContextMenu: function(record, recordIndex, e) {
this._showMenu(this, recordIndex, e);
}
});
Ext.reg('grid-local',MODx.grid.LocalGrid);
Ext.reg('modx-grid-local',MODx.grid.LocalGrid);
Expand Down
25 changes: 25 additions & 0 deletions manager/assets/modext/widgets/system/modx.grid.context.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,14 @@ Ext.extend(MODx.grid.Context,MODx.grid.Grid,{
,scope: this
});
}

if (p.indexOf('pedit') != -1) {
m.push({
text: _('context_update')
,handler: this.updateContext
});
}

if (p.indexOf('premove') != -1) {
m.push('-');
m.push({
Expand Down Expand Up @@ -236,6 +238,29 @@ Ext.extend(MODx.grid.Context,MODx.grid.Grid,{
this.getSelectionModel().clearSelections(true);
this.refresh();
}

,getActions: function(record, rowIndex, colIndex, store) {
var permissions = record.data.perm;
var actions = [];

if (~permissions.indexOf('pedit')) {
actions.push({
action: 'updateContext',
icon: 'pencil-square-o',
text: _('context_update')
});
}

if (~permissions.indexOf('premove')) {
actions.push({
action: 'remove',
icon: 'trash-o',
text: _('context_remove')
});
}

return actions;
}
});
Ext.reg('modx-grid-contexts',MODx.grid.Context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ MODx.grid.SystemEvent = function(config) {
,groupBy: 'groupname'
,singleText: _('system_event')
,pluralText: _('system_events')
,showActionsColumn: false
,columns: [{
header: _('name')
,dataIndex: 'name'
Expand Down
1 change: 1 addition & 0 deletions manager/assets/modext/workspace/package.grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ MODx.grid.Package = function(config) {
,'install','textaction','iconaction','updateable']
,plugins: [this.exp]
,pageSize: Math.min(parseInt(MODx.config.default_per_page), 25)
,disableContextMenuAction: true
,columns: cols
,primaryKey: 'signature'
,paging: true
Expand Down
2 changes: 1 addition & 1 deletion manager/templates/default/css/index-min.css

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions manager/templates/default/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -21903,6 +21903,19 @@ a.x-grid-link:hover,
a.x-grid-link:focus {
text-decoration: underline; }

.x-grid-buttons {
text-align: center; }

.x-grid-buttons li {
cursor: pointer;
display: inline-block;
font-size: 1.1em;
line-height: .7;
margin-right: 10px; }

.x-grid-buttons li:last-child {
margin-right: 0; }

/* panel stylings */
.modx-page-header,
.modx-page-header div {
Expand Down

0 comments on commit df8d2e9

Please sign in to comment.