From 15d40c5cf1cf77018341a19fc5aa1e562cb7f7a7 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 15 Sep 2007 01:00:03 +0000 Subject: [PATCH] elofgren: USABILITY: Rename 'Save draft' button to 'Save' and make 'Publish' (will be renamed 'Save & Publish') button save the new draft in addition to publishing it. Requested here: http://www.silverstripe.com/google-summer-of-code-forum/flat/1654?showPost=1730#post1730 (merged from branches/gsoc) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@41863 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/CMSMain.php | 11 +---------- code/LeftAndMain.php | 11 ++++++++--- javascript/CMSMain_right.js | 11 ++--------- javascript/LeftAndMain_right.js | 8 +++++++- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/code/CMSMain.php b/code/CMSMain.php index 5d857176..b35938c6 100644 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -315,7 +315,7 @@ JS; } if($record->canEdit()) { - $actions->push(new FormAction('save','Save draft')); + $actions->push(new FormAction('save','Save')); } } } @@ -393,15 +393,6 @@ JS; return "admin/$action"; } - public function publish($urlParams, $form) { - $id = $_REQUEST['ID']; - $record = DataObject::get_by_id("SiteTree", $id); - $form->saveInto($record); - $this->performPublish($record); - - return $this->tellBrowserAboutPublicationChange($record, "Published '$record->Title' successfully"); - } - public function deletefromlive($urlParams, $form) { $id = $_REQUEST['ID']; Versioned::reading_stage('Live'); diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 4924be45..cafaa9e4 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -354,7 +354,7 @@ JS; /** - * Save page handler + * Save and Publish page handler */ public function save($urlParams, $form) { $className = $this->stat('tree_class'); @@ -487,8 +487,13 @@ JS; } - - return FormResponse::respond(); + // If the 'Save & Publish' button was clicked, also publish the page + if (isset($urlParams['publish']) && $urlParams['publish'] == 1) { + $this->performPublish($record); + return $this->tellBrowserAboutPublicationChange($record, "Published '$record->Title' successfully"); + } else { + return FormResponse::respond(); + } } /** diff --git a/javascript/CMSMain_right.js b/javascript/CMSMain_right.js index 2d832f67..37e5d6fe 100755 --- a/javascript/CMSMain_right.js +++ b/javascript/CMSMain_right.js @@ -1,13 +1,6 @@ function action_publish_right() { - $('Form_EditForm').notify('BeforeSave'); - Ajax.SubmitForm('Form_EditForm', 'action_publish', { - onSuccess : function(response) { - Ajax.Evaluator(response); - }, - onFailure : function(response) { - errorMessage('Error publishing content', response); - } - }); + var publish = true; + $('Form_EditForm').save(false, null, 'save', publish); } function action_revert_right() { Ajax.SubmitForm('Form_EditForm', 'action_revert', { diff --git a/javascript/LeftAndMain_right.js b/javascript/LeftAndMain_right.js index 7dcf970b..f21f5d16 100755 --- a/javascript/LeftAndMain_right.js +++ b/javascript/LeftAndMain_right.js @@ -129,8 +129,10 @@ CMSForm.prototype = { /** * Save the contens of the form, by submitting it and resetting is changed checker * on success. + * + * @param publish boolean (optional) whether to publish in addition to saving */ - save: function(ifChanged, callAfter, action) { + save: function(ifChanged, callAfter, action, publish) { _AJAX_LOADING = true; if(typeof tinyMCE != 'undefined') tinyMCE.triggerSave(); if(!action) action = "save"; @@ -160,6 +162,10 @@ CMSForm.prototype = { } else { var data = this.serializeAllFields() + '&ajax=1&action_' + action + '=1'; } + if(publish) + { + data += '&publish=1'; + } statusMessage("Saving...", null, true); new Ajax.Request(this.action, {