2012-03-12 11:40:43 +01:00
|
|
|
(function($) {
|
|
|
|
|
2012-05-18 02:09:47 +02:00
|
|
|
$.entwine('ss.tree', function($){
|
2012-03-12 11:40:43 +01:00
|
|
|
$('.cms-tree').entwine({
|
2013-08-20 15:37:17 +02:00
|
|
|
fromDocument: {
|
|
|
|
'oncontext_show.vakata': function(e){
|
|
|
|
this.adjustContextClass();
|
|
|
|
}
|
2013-08-07 03:46:40 +02:00
|
|
|
},
|
|
|
|
/*
|
|
|
|
* Add and remove classes from context menus to allow for
|
|
|
|
* adjusting the display
|
|
|
|
*/
|
|
|
|
adjustContextClass: function(){
|
|
|
|
var menus = $('#vakata-contextmenu').find("ul ul");
|
|
|
|
|
|
|
|
menus.each(function(i){
|
2013-10-10 04:42:49 +02:00
|
|
|
var col = "1",
|
2013-08-07 03:46:40 +02:00
|
|
|
count = $(menus[i]).find('li').length;
|
|
|
|
|
|
|
|
//Assign columns to menus over 10 items long
|
|
|
|
if(count > 20){
|
2013-10-10 04:42:49 +02:00
|
|
|
col = "3";
|
2013-08-07 03:46:40 +02:00
|
|
|
}else if(count > 10){
|
2013-10-10 04:42:49 +02:00
|
|
|
col = "2";
|
2013-08-07 03:46:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$(menus[i]).addClass('col-' + col).removeClass('right');
|
|
|
|
|
|
|
|
//Remove "right" class that jstree adds on mouseenter
|
2013-10-10 04:42:49 +02:00
|
|
|
$(menus[i]).find('li').on("mouseenter", function (e) {
|
2013-08-07 03:46:40 +02:00
|
|
|
$(this).parent('ul').removeClass("right");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2012-03-12 11:40:43 +01:00
|
|
|
getTreeConfig: function() {
|
2012-04-30 16:42:45 +02:00
|
|
|
var self = this, config = this._super(), hints = this.getHints();
|
2012-03-12 11:40:43 +01:00
|
|
|
config.plugins.push('contextmenu');
|
|
|
|
config.contextmenu = {
|
2012-03-19 02:05:09 +01:00
|
|
|
'items': function(node) {
|
2013-10-10 04:42:49 +02:00
|
|
|
|
2012-12-03 16:33:06 +01:00
|
|
|
var menuitems = {
|
2012-03-19 02:05:09 +01:00
|
|
|
'edit': {
|
2013-05-21 04:57:29 +02:00
|
|
|
'label': ss.i18n._t('Tree.EditPage', 'Edit page', 100, 'Used in the context menu when right-clicking on a page node in the CMS tree'),
|
2012-03-19 02:05:09 +01:00
|
|
|
'action': function(obj) {
|
2012-05-18 02:09:47 +02:00
|
|
|
$('.cms-container').entwine('.ss').loadPanel(ss.i18n.sprintf(
|
2012-04-30 16:42:45 +02:00
|
|
|
self.data('urlEditpage'), obj.data('id')
|
|
|
|
));
|
2012-03-19 02:05:09 +01:00
|
|
|
}
|
2012-12-03 16:33:06 +01:00
|
|
|
}
|
2012-03-19 02:05:09 +01:00
|
|
|
};
|
2013-03-14 17:31:36 +01:00
|
|
|
|
|
|
|
// Add "show as list"
|
|
|
|
if(!node.hasClass('nochildren')) {
|
|
|
|
menuitems['showaslist'] = {
|
|
|
|
'label': ss.i18n._t('Tree.ShowAsList'),
|
|
|
|
'action': function(obj) {
|
|
|
|
$('.cms-container').entwine('.ss').loadPanel(
|
|
|
|
self.data('urlListview') + '&ParentID=' + obj.data('id'),
|
|
|
|
null,
|
|
|
|
// Default to list view tab
|
|
|
|
{tabState: {'pages-controller-cms-content': {'tabSelector': '.content-listview'}}}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2013-10-10 04:42:49 +02:00
|
|
|
|
2012-03-19 02:05:09 +01:00
|
|
|
// Build a list for allowed children as submenu entries
|
2012-12-03 16:33:06 +01:00
|
|
|
var pagetype = node.data('pagetype'),
|
|
|
|
id = node.data('id'),
|
2015-03-11 06:54:08 +01:00
|
|
|
allowedChildren = node.find('>a .item').data('allowedchildren'),
|
2012-12-03 16:33:06 +01:00
|
|
|
menuAllowedChildren = {},
|
|
|
|
hasAllowedChildren = false;
|
2012-03-19 02:05:09 +01:00
|
|
|
|
2012-12-03 16:33:06 +01:00
|
|
|
// Convert to menu entries
|
2015-03-11 06:54:08 +01:00
|
|
|
$.each(allowedChildren, function(klass, title){
|
2012-12-03 16:33:06 +01:00
|
|
|
hasAllowedChildren = true;
|
|
|
|
menuAllowedChildren["allowedchildren-" + klass ] = {
|
2015-03-11 06:54:08 +01:00
|
|
|
'label': '<span class="jstree-pageicon"></span>' + title,
|
2012-12-03 16:33:06 +01:00
|
|
|
'_class': 'class-' + klass,
|
|
|
|
'action': function(obj) {
|
2013-04-30 16:54:18 +02:00
|
|
|
$('.cms-container').entwine('.ss').loadPanel(
|
|
|
|
$.path.addSearchParams(
|
|
|
|
ss.i18n.sprintf(self.data('urlAddpage'), id, klass),
|
|
|
|
self.data('extraParams')
|
|
|
|
)
|
|
|
|
);
|
2012-03-19 02:05:09 +01:00
|
|
|
}
|
|
|
|
};
|
2012-12-03 16:33:06 +01:00
|
|
|
});
|
2013-10-10 04:42:49 +02:00
|
|
|
|
2012-12-03 16:33:06 +01:00
|
|
|
if(hasAllowedChildren) {
|
2012-03-19 02:05:09 +01:00
|
|
|
menuitems['addsubpage'] = {
|
2013-05-21 04:57:29 +02:00
|
|
|
'label': ss.i18n._t('Tree.AddSubPage', 'Add page under this page', 100, 'Used in the context menu when right-clicking on a page node in the CMS tree'),
|
2013-05-31 17:53:05 +02:00
|
|
|
'submenu': menuAllowedChildren
|
2012-03-19 02:05:09 +01:00
|
|
|
};
|
2013-10-10 04:42:49 +02:00
|
|
|
}
|
2013-03-11 21:20:01 +01:00
|
|
|
|
|
|
|
menuitems['duplicate'] = {
|
|
|
|
'label': ss.i18n._t('Tree.Duplicate'),
|
|
|
|
'submenu': [
|
|
|
|
{
|
|
|
|
'label': ss.i18n._t('Tree.ThisPageOnly'),
|
|
|
|
'action': function(obj) {
|
2013-04-30 16:54:18 +02:00
|
|
|
$('.cms-container').entwine('.ss').loadPanel(
|
|
|
|
$.path.addSearchParams(
|
2013-10-10 04:42:49 +02:00
|
|
|
ss.i18n.sprintf(self.data('urlDuplicate'), obj.data('id')),
|
2013-04-30 16:54:18 +02:00
|
|
|
self.data('extraParams')
|
|
|
|
)
|
|
|
|
);
|
2013-03-11 21:20:01 +01:00
|
|
|
}
|
|
|
|
},{
|
|
|
|
'label': ss.i18n._t('Tree.ThisPageAndSubpages'),
|
|
|
|
'action': function(obj) {
|
2013-04-30 16:54:18 +02:00
|
|
|
$('.cms-container').entwine('.ss').loadPanel(
|
|
|
|
$.path.addSearchParams(
|
2013-10-10 04:42:49 +02:00
|
|
|
ss.i18n.sprintf(self.data('urlDuplicatewithchildren'), obj.data('id')),
|
2013-04-30 16:54:18 +02:00
|
|
|
self.data('extraParams')
|
|
|
|
)
|
|
|
|
);
|
2013-03-11 21:20:01 +01:00
|
|
|
}
|
|
|
|
}
|
2013-08-07 03:46:40 +02:00
|
|
|
]
|
2013-03-11 21:20:01 +01:00
|
|
|
};
|
2012-12-03 16:33:06 +01:00
|
|
|
|
2012-03-19 02:05:09 +01:00
|
|
|
return menuitems;
|
2013-10-10 04:42:49 +02:00
|
|
|
}
|
2012-03-12 11:40:43 +01:00
|
|
|
};
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
});
|
2013-10-10 04:42:49 +02:00
|
|
|
|
|
|
|
// Scroll tree down to context of the current page, if it isn't
|
|
|
|
// already visible
|
2013-08-19 03:18:37 +02:00
|
|
|
$('.cms-tree a.jstree-clicked').entwine({
|
2013-10-10 04:42:49 +02:00
|
|
|
onmatch: function(){
|
|
|
|
var self = this,
|
|
|
|
panel = self.parents('.cms-panel-content'),
|
|
|
|
scrollTo;
|
|
|
|
|
|
|
|
if(self.offset().top < 0 ||
|
|
|
|
self.offset().top > panel.height() - self.height()) {
|
|
|
|
// Current scroll top + our current offset top is our
|
|
|
|
// position in the panel
|
|
|
|
scrollTo = panel.scrollTop() + self.offset().top
|
|
|
|
+ (panel.height() / 2);
|
|
|
|
|
|
|
|
panel.animate({
|
|
|
|
scrollTop: scrollTo
|
|
|
|
}, 'slow');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2012-03-12 11:40:43 +01:00
|
|
|
});
|
2012-03-19 02:05:09 +01:00
|
|
|
|
2012-05-18 02:09:47 +02:00
|
|
|
}(jQuery));
|