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=URLSegment]
|
2010-05-08 04:45:05 +02:00
|
|
|
*
|
|
|
|
* Input validation on the URLSegment field
|
2009-11-21 04:19:59 +01:00
|
|
|
*/
|
2011-03-31 10:51:59 +02:00
|
|
|
$('.cms-edit-form input[name=URLSegment]').entwine({
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2010-05-08 04:45:05 +02:00
|
|
|
/**
|
|
|
|
* Constructor: onmatch
|
|
|
|
*/
|
2009-11-21 04:16:03 +01:00
|
|
|
onmatch : function() {
|
|
|
|
var self = this;
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:03 +01:00
|
|
|
// intercept change event, do our own writing
|
|
|
|
this.bind('change', function(e) {
|
2011-11-14 12:29:58 +01:00
|
|
|
if(!self.val()) return;
|
|
|
|
|
2012-03-09 04:12:07 +01:00
|
|
|
self.addClass('disabled').parents('.field:first').addClass('loading');
|
2011-11-14 12:29:58 +01:00
|
|
|
var oldVal = self.val();
|
|
|
|
self.suggest(oldVal, function(data) {
|
2012-03-09 04:12:07 +01:00
|
|
|
self.removeClass('disabled').parents('.field:first').removeClass('loading');
|
2011-11-14 12:29:58 +01:00
|
|
|
var newVal = decodeURIComponent(data.value);
|
|
|
|
self.val(newVal);
|
|
|
|
|
|
|
|
if(oldVal != newVal) {
|
2012-03-27 06:34:49 +02:00
|
|
|
var confirmMessage = ss.i18n.sprintf(
|
|
|
|
ss.i18n._t('UPDATEURL.CONFIRMURLCHANGED', 'The URL has been changed to\n"%s'),
|
|
|
|
data.value
|
|
|
|
);
|
|
|
|
jQuery.noticeAdd({'text':confirmMessage});
|
2011-11-14 12:29:58 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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
|
|
|
},
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:03 +01:00
|
|
|
/**
|
2011-11-14 12:29:58 +01:00
|
|
|
* Function: suggest
|
2010-05-08 04:45:05 +02:00
|
|
|
*
|
2009-11-21 04:16:03 +01:00
|
|
|
* Return a value matching the criteria.
|
|
|
|
*
|
2010-05-08 04:45:05 +02:00
|
|
|
* Parameters:
|
|
|
|
* (String) val
|
2011-11-14 12:29:58 +01:00
|
|
|
* (Function) callback
|
2010-05-08 04:45:05 +02:00
|
|
|
*/
|
2011-11-14 12:29:58 +01:00
|
|
|
suggest: function(val, callback) {
|
|
|
|
$.get(
|
|
|
|
this.parents('form:first').attr('action') +
|
|
|
|
'/field/URLSegment/suggest/?value=' + encodeURIComponent(this.val()),
|
|
|
|
function(data) {
|
|
|
|
callback.apply(this, arguments);
|
|
|
|
}
|
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;
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:03 +01:00
|
|
|
this.bind('change', function(e) {
|
2011-12-17 05:58:58 +01:00
|
|
|
self.updatePageTitleHeading();
|
2011-03-31 10:51:59 +02:00
|
|
|
self.updateURLSegment(jQuery('.cms-edit-form input[name=URLSegment]'));
|
2009-11-21 04:16:03 +01:00
|
|
|
// TODO We should really user-confirm these changes
|
|
|
|
self.parents('form').find('input[name=MetaTitle], input[name=MenuTitle]').val(self.val());
|
|
|
|
});
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: updatePageTitleHeading
|
|
|
|
*
|
|
|
|
* Update the page title heading when page title changes
|
|
|
|
*/
|
|
|
|
updatePageTitleHeading: function() {
|
2012-01-31 14:37:21 +01:00
|
|
|
$('#page-title-heading').text(this.val());
|
2011-12-17 05:58:58 +01:00
|
|
|
},
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2010-05-08 04:45:05 +02:00
|
|
|
/**
|
|
|
|
* Function: updateURLSegment
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* (DOMElement) field
|
|
|
|
*/
|
2009-11-21 04:16:03 +01:00
|
|
|
updateURLSegment: function(field) {
|
|
|
|
if(!field || !field.length) return;
|
2011-11-14 12:29:58 +01:00
|
|
|
|
|
|
|
// TODO The new URL value is determined asynchronously,
|
|
|
|
// which means we need to come up with an alternative system
|
|
|
|
// to ask user permission to change it.
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:03 +01:00
|
|
|
// TODO language/logic coupling
|
|
|
|
var isNew = this.val().indexOf("new") == 0;
|
2011-11-14 12:29:58 +01:00
|
|
|
var confirmMessage = ss.i18n._t(
|
|
|
|
'UPDATEURL.CONFIRMSIMPLE',
|
|
|
|
'Do you want to update the URL from your new page title?'
|
2009-11-21 04:16:03 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
// don't ask for replacement if record is considered 'new' as defined by its title
|
2011-11-14 12:29:58 +01:00
|
|
|
if(isNew || confirm(confirmMessage)) {
|
|
|
|
field.val(this.val()).trigger('change');
|
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) {
|
|
|
|
// @todo i18n
|
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({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: onclick
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* (Event) e
|
|
|
|
*/
|
2012-01-03 17:57:40 +01:00
|
|
|
onclick: function(e) {
|
2011-09-28 00:48:36 +02:00
|
|
|
var parentTreeDropDown = $('.cms-edit-form.CMSPageSettingsController #ParentID');
|
|
|
|
|
|
|
|
if (e.target.id == 'Form_EditForm_ParentType_root') parentTreeDropDown.slideUp();
|
2012-01-03 17:57:40 +01:00
|
|
|
else parentTreeDropDown.slideDown();
|
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
|
|
|
});
|
|
|
|
}(jQuery));
|