ENHANCEMENT Removed some javascript handlers for ajax submission in CMS: action_save_right(), action_publish_right() - they're now using the same unified saving method

ENHANCEMENT Moved javascript handlers in CMS to concrete: action_print_right(), action_email_right(), action_rollback_right()
ENHANCEMENT Moved javascript ParentID UI element in CMS to concrete

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92604 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-11-21 02:36:13 +00:00
parent c5eadd81ab
commit afc285cb12
4 changed files with 100 additions and 104 deletions

View File

@ -745,6 +745,12 @@ JS;
echo sprintf(_t('CMSMain.ROLLEDBACKPUB',"Rolled back to published version. New version number is #%d"),$record->Version);
}
}
function publish($urlParams, $form) {
$urlParams['publish'] = '1';
return $this->save($urlParams, $form);
}
function unpublish() {
$SQL_id = Convert::raw2sql($_REQUEST['ID']);

View File

@ -76,6 +76,100 @@
return layout;
}
}}});
/**
* CMS-specific form behaviour
*/
$('#Form_EditForm').concrete({
onmatch: function() {
// Alert the user on change of page-type - this might have implications
// on the available form fields etc.
this.find(':input[name=ClassName]').bind('change',
function() {
alert('The page type will be updated after the page is saved');
}
);
this.find(':input[name=ParentID]')
}
});
/**
* ParentType / ParentID field combination - mostly toggling between
* the two radiobuttons and setting the hidden "ParentID" field
*/
$('#Form_EditForm_ParentType').concrete({
onmatch : function() {
var parentTypeRootEl = $('#Form_EditForm_ParentType_root');
var parentTypeSubpageEl = $('#Form_EditForm_ParentType_subpage');
if(parentTypeRootEl) {
parentTypeRootEl.onclick = this.rootClick.bind(this);
}
if(parentTypeSubpageEl) {
parentTypeSubpageEl.onclick = this.showHide;
}
this.showHide();
},
rootClick : function() {
$('#Form_EditForm_ParentID').val(0);
this.showHide();
},
showHide : function() {
var parentTypeRootEl = $('#Form_EditForm_ParentType_root');
if(parentTypeRootEl && parentTypeRootEl.checked) {
$('#ParentID').hide();
} else {
$('#ParentID').show();
}
}
});
/**
* Email containing the link to the archived version of the page.
* Visible on readonly older versions of a specific page at the moment.
*/
$('#Form_EditForm .Actions #Form_EditForm_action_email').concrete({
onclick: function(e) {
window.open(
'mailto:?subject='
+ $('input[name=ArchiveEmailSubject]', this[0].form).val()
+ '&body='
+ $(':input[name=ArchiveEmailMessage]', this[0].form).val(),
'archiveemail'
);
return false;
}
});
/**
* Open a printable representation of the form in a new window.
* Used for readonly older versions of a specific page.
*/
$('#Form_EditForm .Actions #Form_EditForm_action_print').concrete({
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');
return false;
}
});
/**
* A "rollback" to a specific version needs user confirmation.
*/
$('#Form_EditForm .Actions #Form_EditForm_action_rollback').concrete({
onclick: function(e) {
// @todo i18n
return confirm("Do you really want to copy the published content to the stage site?");
}
});
})(jQuery);

View File

@ -1,59 +1,4 @@
function action_publish_right() {
$('Form_EditForm_action_publish').value = ss.i18n._t('CMSMAIN.PUBLISHING');
$('Form_EditForm_action_publish').className = 'action loading';
var publish = true;
$('Form_EditForm').save(false, null, 'save', publish);
}
function action_revert_right() {
$('Form_EditForm_action_revert').value = ss.i18n._t('CMSMAIN.RESTORING');
$('Form_EditForm_action_revert').className = 'action loading';
Ajax.SubmitForm('Form_EditForm', 'action_revert', {
onSuccess : Ajax.Evaluator,
onFailure : function(response) {
errorMessage(ss.i18n._t('CMSMAIN.ERRORREVERTING'), response);
}
});
}
function action_rollback_right() {
var options = {
OK: function() {
var pageID = $('Form_EditForm').elements.ID.value;
Ajax.SubmitForm('Form_EditForm', 'action_rollback', {
onSuccess : function(response) {
$('Form_EditForm').getPageFromServer(pageID);
statusMessage(response.responseText,'good');
},
onFailure : function(response) {
errorMessage('Error rolling back content', response);
}
});
},
Cancel:function() {
}
}
if(confirm("Do you really want to copy the published content to the stage site?")) {
options.OK();
} else {
return false;
}
}
/**
* Email containing the link to the archived version of the page
*/
function action_email_right() {
window.open( 'mailto:?subject=' + $('Form_EditForm_ArchiveEmailSubject').value + '&body=' + $('Form_EditForm_ArchiveEmailMessage').value, 'archiveemail' );
}
function action_print_right() {
var printURL = $('Form_EditForm').action.replace(/\?.*$/,'') + '/printable/' + $('Form_EditForm').elements.ID.value;
if(printURL.substr(0,7) != 'http://') printURL = baseHref() + printURL;
window.open(printURL, 'printable');
}
function suggestStageSiteLink() {
var el = $('viewStageSite');
@ -81,45 +26,10 @@ Behaviour.register({
});
Behaviour.register({
'select#Form_EditForm_ClassName' : {
onchange: function() {
alert('The page type will be updated after the page is saved');
}
},
'#Form_EditForm' : {
changeDetection_fieldsToIgnore : {
'restricted-chars[Form_EditForm_URLSegment]' : true,
'Sort' : true
}
},
// ParentType / ParentID field combination
'#Form_EditForm_ParentType' : {
initialize : function() {
var parentTypeRootEl = $('Form_EditForm_ParentType_root');
var parentTypeSubpageEl = $('Form_EditForm_ParentType_subpage');
if(parentTypeRootEl) {
parentTypeRootEl.onclick = this.rootClick.bind(this);
}
if(parentTypeSubpageEl) {
parentTypeSubpageEl.onclick = this.showHide;
}
this.showHide();
},
rootClick : function() {
$('Form_EditForm_ParentID').setValue(0);
this.showHide();
},
showHide : function() {
var parentTypeRootEl = $('Form_EditForm_ParentType_root');
if(parentTypeRootEl && parentTypeRootEl.checked) {
Element.hide('ParentID');
} else {
Element.show('ParentID');
}
}
}
});

View File

@ -317,20 +317,6 @@ CMSRightForm.prototype = {
CMSForm.applyTo('#Form_SubForm');
CMSRightForm.applyTo('#Form_EditForm', 'right');
function action_save_right() {
_AJAX_LOADING = true;
$('Form_EditForm_action_save').value = ss.i18n._t('CMSMAIN.SAVING');
$('Form_EditForm_action_save').className = 'action loading';
$('Form_EditForm_action_save').stopLoading = function() {
if($('Form_EditForm_action_save') && $('Form_EditForm_action_save').className.indexOf('loading') != -1) {
$('Form_EditForm_action_save').value = 'Save';
Element.removeClassName($('Form_EditForm_action_save'), 'loading');
}
}
$('Form_EditForm').save(false);
}
/**
* Handle auto-saving. Detects if changes have been made, and if so save everything on the page.
* If confirmation is true it will ask for confirmation.