2011-04-24 01:05:01 +02:00
|
|
|
(function($) {
|
|
|
|
$.entwine('ss', function($){
|
2012-05-07 14:30:08 +02:00
|
|
|
/**
|
|
|
|
* Reset the parent node selection if the type is
|
|
|
|
* set back to "toplevel page", to avoid submitting inconsistent state.
|
|
|
|
*/
|
|
|
|
$(".cms-add-form .parent-mode :input").entwine({
|
|
|
|
onclick: function(e) {
|
|
|
|
if(this.val() == 'top') {
|
|
|
|
var parentField = this.closest('form').find('#ParentID .TreeDropdownField');
|
|
|
|
parentField.setValue('');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-05-08 13:36:55 +02:00
|
|
|
|
|
|
|
$(".cms-add-form").entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
var self = this;
|
|
|
|
this.find('#ParentID .TreeDropdownField').bind('change', function() {
|
|
|
|
self.updateTypeList();
|
|
|
|
});
|
2012-01-05 17:01:48 +01:00
|
|
|
this.updateTypeList();
|
2012-05-11 07:37:31 +02:00
|
|
|
this._super();
|
2011-05-08 13:36:55 +02:00
|
|
|
},
|
2012-05-14 01:43:55 +02:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
2011-05-08 13:36:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Limit page type selection based on parent class.
|
|
|
|
* Similar implementation to LeftAndMain.Tree.js.
|
|
|
|
*/
|
|
|
|
updateTypeList: function() {
|
|
|
|
var hints = this.find('.hints').data('hints'),
|
|
|
|
metadata = this.find('#ParentID .TreeDropdownField').data('metadata'),
|
|
|
|
id = this.find('#ParentID .TreeDropdownField').getValue(),
|
2012-12-03 16:33:06 +01:00
|
|
|
newClassName = (id && metadata) ? metadata.ClassName : null,
|
|
|
|
hintKey = (newClassName) ? newClassName : 'Root',
|
|
|
|
hint = (typeof hints[hintKey] != 'undefined') ? hints[hintKey] : null,
|
|
|
|
allAllowed = true;
|
2012-01-09 13:20:11 +01:00
|
|
|
|
|
|
|
var disallowedChildren = (hint && typeof hint.disallowedChildren != 'undefined') ? hint.disallowedChildren : [],
|
|
|
|
defaultChildClass = (hint && typeof hint.defaultChild != 'undefined') ? hint.defaultChild : null;
|
2011-05-08 13:36:55 +02:00
|
|
|
|
|
|
|
// Limit selection
|
|
|
|
this.find('#PageType li').each(function() {
|
2012-12-03 16:33:06 +01:00
|
|
|
var className = $(this).find('input').val(),
|
|
|
|
isAllowed = ($.inArray(className, disallowedChildren) == -1);
|
|
|
|
|
2011-05-08 13:36:55 +02:00
|
|
|
$(this).setEnabled(isAllowed);
|
2012-12-03 16:33:06 +01:00
|
|
|
if(!isAllowed) $(this).setSelected(false);
|
|
|
|
allAllowed = allAllowed && isAllowed;
|
2011-05-08 13:36:55 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Set default child selection, or fall back to first available option
|
|
|
|
if(defaultChildClass) {
|
|
|
|
var selectedEl = this.find('#PageType li input[value=' + defaultChildClass + ']').parents('li:first');
|
|
|
|
} else {
|
|
|
|
var selectedEl = this.find('#PageType li:not(.disabled):first');
|
|
|
|
}
|
|
|
|
selectedEl.setSelected(true);
|
|
|
|
selectedEl.siblings().setSelected(false);
|
2012-09-11 04:56:13 +02:00
|
|
|
|
|
|
|
// Disable the "Create" button if none of the pagetypes are available
|
|
|
|
var buttonState = (this.find('#PageType li:not(.disabled)').length) ? 'enable' : 'disable';
|
|
|
|
this.find('button[name=action_doAdd]').button(buttonState);
|
2012-12-03 16:33:06 +01:00
|
|
|
|
|
|
|
this.find('.message-restricted')[allAllowed ? 'hide' : 'show']();
|
2011-05-08 13:36:55 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".cms-add-form #PageType li").entwine({
|
2012-01-05 17:01:48 +01:00
|
|
|
onclick: function() {
|
|
|
|
this.setSelected(true);
|
|
|
|
},
|
2011-05-08 13:36:55 +02:00
|
|
|
setSelected: function(bool) {
|
2012-01-06 16:54:16 +01:00
|
|
|
var input = this.find('input');
|
2011-05-08 13:36:55 +02:00
|
|
|
this.toggleClass('selected', bool);
|
2012-01-06 16:54:16 +01:00
|
|
|
if(bool && !input.is(':disabled')) {
|
2012-01-05 17:01:48 +01:00
|
|
|
this.siblings().setSelected(false);
|
2012-01-06 16:54:16 +01:00
|
|
|
input.attr('checked', 'checked');
|
2012-01-05 17:01:48 +01:00
|
|
|
}
|
2011-05-08 13:36:55 +02:00
|
|
|
},
|
|
|
|
setEnabled: function(bool) {
|
2012-01-05 17:01:48 +01:00
|
|
|
$(this).toggleClass('disabled', !bool);
|
|
|
|
if(!bool) $(this).find('input').attr('disabled', 'disabled').removeAttr('checked');
|
|
|
|
else $(this).find('input').removeAttr('disabled');
|
2011-04-24 01:05:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".cms-page-add-button").entwine({
|
|
|
|
onclick: function(e) {
|
2012-06-03 19:54:14 +02:00
|
|
|
var selected = $('.cms-tree').jstree('get_selected'),
|
|
|
|
parentId = selected ? $(selected[0]).data('id') : null,
|
|
|
|
data = {selector: this.data('targetPanel'),pjax: this.data('pjax')},
|
|
|
|
url = parentId ? ss.i18n.sprintf(this.data('urlAddpage'), parentId) : this.attr('href');
|
|
|
|
|
|
|
|
$('.cms-container').loadPanel(url, null, data);
|
2011-04-24 01:05:01 +02:00
|
|
|
e.preventDefault();
|
2012-06-03 19:54:14 +02:00
|
|
|
|
|
|
|
// $('.cms-page-add-form-dialog').dialog('open');
|
|
|
|
// e.preventDefault();
|
2011-04-24 01:05:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2012-05-11 07:37:31 +02:00
|
|
|
}(jQuery));
|