silverstripe-cms/javascript/CMSMain.Tree.js

59 lines
1.7 KiB
JavaScript
Raw Normal View History

(function($) {
$.entwine('ss', function($){
$('.cms-tree').entwine({
getTreeConfig: function() {
var self = this, config = this._super(), hints = this.getHints();
config.plugins.push('contextmenu');
config.contextmenu = {
'items': function(node) {
// Build a list for allowed children as submenu entries
2012-05-07 14:45:39 +02:00
var pagetype = node.data('pagetype');
var id = node.data('id');
var allowedChildren = new Object;
2012-05-07 14:45:39 +02:00
$(hints[pagetype].allowedChildren).each(
function(key, val){
allowedChildren["allowedchildren-" + key ] = {
'label': '<span class="jstree-pageicon"></span>' + val.ssname,
2012-05-07 14:45:39 +02:00
'_class': 'class-' + val.pagetype,
'action': function(obj) {
$('.cms-container').loadPanel(ss.i18n.sprintf(
2012-05-07 14:45:39 +02:00
self.data('urlAddpage'), id, val.pagetype
));
}
};
}
);
var menuitems =
{
'edit': {
'label': ss.i18n._t('Tree.EditPage'),
'action': function(obj) {
$('.cms-container').loadPanel(ss.i18n.sprintf(
self.data('urlEditpage'), obj.data('id')
));
}
}
};
// Test if there are any allowed Children and thus the possibility of adding some
if(allowedChildren.hasOwnProperty('allowedchildren-0')) {
menuitems['addsubpage'] = {
'label': ss.i18n._t('Tree.AddSubPage'),
'action': function(obj) {
$('.cms-container').loadPanel(ss.i18n.sprintf(
self.data('urlAddpage'), id, 'Page'
));
},
'submenu': allowedChildren
};
}
return menuitems;
}
};
return config;
}
});
});
}(jQuery));