Skip to content

Instantly share code, notes, and snippets.

@Fi1osof
Last active December 13, 2015 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Fi1osof/4986826 to your computer and use it in GitHub Desktop.
Save Fi1osof/4986826 to your computer and use it in GitHub Desktop.
MODX Revolution. Плагин, позволяющий определять, какие дочерние документы показывать или нет. Просто создайте плагин на событие OnManagerPageInit и пропишите в нем свои правила resourcesRules
<?php
switch($modx->event->name){
case 'OnManagerPageInit':
$JS = <<<JS
<script type="text/javascript">
Ext.onReady(function(){
// Получаем дерево
var tree = Ext.getCmp('modx-resource-tree');
// Описываем правила разрешенных дочерних ресурсов
var resourcesRules = {
modDocument: ['modStaticResource', 'modDocument']
};
// Прописываем функцию копирования значений объекта,
// так как у нас проблемы на уровне ссылок на объекты,
// то есть изменяя одну переменную, изменяется и другая, если объект общий
var copyObject = function(from){
var to = {};
for(i in from){
to[i] = from[i];
}
return to;
}
// Фиксируем изначальный набор классов
var classes = copyObject(MODx.config.resource_classes);
// Навешиваем функцию изменения набора классов
// при создании контекстного меню
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);
// Навешиваем функцию восстановления набора классов
// Эта функция выполнится после формирования меню, так как навешено позже
// базового метода дерева ресурсов
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