diff --git a/code/controller/CMSMain.php b/code/controller/CMSMain.php index 444fbe78..829c0de7 100755 --- a/code/controller/CMSMain.php +++ b/code/controller/CMSMain.php @@ -63,6 +63,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr Requirements::javascript(CMS_DIR . '/javascript/CMSMain.js'); Requirements::javascript(CMS_DIR . '/javascript/CMSMain.EditForm.js'); + Requirements::javascript(CMS_DIR . '/javascript/CMSMain.AddForm.js'); Requirements::add_i18n_javascript(CMS_DIR . '/javascript/lang'); Requirements::css(CMS_DIR . '/css/CMSMain.css'); @@ -281,17 +282,17 @@ JS; $addAction = $instance->i18n_singular_name(); - // if we're in translation mode, the link between the translated pagetype - // title and the actual classname might not be obvious, so we add it in parantheses - // Example: class "RedirectorPage" has the title "Weiterleitung" in German, - // so it shows up as "Weiterleitung (RedirectorPage)" - if(i18n::get_locale() != 'en_US') { - $addAction .= " ({$class})"; - } - + // Get description + $description = _t($class . 'DESCRIPTION'); + if(!$description) $description = $instance->uninherited('description'); + if($class == 'Page' && !$description) $description = singleton('SiteTree')->uninherited('description'); + $result->push(new ArrayData(array( 'ClassName' => $class, 'AddAction' => $addAction, + 'Description' => $description, + // TODO Sprite support + 'IconURL' => $instance->stat('icon') ))); } @@ -1250,24 +1251,38 @@ JS; } } + /** + * @return Form + */ function AddForm() { + $record = $this->currentPage(); + $pageTypes = array(); - - foreach( $this->PageTypes() as $arrayData ) { - $pageTypes[$arrayData->getField('ClassName')] = $arrayData->getField('AddAction'); + foreach($this->PageTypes() as $type) { + $html = sprintf('%s%s', + $type->getField('ClassName'), + $type->getField('AddAction'), + $type->getField('Description') + ); + $pageTypes[$type->getField('ClassName')] = $html; } $fields = new FieldSet( - new HiddenField("ParentID"), - new DropdownField("PageType", "", $pageTypes, 'Page') + // new HiddenField("ParentID", false, ($this->parentRecord) ? $this->parentRecord->ID : null), + $parentField = new TreeDropdownField("ParentID", _t('CMSMain.AddFormParentLabel', 'Parent page'), 'SiteTree'), + new OptionsetField("PageType", "", $pageTypes, 'Page') ); + $parentField->setValue(($record) ? $record->ID : null); + + $actions = new FieldSet( + // $resetAction = new ResetFormAction('doCancel', _t('CMSMain.Cancel', 'Cancel')), + $createAction = new FormAction("doAdd", _t('CMSMain.Create',"Create")) + ); + // $resetAction->addExtraClass('ss-ui-action-destructive'); + $createAction->addExtraClass('ss-ui-action-constructive'); $this->extend('updatePageOptions', $fields); - $actions = new FieldSet( - new FormAction("doAdd", _t('CMSMain.GO',"Go")) - ); - $form = new Form($this, "AddForm", $fields, $actions); return $form; diff --git a/javascript/CMSMain.AddForm.js b/javascript/CMSMain.AddForm.js new file mode 100644 index 00000000..1e636f30 --- /dev/null +++ b/javascript/CMSMain.AddForm.js @@ -0,0 +1,34 @@ +(function($) { + $.entwine('ss', function($){ + $('.cms-page-add-form-dialog').entwine({ + onmatch: function() { + this.dialog({ + autoOpen: false, + bgiframe: true, + modal: true, + height: 400, + width: 600, + ghost: true + }); + this._super(); + } + }); + + $('.cms-page-add-form-dialog input[name=PageType]').entwine({ + onmatch: function() { + if(this.is(':checked')) this.trigger('click'); + this._super(); + }, + onclick: function() { + this.parents('li:first').addClass('selected').siblings().removeClass('selected'); + } + }); + + $(".cms-page-add-button").entwine({ + onclick: function(e) { + $('.cms-page-add-form-dialog').dialog('open'); + e.preventDefault(); + } + }); + }); +}(jQuery)); \ No newline at end of file diff --git a/templates/Includes/CMSPagesController_Content.ss b/templates/Includes/CMSPagesController_Content.ss index 57cd9d30..ade81db3 100644 --- a/templates/Includes/CMSPagesController_Content.ss +++ b/templates/Includes/CMSPagesController_Content.ss @@ -30,27 +30,21 @@
-
- <% _t("TreeTools.DisplayLabel","Display:") %> - <% if CanOrganiseSitetree %> -
- - -
- <% end_if %> -
- - -
-
- -
- $BatchActionsForm +
+ <% include CMSPagesController_ContentToolbar %>
$SiteTreeAsUL
+ +
+ <% include CMSPagesController_ContentToolbar %> +
+ +
+ $AddForm +
diff --git a/templates/Includes/CMSPagesController_ContentToolbar.ss b/templates/Includes/CMSPagesController_ContentToolbar.ss new file mode 100644 index 00000000..4984f3d4 --- /dev/null +++ b/templates/Includes/CMSPagesController_ContentToolbar.ss @@ -0,0 +1,21 @@ +
+ <% _t("TreeTools.DisplayLabel","Display:") %> + <% if CanOrganiseSitetree %> +
+ + +
+ <% end_if %> +
+ + +
+
+ +
+ <% _t('CMSMain.AddNewButton', 'Add new') %> +
+ +
+ $BatchActionsForm +
\ No newline at end of file diff --git a/tests/controller/CMSMainTest.php b/tests/controller/CMSMainTest.php index 891371d3..d9f0ecb4 100644 --- a/tests/controller/CMSMainTest.php +++ b/tests/controller/CMSMainTest.php @@ -197,22 +197,22 @@ class CMSMainTest extends FunctionalTest { // with insufficient permissions $cmsUser->logIn(); - $this->get('admin'); + $this->get('admin/pages'); $response = $this->submitForm( 'Form_AddForm', null, - array('ParentID' => '0', 'PageType' => 'Page', 'Locale' => 'en_US') + array('ParentID' => '0', 'ClassName' => 'Page', 'Locale' => 'en_US') ); // should redirect, which is a permission error $this->assertEquals(403, $response->getStatusCode(), 'Add TopLevel page must fail for normal user'); // with correct permissions $rootEditUser->logIn(); - $this->get('admin'); + $this->get('admin/pages/'); $response = $this->submitForm( 'Form_AddForm', null, - array('ParentID' => '0', 'PageType' => 'Page', 'Locale' => 'en_US') + array('ParentID' => '0', 'ClassName' => 'Page', 'Locale' => 'en_US') ); $this->assertEquals(302, $response->getStatusCode(), 'Must be a redirect on success'); $location=$response->getHeader('Location');