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({
|
2010-05-08 04:45:05 +02:00
|
|
|
/**
|
|
|
|
* Property: FilterRegex
|
|
|
|
* Regex
|
|
|
|
*/
|
2009-11-21 04:16:03 +01:00
|
|
|
FilterRegex: /[^A-Za-z0-9-]+/,
|
2010-05-08 04:45:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Property: ValidationMessage
|
|
|
|
* String
|
|
|
|
*/
|
2009-11-21 04:17:54 +01:00
|
|
|
ValidationMessage: ss.i18n._t('CMSMAIN.URLSEGMENTVALIDATION'),
|
2010-05-08 04:45:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Property: MaxLength
|
|
|
|
* Int
|
|
|
|
*/
|
2009-11-21 04:16:03 +01:00
|
|
|
MaxLength: 50,
|
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) {
|
|
|
|
if(!self.validate()) {
|
2009-11-21 04:19:59 +01:00
|
|
|
jQuery.noticeAdd(self.getValidationMessage());
|
2009-11-21 04:16:03 +01:00
|
|
|
}
|
|
|
|
self.val(self.suggestValue(e.target.value));
|
|
|
|
return false;
|
|
|
|
});
|
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
|
|
|
/**
|
2010-05-08 04:45:05 +02:00
|
|
|
* Function: suggestValue
|
|
|
|
*
|
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
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* String
|
2009-11-21 04:16:03 +01:00
|
|
|
*/
|
|
|
|
suggestValue: function(val) {
|
|
|
|
// TODO Do we want to enforce lowercasing in URLs?
|
2009-11-21 04:19:59 +01:00
|
|
|
return val.substr(0, this.getMaxLength()).replace(this.getFilterRegex(), '').toLowerCase();
|
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: validate
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Boolean
|
|
|
|
*/
|
2009-11-21 04:16:03 +01:00
|
|
|
validate: function() {
|
|
|
|
return (
|
2009-11-21 04:19:59 +01:00
|
|
|
this.val().length > this.getMaxLength()
|
|
|
|
|| this.val().match(this.getFilterRegex())
|
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-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
|
|
|
},
|
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;
|
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;
|
2010-04-13 07:55:56 +02:00
|
|
|
var suggestion = field.entwine('ss').suggestValue(this.val());
|
2009-11-21 04:16:03 +01:00
|
|
|
var confirmMessage = ss.i18n.sprintf(
|
|
|
|
ss.i18n._t(
|
|
|
|
'UPDATEURL.CONFIRM',
|
|
|
|
'Would you like me to change the URL to:\n\n'
|
|
|
|
+ '%s/\n\nClick Ok to change the URL, '
|
|
|
|
+ 'click Cancel to leave it as:\n\n%s'
|
|
|
|
),
|
|
|
|
suggestion,
|
|
|
|
field.val()
|
|
|
|
);
|
|
|
|
|
|
|
|
// don't ask for replacement if record is considered 'new' as defined by its title
|
|
|
|
if(isNew || (suggestion != field.val() && confirm(confirmMessage))) {
|
|
|
|
field.val(suggestion);
|
|
|
|
}
|
|
|
|
}
|
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);});
|
|
|
|
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);
|
|
|
|
// toggle tree dropdown based on selection
|
|
|
|
this.find('#ParentID').toggle(selected != 'root');
|
|
|
|
}
|
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) {
|
2011-04-30 08:34:52 +02:00
|
|
|
dropdown[e.target.value == 'OnlyTheseUsers' ? 'show' : '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) {
|
|
|
|
message = "Do you really want to roll back to version #" + version + " of this page?";
|
|
|
|
} else {
|
|
|
|
message = "Do you really want to copy the published content to the stage site?";
|
|
|
|
}
|
|
|
|
return confirm(message);
|
2009-11-21 04:16:03 +01:00
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
});
|
2009-11-21 04:16:03 +01:00
|
|
|
});
|
|
|
|
}(jQuery));
|