Skip to content

Instantly share code, notes, and snippets.

@vasia123
Forked from Fi1osof/gist:4986826
Last active December 25, 2015 10:39
Show Gist options
  • Save vasia123/6962883 to your computer and use it in GitHub Desktop.
Save vasia123/6962883 to your computer and use it in GitHub Desktop.
Just translated comments for the method of adding items to the context menu. List of menu items listed in the line 13. Taken from article http://community.modx-cms.ru/blog/research/9846.html
<?php
switch($modx->event->name){
case 'OnManagerPageInit':
$JS = <<<JS
<script type="text/javascript">
Ext.onReady(function(){
// Get a tree
var tree = Ext.getCmp('modx-resource-tree');
// Describes a rule the allowed child resources
var resourcesRules = {
modDocument: ['modStaticResource', 'modDocument']
};
// Write functions copying the values ​​of the object,
// since we have a problem at the level of reference objects
// ie changing one variable is changed and the other, if the object is common
var copyObject = function(from){
var to = {};
for(i in from){
to[i] = from[i];
}
return to;
}
// We fix an initial set of classes
var classes = copyObject(MODx.config.resource_classes);
// Adding the function of changing a set of classes
// when creating a context menu
tree.on('loadCreateMenus', function(types){
var node = this.getSelectionModel().getSelectedNode()
,classKey;
if(resourcesRules && node && node.attributes
&& (classKey = node.attributes.classKey)
&& resourcesRules[classKey]
){
for(var i in types){
if(!resourcesRules[classKey].in_array(i)){
delete types[i];
}
}
}
return true;
}, tree);
// Adding the recovery function set of classes
// This function is executed after the formation of the menu because added later
// than the basic method of the resource tree
tree.on('contextmenu', function(){
MODx.config.resource_classes = copyObject(classes);
});
});
</script>
JS;
$modx->regClientStartupScript($JS, true);
break;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment