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-06-22 03:02:35 +02:00
|
|
|
|
|
|
|
self.data('OrigVal', self.val());
|
2012-05-10 02:01:57 +02:00
|
|
|
|
2013-02-04 20:47:23 +01:00
|
|
|
var form = self.closest('form');
|
|
|
|
var urlSegmentInput = $('input:text[name=URLSegment]', form);
|
|
|
|
var liveLinkInput = $('input[name=LiveLink]', form);
|
2012-05-22 04:04:20 +02:00
|
|
|
|
2013-02-04 20:47:23 +01:00
|
|
|
if (urlSegmentInput.length > 0) {
|
|
|
|
self._addActions();
|
2012-05-22 04:04:20 +02:00
|
|
|
this.bind('change', function(e) {
|
2012-06-22 03:02:35 +02:00
|
|
|
var origTitle = self.data('OrigVal');
|
2012-05-22 04:04:20 +02:00
|
|
|
var title = self.val();
|
2012-06-22 03:02:35 +02:00
|
|
|
self.data('OrigVal', title);
|
|
|
|
|
2012-05-22 04:04:20 +02:00
|
|
|
// Criteria for defining a "new" page
|
2013-02-04 20:47:23 +01:00
|
|
|
if ((urlSegmentInput.val().indexOf('new') == 0) && liveLinkInput.val() == '') {
|
2012-05-22 04:04:20 +02:00
|
|
|
self.updateURLSegment(title);
|
|
|
|
} else {
|
|
|
|
$('.update', self.parent()).show();
|
|
|
|
}
|
2012-06-22 03:02:35 +02:00
|
|
|
|
|
|
|
self.updateRelatedFields(title, origTitle);
|
2012-06-18 07:34:35 +02:00
|
|
|
self.updateBreadcrumbLabel(title);
|
2012-05-22 04:04:20 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-11-21 04:19:59 +01:00
|
|
|
this._super();
|
2009-11-21 04:16:03 +01:00
|
|
|
},
|
2012-05-14 01:43:55 +02:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
2011-12-17 05:58:58 +01:00
|
|
|
|
|
|
|
/**
|
2012-05-13 06:55:26 +02:00
|
|
|
* Function: updateRelatedFields
|
|
|
|
*
|
2012-06-22 03:02:35 +02:00
|
|
|
* Update the related fields if appropriate
|
|
|
|
* (String) title The new title
|
|
|
|
* (Stirng) origTitle The original title
|
2012-05-13 06:55:26 +02:00
|
|
|
*/
|
2012-06-22 03:02:35 +02:00
|
|
|
updateRelatedFields: function(title, origTitle) {
|
|
|
|
// Update these fields only if their value was originally the same as the title
|
|
|
|
this.parents('form').find('input[name=MetaTitle], input[name=MenuTitle]').each(function() {
|
|
|
|
var $this = $(this);
|
|
|
|
if($this.val() == origTitle) {
|
|
|
|
$this.val(title);
|
|
|
|
// Onchange bubbling didn't work in IE8, so .trigger('change') couldn't be used
|
|
|
|
if($this.updatedRelatedFields) $this.updatedRelatedFields();
|
|
|
|
}
|
|
|
|
});
|
2012-05-13 06:55:26 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: updateURLSegment
|
|
|
|
*
|
|
|
|
* Update the URLSegment
|
|
|
|
* (String) title
|
|
|
|
*/
|
|
|
|
updateURLSegment: function(title) {
|
2013-02-04 20:47:23 +01:00
|
|
|
var urlSegmentInput = $('input:text[name=URLSegment]', this.closest('form'));
|
|
|
|
var urlSegmentField = urlSegmentInput.closest('.field.urlsegment');
|
2012-05-13 06:55:26 +02:00
|
|
|
var updateURLFromTitle = $('.update', this.parent());
|
2013-02-04 20:47:23 +01:00
|
|
|
urlSegmentField.update(title);
|
2012-05-13 06:55:26 +02:00
|
|
|
if (updateURLFromTitle.is(':visible')) {
|
|
|
|
updateURLFromTitle.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2012-06-18 07:34:35 +02:00
|
|
|
* Function: updateBreadcrumbLabel
|
2011-12-17 05:58:58 +01:00
|
|
|
*
|
2012-06-18 07:34:35 +02:00
|
|
|
* Update the breadcrumb
|
2012-05-13 06:55:26 +02:00
|
|
|
* (String) title
|
2011-12-17 05:58:58 +01:00
|
|
|
*/
|
2012-06-18 07:34:35 +02:00
|
|
|
updateBreadcrumbLabel: function(title) {
|
2012-05-13 06:55:26 +02:00
|
|
|
var pageID = $('.cms-edit-form input[name=ID]').val();
|
|
|
|
var panelCrumb = $('span.cms-panel-link.crumb');
|
|
|
|
if (title && title != "") {
|
|
|
|
panelCrumb.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',
|
2015-01-13 11:36:09 +01:00
|
|
|
'text': ss.i18n._t('URLSEGMENT.UpdateURL'),
|
2012-05-13 06:55:26 +02:00
|
|
|
'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
|
|
|
},
|
2012-05-14 01:43:55 +02:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
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
|
|
|
|
2012-05-14 01:43:55 +02:00
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
onunmatch: function() {
|
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
|
|
|
|
2012-11-21 21:46:45 +01:00
|
|
|
/**
|
|
|
|
* Enable save buttons upon detecting changes to content.
|
|
|
|
* "changed" class is added by jQuery.changetracker.
|
|
|
|
*/
|
2012-12-17 23:02:32 +01:00
|
|
|
$('.cms-edit-form.changed').entwine({
|
2012-11-21 21:46:45 +01:00
|
|
|
onmatch: function(e) {
|
2012-12-17 23:02:32 +01:00
|
|
|
this.find('button[name=action_save]').button('option', 'showingAlternate', true);
|
|
|
|
this.find('button[name=action_publish]').button('option', 'showingAlternate', true);
|
2012-11-21 21:46:45 +01:00
|
|
|
this._super(e);
|
|
|
|
},
|
|
|
|
onunmatch: function(e) {
|
2013-01-21 00:56:02 +01:00
|
|
|
var saveButton = this.find('button[name=action_save]');
|
2014-02-17 02:34:12 +01:00
|
|
|
if(saveButton.data('button')) saveButton.button('option', 'showingAlternate', false);
|
2013-01-21 00:56:02 +01:00
|
|
|
var publishButton = this.find('button[name=action_publish]');
|
2014-02-17 02:34:12 +01:00
|
|
|
if(publishButton.data('button')) publishButton.button('option', 'showingAlternate', false);
|
2012-11-21 21:46:45 +01:00
|
|
|
this._super(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.cms-edit-form .Actions button[name=action_publish]').entwine({
|
|
|
|
/**
|
|
|
|
* Bind to ssui.button event to trigger stylistic changes.
|
|
|
|
*/
|
|
|
|
onbuttonafterrefreshalternate: function() {
|
|
|
|
if (this.button('option', 'showingAlternate')) {
|
|
|
|
this.addClass('ss-ui-action-constructive');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.removeClass('ss-ui-action-constructive');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.cms-edit-form .Actions button[name=action_save]').entwine({
|
|
|
|
/**
|
|
|
|
* Bind to ssui.button event to trigger stylistic changes.
|
|
|
|
*/
|
|
|
|
onbuttonafterrefreshalternate: function() {
|
|
|
|
if (this.button('option', 'showingAlternate')) {
|
|
|
|
this.addClass('ss-ui-action-constructive');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.removeClass('ss-ui-action-constructive');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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-05-14 01:43:55 +02:00
|
|
|
onunmatch: function() {
|
|
|
|
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));
|