Skip to content
This repository
Browse code

Actually merge in Save & Publish, don't just pretend to

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.1.0@42286 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
commit 73b5103a788ee9fbd11f85097834894615e3b287 1 parent d71d3c2
Andrew O'Neil authored September 19, 2007 sminnee committed February 02, 2011
11  code/CMSMain.php
@@ -315,7 +315,7 @@ public function getEditForm($id) {
315 315
 					}
316 316
 					
317 317
 					if($record->canEdit()) {
318  
-						$actions->push(new FormAction('save','Save draft'));
  318
+						$actions->push(new FormAction('save','Save'));
319 319
 					}
320 320
 				}
321 321
 			}
@@ -393,15 +393,6 @@ public function Link($action = null) {
393 393
 		return "admin/$action";
394 394
 	}
395 395
 
396  
-	public function publish($urlParams, $form) {
397  
-		$id = $_REQUEST['ID'];
398  
-		$record = DataObject::get_by_id("SiteTree", $id);
399  
-		$form->saveInto($record);
400  
-		$this->performPublish($record);
401  
-		
402  
-		return $this->tellBrowserAboutPublicationChange($record, "Published '$record->Title' successfully");
403  
-	}
404  
-	
405 396
 	public function deletefromlive($urlParams, $form) {
406 397
 		$id = $_REQUEST['ID'];
407 398
 		Versioned::reading_stage('Live');
10  code/LeftAndMain.php
@@ -353,7 +353,7 @@ public function returnItemToUser($p) {
353 353
 
354 354
 
355 355
 	/**
356  
-	 * Save page handler
  356
+	 * Save and Publish page handler
357 357
 	 */
358 358
 	public function save($urlParams, $form) {
359 359
 		$className = $this->stat('tree_class');
@@ -487,7 +487,13 @@ public function save($urlParams, $form) {
487 487
 
488 488
 		}
489 489
 		
490  
-		return FormResponse::respond();
  490
+		// If the 'Save & Publish' button was clicked, also publish the page
  491
+		if(isset($urlParams['publish']) && $urlParams['publish'] == 1) {
  492
+			$this->performPublish($record);
  493
+			return $this->tellBrowserAboutPublicationChange($record, "Published '$record->Title' successfully");
  494
+		} else {
  495
+			return FormResponse::respond();
  496
+		}
491 497
 	}
492 498
 	
493 499
 	/**
11  javascript/CMSMain_right.js
... ...
@@ -1,13 +1,6 @@
1 1
 function action_publish_right() {
2  
-	$('Form_EditForm').notify('BeforeSave');
3  
-	Ajax.SubmitForm('Form_EditForm', 'action_publish', {
4  
-		onSuccess : function(response) {
5  
-			Ajax.Evaluator(response);
6  
-		},
7  
-		onFailure : function(response) {
8  
-			errorMessage('Error publishing content', response);
9  
-		}
10  
-	});
  2
+	var publish = true;
  3
+	$('Form_EditForm').save(false, null, 'save', publish);
11 4
 }
12 5
 function action_revert_right() {
13 6
 	Ajax.SubmitForm('Form_EditForm', 'action_revert', {
8  javascript/LeftAndMain_right.js
@@ -129,8 +129,10 @@ CMSForm.prototype = {
129 129
 	/**
130 130
 	 * Save the contens of the form, by submitting it and resetting is changed checker
131 131
 	 * on success.
  132
+	 *
  133
+	 * @param publish boolean (optional) whether to publish in addition to saving
132 134
 	 */
133  
-	save: function(ifChanged, callAfter, action) {
  135
+	save: function(ifChanged, callAfter, action, publish) {
134 136
 		_AJAX_LOADING = true;
135 137
 		if(typeof tinyMCE != 'undefined') tinyMCE.triggerSave();
136 138
 		if(!action) action = "save";
@@ -160,6 +162,10 @@ CMSForm.prototype = {
160 162
 		} else {
161 163
 			var data = this.serializeAllFields() + '&ajax=1&action_' + action + '=1';
162 164
 		}
  165
+		if(publish)
  166
+		{
  167
+			data += '&publish=1';
  168
+		}
163 169
 		
164 170
 		statusMessage("Saving...", null, true);
165 171
 		new Ajax.Request(this.action, {

0 notes on commit 73b5103

Please sign in to comment.
Something went wrong with that request. Please try again.