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') {
|
2013-03-25 23:41:21 +01:00
|
|
|
var parentField = this.closest('form').find('#ParentID .TreeDropdownField')
|
2012-05-07 14:30:08 +02:00
|
|
|
parentField.setValue('');
|
2013-03-25 23:41:21 +01:00
|
|
|
parentField.setTitle('');
|
2012-05-07 14:30:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-05-08 13:36:55 +02:00
|
|
|
|
|
|
|
$(".cms-add-form").entwine({
|
2013-04-08 01:03:12 +02:00
|
|
|
onadd: function() {
|
2011-05-08 13:36:55 +02:00
|
|
|
var self = this;
|
|
|
|
this.find('#ParentID .TreeDropdownField').bind('change', function() {
|
|
|
|
self.updateTypeList();
|
|
|
|
});
|
2012-01-05 17:01:48 +01:00
|
|
|
this.updateTypeList();
|
2012-05-14 01:43:55 +02:00
|
|
|
},
|
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({
|
2013-03-12 23:05:47 +01:00
|
|
|
onclick: function(e) {
|
2012-01-05 17:01:48 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
2013-11-11 13:31:32 +01:00
|
|
|
|
2011-04-24 01:05:01 +02:00
|
|
|
$(".cms-page-add-button").entwine({
|
|
|
|
onclick: function(e) {
|
2013-03-14 18:59:19 +01:00
|
|
|
var tree = $('.cms-tree'), list = $('.cms-list'), parentId = 0;
|
|
|
|
|
|
|
|
// Choose parent ID either from tree or list view, depending which is visible
|
|
|
|
if(tree.is(':visible')) {
|
|
|
|
var selected = tree.jstree('get_selected');
|
|
|
|
parentId = selected ? $(selected[0]).data('id') : null;
|
|
|
|
} else {
|
|
|
|
var state = list.find('input[name="Page[GridState]"]').val();
|
|
|
|
if(state) parentId = parseInt(JSON.parse(state).ParentID, 10);
|
|
|
|
}
|
|
|
|
|
2013-04-30 16:54:18 +02:00
|
|
|
var data = {selector: this.data('targetPanel'),pjax: this.data('pjax')}, url;
|
2013-05-14 16:38:07 +02:00
|
|
|
if(parentId) {
|
|
|
|
extraParams = this.data('extraParams') ? this.data('extraParams') : '';
|
|
|
|
url = $.path.addSearchParams(ss.i18n.sprintf(this.data('urlAddpage'), parentId), extraParams);
|
2013-04-30 16:54:18 +02:00
|
|
|
} else {
|
|
|
|
url = this.attr('href');
|
|
|
|
}
|
2012-06-03 19:54:14 +02:00
|
|
|
|
|
|
|
$('.cms-container').loadPanel(url, null, data);
|
2011-04-24 01:05:01 +02:00
|
|
|
e.preventDefault();
|
2012-06-03 19:54:14 +02:00
|
|
|
|
2013-12-16 15:44:24 +01:00
|
|
|
// Remove focussed state from button
|
|
|
|
this.blur();
|
|
|
|
|
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));
|