Skip to content

Commit

Permalink
Base class updates
Browse files Browse the repository at this point in the history
Additional logic to fix issues raised in PR review
  • Loading branch information
smg6511 committed Oct 30, 2023
1 parent 38992d1 commit 334d553
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 15 deletions.
13 changes: 11 additions & 2 deletions manager/assets/modext/widgets/core/modx.grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ Ext.extend(MODx.grid.Grid,Ext.grid.EditorGridPanel,{
case 0:
md.css = 'red';
return _('no');
// no default
}
}

Expand Down Expand Up @@ -909,7 +910,14 @@ Ext.extend(MODx.grid.Grid,Ext.grid.EditorGridPanel,{
activeParentTabIdx
;
if (!Ext.isEmpty(filterValue)) {
// Add param to URL when filter has a value
urlParams[param] = filterValue;
} else if (MODx.request[param]) {
/*
Maintain params in URL when already present in URL. Prevents removal of
filter params when reloading or navigating to a URL that includes filter params.
*/
urlParams[param] = MODx.request[param];
} else {
MODx.util.url.clearParam(cmp);
}
Expand All @@ -918,7 +926,6 @@ Ext.extend(MODx.grid.Grid,Ext.grid.EditorGridPanel,{
} else {
store.baseParams[param] = filterValue;
}

if (tabPanel) {
/*
Determine if this is a vertical tab panel; if so there will also be a
Expand Down Expand Up @@ -1003,7 +1010,9 @@ Ext.extend(MODx.grid.Grid,Ext.grid.EditorGridPanel,{
});
}
if (isCombo) {
cmp.getStore().load();
if (cmp.mode !== 'local') {
cmp.getStore().load();
}
}
store.baseParams[param] = itemDefaultVal;
});
Expand Down
74 changes: 61 additions & 13 deletions manager/assets/modext/widgets/core/modx.tabs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
/**
* Override of onStripMouseDown (private method) made to update new 'tabClicked' property when
* a tab is clicked. There is no built-in click event for the Ext.TabPanel component and adding one
* an instance listener (via a vanilla addEventListener) it ends up firing the event too late in the chain
* of events. Thus, notification of tab clicks is made in this way (which sets the 'tabClicked' value
* very early in the process).
*/
Ext.override(Ext.TabPanel, {
onStripMouseDown: function(e) {
if (e.button !== 0) {
return;
}
e.preventDefault();
const t = this.findTargets(e);
if (t.close) {
if (t.item.fireEvent('beforeclose', t.item) !== false) {
t.item.fireEvent('close', t.item);
this.remove(t.item);
}
return;
}
if (t.item && t.item !== this.activeTab) {
this.tabClicked = true;
this.setActiveTab(t.item);
}
}
});

MODx.Tabs = function(config = {}) {
Ext.applyIf(config, {
enableTabScroll: true,
Expand All @@ -13,6 +41,7 @@ MODx.Tabs = function(config = {}) {
bodyCssClass: 'tab-panel-wrapper'
},
activeTab: 0,
tabClicked: false,
border: false,
autoScroll: true,
autoHeight: true,
Expand All @@ -34,15 +63,25 @@ MODx.Tabs = function(config = {}) {
tabPanel.on({
beforetabchange: function(tabPanelCmp, newTab, currentTab) {
/*
Only proceed with the clearing process if the tab has changed.
Only proceed with the clearing process if the tab has changed (via click).
This is needed to prevent clearing when a URL has been typed in.
NOTE: The currentTab is the previous one being navigated away from
*/
if (newTab && currentTab && newTab.id !== currentTab.id) {
if (this.tabClicked && newTab && currentTab && newTab.id !== currentTab.id) {
const resetVerticalTabPanelFilters = (currentTab.items?.items[0]?.xtype === 'modx-vtabs') || currentTab.ownerCt?.xtype === 'modx-vtabs',
changedBetweenVtabs = newTab.ownerCt?.xtype === 'modx-vtabs' && currentTab.ownerCt?.xtype === 'modx-vtabs'
;
/*
When navigating back to Access Permissions and the TabPanel is not stateful,
ensure that the first vertical tab is activated
*/
if (newTab.itemId === 'modx-usergroup-permissions-panel' && !this.stateful) {
const vTabPanel = newTab.items?.items[0];
if (vTabPanel && vTabPanel.xtype === 'modx-vtabs') {
vTabPanel.setActiveTab(0);
}
}
this.clearFiltersBeforeChange(currentTab, resetVerticalTabPanelFilters, changedBetweenVtabs);
}
}
Expand Down Expand Up @@ -90,13 +129,20 @@ Ext.extend(MODx.Tabs, Ext.TabPanel, {
}
if (itemsSource.length > 0) {
gridObj = this.findGridObject(itemsSource);
/*
Grids placed in an atypical structure, such as the ACLs User Group grid that
is activated via the User Groups tree, require further searching
*/
if (!gridObj && itemsSource?.map['modx-tree-panel-usergroup']) {
itemsSource = itemsSource.map['modx-tree-panel-usergroup'].items;
gridObj = this.findGridObject(itemsSource);

// Grids placed in an atypical structure require further searching
if (!gridObj) {
let customItemsSource = null;
if (itemsSource?.map['modx-tree-panel-usergroup']) {
// ACLs User Group grid that is activated via the User Groups tree
customItemsSource = itemsSource.map['modx-tree-panel-usergroup'].items;
} else if (itemsSource?.map['packages-breadcrumbs']) {
// (Installed) Packages grid
customItemsSource = itemsSource.map['card-container'].items.map['modx-panel-packages'].items;
}
if (customItemsSource) {
gridObj = this.findGridObject(customItemsSource);
}
}
}
if (gridObj) {
Expand Down Expand Up @@ -134,10 +180,12 @@ MODx.VerticalTabs = function(config = {}) {
});
MODx.VerticalTabs.superclass.constructor.call(this, config);
this.config = config;
this.on('afterrender', function() {
if (MODx.request && Object.prototype.hasOwnProperty.call(MODx.request, 'vtab')) {
const tabId = parseInt(MODx.request.vtab, 10);
this.setActiveTab(tabId);
this.on({
afterrender: function() {
if (MODx.request && Object.prototype.hasOwnProperty.call(MODx.request, 'vtab')) {
const tabId = parseInt(MODx.request.vtab, 10);
this.setActiveTab(tabId);
}
}
});
};
Expand Down

0 comments on commit 334d553

Please sign in to comment.