From 266acd409dc1d3be3c92a9c4af51446181253d39 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 6 Jan 2009 02:18:33 +0000 Subject: [PATCH] ENHANCEMENT Moved batch forms in CMSMain and AssetAdmin from hardcoded templates to SilverStripe forms. Enhances styling capabilities, unifies HTML syntax, better support for unobtrusive scripting, validation and field additions. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@69744 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/AssetAdmin.php | 23 +++++++++++++++ code/CMSMain.php | 42 +++++++++++++++++++++++++++ css/cms_left.css | 6 +++- javascript/AssetAdmin.js | 15 +++++----- javascript/CMSMain_left.js | 12 ++++---- templates/Includes/AssetAdmin_left.ss | 8 +---- templates/Includes/CMSMain_left.ss | 17 ++--------- 7 files changed, 88 insertions(+), 35 deletions(-) diff --git a/code/AssetAdmin.php b/code/AssetAdmin.php index 7879f082..a6dc080a 100755 --- a/code/AssetAdmin.php +++ b/code/AssetAdmin.php @@ -32,6 +32,7 @@ class AssetAdmin extends LeftAndMain { 'addfolder', 'deletefolder', 'deletemarked', + 'DeleteItemsForm', 'deleteUnusedThumbnails', 'doUpload', 'getfile', @@ -541,6 +542,28 @@ JS; } } + /** + * @return Form + */ + function DeleteItemsForm() { + $form = new Form( + $this, + 'DeleteItemsForm', + new FieldSet( + new LiteralField('SelectedPagesNote', + sprintf('

%s

', _t('AssetAdmin_left.ss.SELECTTODEL','Select the folders that you want to delete and then click the button below')) + ), + new HiddenField('csvIDs') + ), + new FieldSet( + new FormAction('deletefolder', _t('AssetAdmin_left.ss.DELFOLDERS','Delete the selected folders')) + ) + ); + $form->addExtraClass('actionparams'); + + return $form; + } + /** * Delete a folder */ diff --git a/code/CMSMain.php b/code/CMSMain.php index 9bcb33e4..217dc15e 100644 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -36,6 +36,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr 'delete', 'deletefromlive', 'deleteitems', + 'DeleteItemsForm', 'dialog', 'duplicate', 'duplicatewithchildren', @@ -45,6 +46,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr 'getversion', 'publishall', 'publishitems', + 'PublishItemsForm', 'restorepage', 'revert', 'rollback', @@ -1091,6 +1093,25 @@ HTML; return FormResponse::respond(); } + + /** + * @return Form + */ + public function PublishItemsForm() { + $form = new Form( + $this, + 'PublishItemsForm', + new FieldSet( + new HiddenField('csvIDs'), + new CheckboxField('ShowDrafts', _t('CMSMain_left.ss.SHOWONLYCHANGED','Show only changed pages')) + ), + new FieldSet( + new FormAction('publishitems', _t('CMSMain_left.ss.PUBLISHCONFIRM','Publish the selected pages')) + ) + ); + $form->addExtraClass('actionparams'); + return $form; + } /** * Delete a number of items. @@ -1183,6 +1204,27 @@ HTML; return FormResponse::respond(); } + + /** + * @return Form + */ + function DeleteItemsForm() { + $form = new Form( + $this, + 'DeleteItemsForm', + new FieldSet( + new LiteralField('SelectedPagesNote', + sprintf('

%s

', _t('CMSMain_left.ss.SELECTPAGESACTIONS','Select the pages that you want to change & then click an action:')) + ), + new HiddenField('csvIDs') + ), + new FieldSet( + new FormAction('deleteitems', _t('CMSMain_left.ss.DELETECONFIRM','Delete the selected pages')) + ) + ); + $form->addExtraClass('actionparams'); + return $form; + } function buildbrokenlinks() { if($this->urlParams['ID']) { diff --git a/css/cms_left.css b/css/cms_left.css index 28e38599..6443e4be 100644 --- a/css/cms_left.css +++ b/css/cms_left.css @@ -21,7 +21,7 @@ width: 5%; } -#deletepage_options p { +#Form_DeleteItemsForm p { margin: 4px 0; font-size: 11px; color: #666; @@ -192,6 +192,10 @@ ul.tree span.a span.modified, margin-right: 2px; } +#treepanes form .field { + margin: 0; +} + .listpane p { margin: 3px 3px 7px 3px; font-size: 10px; diff --git a/javascript/AssetAdmin.js b/javascript/AssetAdmin.js index 5623a8b9..c04ca8ed 100755 --- a/javascript/AssetAdmin.js +++ b/javascript/AssetAdmin.js @@ -11,7 +11,7 @@ SiteTreeHandlers.controller_url = 'admin/assets'; var _HANDLER_FORMS = { addpage : 'addpage_options', - deletepage : 'deletepage_options', + deletepage : 'Form_DeleteItemsForm', sortitems : 'sortitems_options' }; @@ -330,7 +330,7 @@ deletefolder = { button_onclick : function() { if(treeactions.toggleSelection(this)) { deletefolder.o1 = $('sitetree').observeMethod('SelectionChanged', deletefolder.treeSelectionChanged); - deletefolder.o2 = $('deletepage_options').observeMethod('Close', deletefolder.popupClosed); + deletefolder.o2 = $('Form_DeleteItemsForm').observeMethod('Close', deletefolder.popupClosed); addClass($('sitetree'),'multiselect'); @@ -367,7 +367,7 @@ deletefolder = { popupClosed : function() { removeClass($('sitetree'),'multiselect'); $('sitetree').stopObserving(deletefolder.o1); - $('deletepage_options').stopObserving(deletefolder.o2); + $('Form_DeleteItemsForm').stopObserving(deletefolder.o2); for(var idx in deletefolder.selectedNodes) { if(deletefolder.selectedNodes[idx]) { @@ -391,11 +391,11 @@ deletefolder = { } if(csvIDs) { - $('deletepage_options').elements.csvIDs.value = csvIDs; + $('Form_DeleteItemsForm').elements.csvIDs.value = csvIDs; statusMessage('deleting pages'); - Ajax.SubmitForm('deletepage_options', null, { + Ajax.SubmitForm('Form_DeleteItemsForm', null, { onSuccess : deletefolder.submit_success, onFailure : function(response) { errorMessage('Error deleting pages', response); @@ -464,11 +464,12 @@ Behaviour.register({ */ appendLoader(function () { // Set up delete page - Observable.applyTo($('deletepage_options')); + Observable.applyTo($('Form_DeleteItemsForm')); if($('deletepage')) { $('deletepage').onclick = deletefolder.button_onclick; $('deletepage').getElementsByTagName('button')[0].onclick = function() { return false; }; - $('deletepage_options').onsubmit = deletefolder.form_submit; + $('Form_DeleteItemsForm').onsubmit = deletefolder.form_submit; + Element.hide('Form_DeleteItemsForm'); } new CheckBoxRange($('Form_EditForm'), 'Files[]'); diff --git a/javascript/CMSMain_left.js b/javascript/CMSMain_left.js index 7b57f8fa..63b757ad 100755 --- a/javascript/CMSMain_left.js +++ b/javascript/CMSMain_left.js @@ -290,7 +290,7 @@ batchActionGlobals = { * Publish selected pages action */ publishpage = Class.create(); -publishpage.applyTo('#publishpage_options'); +publishpage.applyTo('#Form_PublishItemsForm'); publishpage.prototype = { onsubmit : function() { csvIDs = batchActionGlobals.getCsvIds(); @@ -300,11 +300,11 @@ publishpage.prototype = { statusMessage(ss.i18n._t('CMSMAIN.PUBLISHINGPAGES')); // Put an AJAXY loading icon on the button - $('action_publish_selected').className = 'loading'; + $('Form_PublishItemsForm_action_publishitems').className = 'loading'; Ajax.SubmitForm(this, null, { onSuccess : function(response) { Ajax.Evaluator(response); - $('action_publish_selected').className = ''; + $('Form_PublishItemsForm_action_publishitems').className = ''; treeactions.closeSelection($('batchactions')); }, onFailure : function(response) { @@ -324,7 +324,7 @@ publishpage.prototype = { * Delete selected pages action */ deletepage = Class.create(); -deletepage.applyTo('#deletepage_options'); +deletepage.applyTo('#Form_DeleteItemsForm'); deletepage.prototype = { onsubmit : function() { csvIDs = batchActionGlobals.getCsvIds(); @@ -352,11 +352,11 @@ deletepage.prototype = { batchActionGlobals.newNodes = new Array(); // Put an AJAXY loading icon on the button - $('action_delete_selected').className = 'loading'; + $('Form_DeleteItemsForm_action_deleteitems').className = 'loading'; Ajax.SubmitForm(this, null, { onSuccess : function(response) { Ajax.Evaluator(response); - $('action_delete_selected').className = ''; + $('Form_DeleteItemsForm_action_deleteitems').className = ''; treeactions.closeSelection($('batchactions')); }, onFailure : function(response) { diff --git a/templates/Includes/AssetAdmin_left.ss b/templates/Includes/AssetAdmin_left.ss index a8ea73e7..4222579b 100755 --- a/templates/Includes/AssetAdmin_left.ss +++ b/templates/Includes/AssetAdmin_left.ss @@ -12,13 +12,7 @@ - + $DeleteItemsForm <% control DuplicatePagesOptionsForm %>