Skip to content

Commit

Permalink
Update modx.panel.filetree.js
Browse files Browse the repository at this point in the history
Formatting, style, optimization updates. No substantive changes.
  • Loading branch information
smg6511 committed Oct 21, 2024
1 parent 6f2c32d commit c9d1f58
Showing 1 changed file with 50 additions and 64 deletions.
114 changes: 50 additions & 64 deletions manager/assets/modext/widgets/system/modx.panel.filetree.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
* @param {Object} config
* @xtype modx-panel-filetree
*/
MODx.panel.FileTree = function(config) {
config = config || {};
MODx.panel.FileTree = function(config = {}) {
Ext.applyIf(config, {
_treePrefix: 'source-tree-'
,autoHeight: true
,defaults: {
autoHeight: true
,border: false
_treePrefix: 'source-tree-',
autoHeight: true,
defaults: {
autoHeight: true,
border: false
}
});
MODx.panel.FileTree.superclass.constructor.call(this, config);
Expand All @@ -25,94 +24,81 @@ Ext.extend(MODx.panel.FileTree, Ext.Container, {
*/
getSourceList: function() {
MODx.Ajax.request({
url: MODx.config.connector_url
,params: {
action: 'Source/GetList'
,limit: 0
}
,listeners: {
url: MODx.config.connector_url,
params: {
action: 'Source/GetList',
limit: 0
},
listeners: {
success: {
fn: function(data) {
this.onSourceListReceived(data.results);
}
,scope:this
}
,failure: {
},
scope: this
},
failure: {
fn: function(data) {
// Check if this really is an error
if (data.total > 0 && data.results != undefined) {
if (data.total > 0 && data.results !== undefined) {
this.onSourceListReceived(data.results);
}
return false;
}
,scope: this
},
scope: this
}
}
})
}
});
},

/**
* Iterate over the given media sources list to add their trees
*
* @param {Array} sources
*/
,onSourceListReceived: function(sources) {
for (var k = 0; k < sources.length; k++) {
var source = sources[k]
,exists = this.getComponent(this._treePrefix + source.id);

if (!exists) {
var tree = this.loadTree(source);
onSourceListReceived: function(sources) {
sources.forEach(source => {
const
sourceTreeExists = this.getComponent(this._treePrefix + source.id),
newSourceTree = !sourceTreeExists ? this.loadTree(source) : false
;
if (newSourceTree) {
this.add(newSourceTree);
}

this.add(tree);
tree = exists = void 0;
}
});
this.doLayout();
}
},

/**
* Load the tree configuration for the given media source
*
* @param {Object} source
* @returns {Object}
*/
,loadTree: function(source) {
var params = {};
if (location.search) {
var parts = location.search.substring(1).split('&');

for (var i = 0; i < parts.length; i++) {
var nv = parts[i].split('=');
if (!nv[0]) continue;
params[nv[0]] = nv[1] || true;
loadTree: function(source) {
let expandSource = false;
if (window.location.search) {
const params = MODx.util.UrlParams.get();
if (Object.hasOwn(params, 'source')) {
expandSource = source.id === params.source;
}
}
var activeSource = params.source,
expandSource = false;

if (source.id == activeSource) {
expandSource = true;
}

return MODx.load({
xtype: 'modx-tree-directory'
,autoExpandRoot: expandSource
,itemId: this._treePrefix + source.id
,stateId: this._treePrefix + source.id
,id: this._treePrefix + source.id
,cls: source.cls || ''
,rootName: source.name
,rootQtip: source.description || ''
,hideSourceCombo: true
,source: source.id
,rootIconCls: source.iconCls || ''
,tbar: false
,tbarCfg: {
xtype: 'modx-tree-directory',
autoExpandRoot: expandSource,
itemId: this._treePrefix + source.id,
stateId: this._treePrefix + source.id,
id: this._treePrefix + source.id,
cls: source.cls || '',
rootName: source.name,
rootQtip: source.description || '',
hideSourceCombo: true,
source: source.id,
rootIconCls: source.iconCls || '',
tbar: false,
tbarCfg: {
hidden: true
}
});
}
});
Ext.reg('modx-panel-filetree', MODx.panel.FileTree);

0 comments on commit c9d1f58

Please sign in to comment.