2009-11-21 04:16:03 +01:00
|
|
|
(function($) {
|
2009-11-21 04:19:59 +01:00
|
|
|
$.concrete('ss', function($){
|
|
|
|
/**
|
|
|
|
* Alert the user on change of page-type - this might have implications
|
|
|
|
* on the available form fields etc.
|
|
|
|
* @name ss.EditFormClassName
|
|
|
|
*/
|
|
|
|
$('#Form_EditForm :input[name=ClassName]').concrete(/** @lends ss.EditFormClassName */{
|
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
|
|
|
/**
|
|
|
|
* @class Input validation on the URLSegment field
|
|
|
|
* @name ss.EditForm.URLSegment
|
|
|
|
*/
|
|
|
|
$('#Form_EditForm input[name=URLSegment]').concrete(/** @lends ss.EditForm.URLSegment */{
|
2009-11-21 04:16:03 +01:00
|
|
|
FilterRegex: /[^A-Za-z0-9-]+/,
|
2009-11-21 04:17:54 +01:00
|
|
|
ValidationMessage: ss.i18n._t('CMSMAIN.URLSEGMENTVALIDATION'),
|
2009-11-21 04:16:03 +01:00
|
|
|
MaxLength: 50,
|
2009-11-21 04:19:59 +01:00
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Return a value matching the criteria.
|
|
|
|
*
|
|
|
|
* @param {String} val
|
|
|
|
* @return val
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @class Input validation on the Title field
|
|
|
|
* @name ss.EditForm.Title
|
|
|
|
*/
|
|
|
|
$('#Form_EditForm input[name=Title]').concrete(/** @lends ss.EditForm.Title */{
|
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) {
|
|
|
|
self.updateURLSegment(jQuery('#Form_EditForm input[name=URLSegment]'));
|
|
|
|
// 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
|
|
|
|
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;
|
|
|
|
var suggestion = field.concrete('ss').suggestValue(this.val());
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @class ParentID field combination - mostly toggling between
|
|
|
|
* the two radiobuttons and setting the hidden "ParentID" field
|
|
|
|
* @name ss.EditForm.parentTypeSelector
|
|
|
|
*/
|
|
|
|
$('#Form_EditForm .parentTypeSelector').concrete(/** @lends ss.EditForm.parentTypeSelector */{
|
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
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @class Toggle display of group dropdown in "access" tab,
|
|
|
|
* based on selection of radiobuttons.
|
|
|
|
* @name ss.Form_EditForm.Access
|
|
|
|
*/
|
|
|
|
$('#Form_EditForm #CanViewType, #Form_EditForm #CanEditType').concrete(/** @lends ss.Form_EditForm.Access */{
|
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');
|
2009-11-21 04:19:59 +01:00
|
|
|
|
2009-11-21 04:16:03 +01:00
|
|
|
this.find('.optionset :input').bind('change', function(e) {
|
|
|
|
dropdown.toggle(e.target.value == 'OnlyTheseUsers');
|
|
|
|
});
|
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();
|
|
|
|
dropdown.toggle(currentVal == 'OnlyTheseUsers');
|
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
|
|
|
/**
|
|
|
|
* @class Email containing the link to the archived version of the page.
|
|
|
|
* Visible on readonly older versions of a specific page at the moment.
|
|
|
|
* @name ss.Form_EditForm_action_email
|
|
|
|
*/
|
|
|
|
$('#Form_EditForm .Actions #Form_EditForm_action_email').concrete(/** @lends ss.Form_EditForm_action_email */{
|
2009-11-21 04:16:03 +01:00
|
|
|
onclick: function(e) {
|
|
|
|
window.open(
|
|
|
|
'mailto:?subject='
|
|
|
|
+ $('input[name=ArchiveEmailSubject]', this[0].form).val()
|
|
|
|
+ '&body='
|
|
|
|
+ $(':input[name=ArchiveEmailMessage]', this[0].form).val(),
|
|
|
|
'archiveemail'
|
|
|
|
);
|
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
|
|
|
/**
|
|
|
|
* @class Open a printable representation of the form in a new window.
|
|
|
|
* Used for readonly older versions of a specific page.
|
|
|
|
* @name ss.Form_EditForm_action_print
|
|
|
|
*/
|
|
|
|
$('#Form_EditForm .Actions #Form_EditForm_action_print').concrete(/** @lends ss.Form_EditForm_action_print */{
|
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
|
|
|
/**
|
|
|
|
* @class A "rollback" to a specific version needs user confirmation.
|
|
|
|
* @name ss.Form_EditForm_action_rollback
|
|
|
|
*/
|
|
|
|
$('#Form_EditForm .Actions #Form_EditForm_action_rollback').concrete(/** @lends ss.Form_EditForm_action_rollback */{
|
2009-11-21 04:16:03 +01:00
|
|
|
onclick: function(e) {
|
|
|
|
// @todo i18n
|
|
|
|
return confirm("Do you really want to copy the published content to the stage site?");
|
|
|
|
}
|
2009-11-21 04:19:59 +01:00
|
|
|
});
|
2009-11-21 04:16:03 +01:00
|
|
|
});
|
|
|
|
}(jQuery));
|