2010-05-08 09:35:35 +02:00
|
|
|
/**
|
|
|
|
* File: CMSMain.EditForm.js
|
|
|
|
*/
|
2009-11-21 04:16:03 +01:00
|
|
|
(function($) {
|
2010-04-13 07:55:56 +02:00
|
|
|
$.entwine('ss', function($){
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
2011-03-31 10:51:59 +02:00
|
|
|
* Class: .cms-edit-form :input[name=ClassName]
|
2010-05-08 04:45:05 +02:00
|
|
|
* Alert the user on change of page-type. This might have implications
|
2009-11-21 04:19:59 +01:00
|
|
|
* on the available form fields etc.
|
|
|
|
*/
|
2011-03-31 10:51:59 +02:00
|
|
|
$('.cms-edit-form :input[name=ClassName]').entwine({
|
2010-05-08 04:45:05 +02:00
|
|
|
// Function: onchange
|
2009-11-21 04:17:54 +01:00
|
|
|
onchange: function() {
|
|
|
|
alert(ss.i18n._t('CMSMAIN.ALERTCLASSNAME'));
|
2009-11-21 04:16:03 +01:00
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
});
|
2009-11-21 04:16:03 +01:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
2011-03-31 10:51:59 +02:00
|
|
|
* Class: .cms-edit-form input[name=Title]
|
2010-05-08 04:45:05 +02:00
|
|
|
*
|
|
|
|
* Input validation on the Title field
|
2009-11-21 04:19:59 +01:00
|
|
|
*/
|
2011-03-31 10:51:59 +02:00
|
|
|
$('.cms-edit-form input[name=Title]').entwine({
|
2010-05-08 04:45:05 +02:00
|
|
|
// Constructor: onmatch
|
2009-11-21 04:16:03 +01:00
|
|
|
onmatch : function() {
|
|
|
|
var self = this;
|
2012-05-10 02:01:57 +02:00
|
|
|
|
2012-05-13 06:55:26 +02:00
|
|
|
var form = self.parents('form');
|
|
|
|
var url_segment = $('.field.urlsegment', form).find(':text');
|
|
|
|
var live_url_segment = $('input[name=LiveURLSegment]', form);
|
|
|
|
|
|
|
|
self._addActions();
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:03 +01:00
|
|
|
this.bind('change', function(e) {
|
2012-05-13 06:55:26 +02:00
|
|
|
var title = self.val();
|
2012-05-10 02:01:57 +02:00
|
|
|
// Criteria for defining a "new" page
|
2012-05-13 06:55:26 +02:00
|
|
|
if ( (url_segment.val().indexOf("new") == 0) && live_url_segment.val() == "" ) {
|
|
|
|
self.updateRelatedFields(title);
|
|
|
|
self.updateURLSegment(title);
|
2012-05-10 02:01:57 +02:00
|
|
|
} else {
|
2012-05-13 06:55:26 +02:00
|
|
|
$('.update', self.parent()).show();
|
2012-05-10 02:01:57 +02:00
|
|
|
}
|
2012-05-13 06:55:26 +02:00
|
|
|
self.updatePanelLabels(title);
|
2009-11-21 04:16:03 +01:00
|
|
|
});
|
2009-11-21 04:19:59 +01:00
|
|
|
|
|
|
|
this._super();
|
2009-11-21 04:16:03 +01:00
|
|
|
},
|
2011-12-17 05:58:58 +01:00
|
|
|
|
|
|
|
/**
|
2012-05-13 06:55:26 +02:00
|
|
|
* Function: updateRelatedFields
|
|
|
|
*
|
|
|
|
* Update the related fields
|
|
|
|
* (String) title
|
|
|
|
*/
|
|
|
|
updateRelatedFields: function(title) {
|
|
|
|
var form = this.parents('form');
|
|
|
|
form.find('input[name=MetaTitle], input[name=MenuTitle]').val(title);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: updateURLSegment
|
|
|
|
*
|
|
|
|
* Update the URLSegment
|
|
|
|
* (String) title
|
|
|
|
*/
|
|
|
|
updateURLSegment: function(title) {
|
|
|
|
var url_segment_field = $('.field.urlsegment', this.parents('form'));
|
|
|
|
var updateURLFromTitle = $('.update', this.parent());
|
|
|
|
url_segment_field.update(title);
|
|
|
|
if (updateURLFromTitle.is(':visible')) {
|
|
|
|
updateURLFromTitle.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: updatePanelLabels
|
2011-12-17 05:58:58 +01:00
|
|
|
*
|
2012-05-13 06:55:26 +02:00
|
|
|
* Update the breadcrumb and tree
|
|
|
|
* (String) title
|
2011-12-17 05:58:58 +01:00
|
|
|
*/
|
2012-05-13 06:55:26 +02:00
|
|
|
updatePanelLabels: function(title) {
|
|
|
|
var pageID = $('.cms-edit-form input[name=ID]').val();
|
|
|
|
var panelCrumb = $('span.cms-panel-link.crumb');
|
|
|
|
var treeItem = $('.item', $('.cms-tree').find("[data-id='" + pageID + "']"));
|
|
|
|
if (title && title != "") {
|
|
|
|
panelCrumb.text(title);
|
|
|
|
treeItem.text(title);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: _addActions
|
|
|
|
*
|
|
|
|
* Utility to add update from title action
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
_addActions: function() {
|
|
|
|
var self = this;
|
|
|
|
var updateURLFromTitle;
|
|
|
|
|
|
|
|
// update button
|
|
|
|
updateURLFromTitle = $('<button />', {
|
|
|
|
'class': 'update ss-ui-button-small',
|
|
|
|
'text': 'Update URL',
|
|
|
|
'click': function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
self.updateURLSegment(self.val());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// insert elements
|
|
|
|
updateURLFromTitle.insertAfter(self);
|
|
|
|
updateURLFromTitle.hide();
|
2009-11-21 04:16:03 +01:00
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
});
|
2009-11-21 04:16:03 +01:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
2011-03-31 10:51:59 +02:00
|
|
|
* Class: .cms-edit-form .parentTypeSelector
|
2010-05-08 04:45:05 +02:00
|
|
|
*
|
|
|
|
* ParentID field combination - mostly toggling between
|
2009-11-21 04:19:59 +01:00
|
|
|
* the two radiobuttons and setting the hidden "ParentID" field
|
|
|
|
*/
|
2011-03-31 10:51:59 +02:00
|
|
|
$('.cms-edit-form .parentTypeSelector').entwine({
|
2010-05-08 04:45:05 +02:00
|
|
|
// Constructor: onmatch
|
2009-11-21 04:16:03 +01:00
|
|
|
onmatch : function() {
|
|
|
|
var self = this;
|
|
|
|
this.find(':input[name=ParentType]').bind('click', function(e) {self._toggleSelection(e);});
|
2012-02-11 00:49:51 +01:00
|
|
|
this.find('.TreeDropdownField').bind('change', function(e) {self._changeParentId(e);});
|
|
|
|
|
|
|
|
this._changeParentId();
|
2009-11-21 04:16:03 +01:00
|
|
|
this._toggleSelection();
|
2009-11-21 04:19:59 +01:00
|
|
|
|
|
|
|
this._super();
|
2009-11-21 04:16:03 +01:00
|
|
|
},
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2010-05-08 04:45:05 +02:00
|
|
|
/**
|
|
|
|
* Function: _toggleSelection
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* (Event) e
|
|
|
|
*/
|
2009-11-21 04:16:03 +01:00
|
|
|
_toggleSelection: function(e) {
|
|
|
|
var selected = this.find(':input[name=ParentType]:checked').val();
|
|
|
|
// reset parent id if 'root' radiobutton is selected
|
|
|
|
if(selected == 'root') this.find(':input[name=ParentID]').val(0);
|
2012-02-11 00:49:51 +01:00
|
|
|
// otherwise use the old value
|
|
|
|
else this.find(':input[name=ParentID]').val(this.find('#Form_EditForm_ParentType_subpage').data('parentIdValue'));
|
2009-11-21 04:16:03 +01:00
|
|
|
// toggle tree dropdown based on selection
|
|
|
|
this.find('#ParentID').toggle(selected != 'root');
|
2012-02-11 00:49:51 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: _changeParentId
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* (Event) e
|
|
|
|
*/
|
|
|
|
_changeParentId: function(e) {
|
|
|
|
var value = this.find(':input[name=ParentID]').val();
|
|
|
|
// set a data attribute so we know what to use in _toggleSelection
|
|
|
|
this.find('#Form_EditForm_ParentType_subpage').data('parentIdValue', value);
|
2009-11-21 04:16:03 +01:00
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
});
|
2009-11-21 04:16:03 +01:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
2011-03-31 10:51:59 +02:00
|
|
|
* Class: .cms-edit-form #CanViewType, .cms-edit-form #CanEditType
|
2010-05-08 04:45:05 +02:00
|
|
|
*
|
|
|
|
* Toggle display of group dropdown in "access" tab,
|
2009-11-21 04:19:59 +01:00
|
|
|
* based on selection of radiobuttons.
|
|
|
|
*/
|
2011-04-30 08:34:52 +02:00
|
|
|
$('.cms-edit-form #CanViewType, .cms-edit-form #CanEditType, .cms-edit-form #CanCreateTopLevelType').entwine({
|
2010-05-08 04:45:05 +02:00
|
|
|
// Constructor: onmatch
|
2009-11-21 04:16:03 +01:00
|
|
|
onmatch: function() {
|
|
|
|
// TODO Decouple
|
|
|
|
var dropdown;
|
|
|
|
if(this.attr('id') == 'CanViewType') dropdown = $('#ViewerGroups');
|
|
|
|
else if(this.attr('id') == 'CanEditType') dropdown = $('#EditorGroups');
|
2011-04-30 08:34:52 +02:00
|
|
|
else if(this.attr('id') == 'CanCreateTopLevelType') dropdown = $('#CreateTopLevelGroups');
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:03 +01:00
|
|
|
this.find('.optionset :input').bind('change', function(e) {
|
2012-03-09 01:14:17 +01:00
|
|
|
var wrapper = $(this).closest('.middleColumn').parent('div');
|
|
|
|
if(e.target.value == 'OnlyTheseUsers') {
|
|
|
|
wrapper.addClass('remove-splitter');
|
|
|
|
dropdown['show']();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
wrapper.removeClass('remove-splitter');
|
|
|
|
dropdown['hide']();
|
|
|
|
}
|
2009-11-21 04:16:03 +01:00
|
|
|
});
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:03 +01:00
|
|
|
// initial state
|
|
|
|
var currentVal = this.find('input[name=' + this.attr('id') + ']:checked').val();
|
2011-04-30 08:34:52 +02:00
|
|
|
dropdown[currentVal == 'OnlyTheseUsers' ? 'show' : 'hide']();
|
2009-11-21 04:19:59 +01:00
|
|
|
|
|
|
|
this._super();
|
2009-11-21 04:16:03 +01:00
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
});
|
2009-11-21 04:16:03 +01:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
2011-03-31 10:51:59 +02:00
|
|
|
* Class: .cms-edit-form .Actions #Form_EditForm_action_print
|
2010-05-08 04:45:05 +02:00
|
|
|
*
|
|
|
|
* Open a printable representation of the form in a new window.
|
2009-11-21 04:19:59 +01:00
|
|
|
* Used for readonly older versions of a specific page.
|
|
|
|
*/
|
2011-03-31 10:51:59 +02:00
|
|
|
$('.cms-edit-form .Actions #Form_EditForm_action_print').entwine({
|
2010-05-08 04:45:05 +02:00
|
|
|
/**
|
|
|
|
* Function: onclick
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* (Event) e
|
|
|
|
*/
|
2009-11-21 04:16:03 +01:00
|
|
|
onclick: function(e) {
|
|
|
|
var printURL = $(this[0].form).attr('action').replace(/\?.*$/,'')
|
|
|
|
+ '/printable/'
|
|
|
|
+ $(':input[name=ID]',this[0].form).val();
|
|
|
|
if(printURL.substr(0,7) != 'http://') printURL = $('base').attr('href') + printURL;
|
|
|
|
|
|
|
|
window.open(printURL, 'printable');
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:03 +01:00
|
|
|
return false;
|
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
});
|
2009-11-21 04:16:03 +01:00
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
/**
|
2011-03-31 10:51:59 +02:00
|
|
|
* Class: .cms-edit-form .Actions #Form_EditForm_action_rollback
|
2010-05-08 04:45:05 +02:00
|
|
|
*
|
|
|
|
* A "rollback" to a specific version needs user confirmation.
|
2009-11-21 04:19:59 +01:00
|
|
|
*/
|
2011-03-31 10:51:59 +02:00
|
|
|
$('.cms-edit-form .Actions #Form_EditForm_action_rollback').entwine({
|
2010-05-08 04:45:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: onclick
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* (Event) e
|
|
|
|
*/
|
2009-11-21 04:16:03 +01:00
|
|
|
onclick: function(e) {
|
2010-04-13 06:26:34 +02:00
|
|
|
var form = this.parents('form:first'), version = form.find(':input[name=Version]').val(), message = '';
|
|
|
|
if(version) {
|
2012-04-10 14:02:05 +02:00
|
|
|
message = ss.i18n.sprintf(
|
|
|
|
ss.i18n._t('CMSMain.RollbackToVersion'),
|
|
|
|
version
|
|
|
|
);
|
2010-04-13 06:26:34 +02:00
|
|
|
} else {
|
2012-04-10 14:02:05 +02:00
|
|
|
message = ss.i18n._t('CMSMain.ConfirmRestoreFromLive');
|
|
|
|
}
|
|
|
|
if(confirm(message)) {
|
|
|
|
return this._super(e);
|
|
|
|
} else {
|
|
|
|
return false;
|
2010-04-13 06:26:34 +02:00
|
|
|
}
|
2009-11-21 04:16:03 +01:00
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
});
|
2011-09-28 00:48:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class: .cms-edit-form.CMSPageSettingsController input[name="ParentType"]:checked
|
|
|
|
*
|
|
|
|
* Showing the "Page location" "Parent page" chooser only when the "Sub-page underneath a parent page"
|
|
|
|
* radio button is selected
|
|
|
|
*/
|
|
|
|
$('.cms-edit-form.CMSPageSettingsController input[name="ParentType"]:checked').entwine({
|
2012-04-23 11:02:29 +02:00
|
|
|
onmatch: function() {
|
2012-04-23 11:21:31 +02:00
|
|
|
this.redraw();
|
2012-04-23 11:02:29 +02:00
|
|
|
this._super();
|
|
|
|
},
|
2012-04-23 11:21:31 +02:00
|
|
|
redraw: function() {
|
|
|
|
var treeField = $('.cms-edit-form.CMSPageSettingsController #ParentID');
|
|
|
|
if ($(this).attr('id') == 'Form_EditForm_ParentType_root') treeField.slideUp();
|
|
|
|
else treeField.slideDown();
|
|
|
|
},
|
|
|
|
onclick: function() {
|
|
|
|
this.redraw();
|
2011-09-28 00:48:36 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//trigger an initial change event to do the initial hiding of the element, if necessary
|
|
|
|
if ($('.cms-edit-form.CMSPageSettingsController input[name="ParentType"]:checked').attr('id') == 'Form_EditForm_ParentType_root') {
|
|
|
|
$('.cms-edit-form.CMSPageSettingsController #ParentID').hide(); //quick hide on first run
|
|
|
|
}
|
2009-11-21 04:16:03 +01:00
|
|
|
});
|
2012-04-21 01:22:55 +02:00
|
|
|
}(jQuery));
|