MINOR Using <button> tags for CMS UI, and new 'data-icon' HTML5 attribute to denote icons

This commit is contained in:
Ingo Schommer 2012-02-16 22:59:47 +01:00
parent 88952c0ac7
commit f620f9b46c
8 changed files with 132 additions and 110 deletions

View File

@ -213,11 +213,12 @@ JS
new FieldList(
),
new FieldList(
$btn = new FormAction('doSync', _t('FILESYSTEMSYNC','Look for new files'))
FormAction::create('doSync', _t('FILESYSTEMSYNC','Look for new files'))
->describe(_t('AssetAdmin_left.ss.FILESYSTEMSYNC_DESC', 'SilverStripe maintains its own database of the files &amp; images stored in your assets/ folder. Click this button to update that database, if files are added to the assets/ folder from outside SilverStripe, for example, if you have uploaded files via FTP.'))
->setUseButtonTag(true)
)
);
$form->setFormMethod('GET');
$btn->describe(_t('AssetAdmin_left.ss.FILESYSTEMSYNC_DESC', 'SilverStripe maintains its own database of the files &amp; images stored in your assets/ folder. Click this button to update that database, if files are added to the assets/ folder from outside SilverStripe, for example, if you have uploaded files via FTP.'));
return $form;
}

View File

@ -205,10 +205,13 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$dateTo->setConfig('showcalendar', true);
$actions = new FieldList(
$resetAction = new ResetFormAction('clear', _t('CMSMain_left.ss.CLEAR', 'Clear')),
$searchAction = new FormAction('doSearch', _t('CMSMain_left.ss.SEARCH', 'Search'))
Object::create('ResetFormAction', 'clear', _t('CMSMain_left.ss.CLEAR', 'Clear'))
->addExtraClass('ss-ui-action-minor'),
FormAction::create('doSearch', _t('CMSMain_left.ss.SEARCH', 'Search'))
);
$resetAction->addExtraClass('ss-ui-action-minor');
// Use <button> to allow full jQuery UI styling
foreach($actions->dataFields() as $action) $action->setUseButtonTag(true);
$form = new Form($this, 'SearchForm', $fields, $actions);
$form->setFormMethod('GET');
@ -493,6 +496,10 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
} else {
$actions = $record->getCMSActions();
}
// Use <button> to allow full jQuery UI styling
$actionsFlattened = $actions->dataFields();
if($actionsFlattened) foreach($actionsFlattened as $action) $action->setUseButtonTag(true);
if($record->hasMethod('getCMSValidator')) {
$validator = $record->getCMSValidator();
@ -534,7 +541,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$siteConfig = SiteConfig::current_site_config();
$fields = $siteConfig->getCMSFields();
$form = new Form($this, 'RootForm', $fields, $siteConfig->getCMSActions());
$actions = $siteConfig->getCMSActions();
$form = new Form($this, 'RootForm', $fields, $actions);
$form->addExtraClass('root-form');
$form->addExtraClass('cms-edit-form');
// TODO Can't merge $FormAttributes in template at the moment
@ -544,6 +552,9 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$form->loadDataFrom($siteConfig);
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
// Use <button> to allow full jQuery UI styling
foreach($actions->dataFields() as $action) $action->setUseButtonTag(true);
$this->extend('updateEditForm', $form);
return $form;
@ -899,7 +910,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
new HiddenField('Locale', false, $this->Locale)
),
new FieldList(
new FormAction('doShowSideReport', _t('CMSMain_left.ss.GO','Go'))
FormAction::create('doShowSideReport', _t('CMSMain_left.ss.GO','Go'))->setUseButtonTag(true)
)
);
$form->unsetValidator();
@ -1110,10 +1121,10 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$actions = new FieldList(
// $resetAction = new ResetFormAction('doCancel', _t('CMSMain.Cancel', 'Cancel')),
$createAction = new FormAction("doAdd", _t('CMSMain.Create',"Create"))
FormAction::create("doAdd", _t('CMSMain.Create',"Create"))
->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')
->setUseButtonTag(true)
);
// $resetAction->addExtraClass('ss-ui-action-destructive');
$createAction->addExtraClass('ss-ui-action-constructive');
$this->extend('updatePageOptions', $fields);

View File

@ -83,7 +83,7 @@ class CMSPageHistoryController extends CMSMain {
$form = parent::getEditForm($record, ($record) ? $record->getCMSFields() : null);
$form->setActions(new FieldList(
$revert = new FormAction('doRollback', _t('CMSPageHistoryController.REVERTTOTHISVERSION', 'Revert to this version'))
$revert = FormAction::create('doRollback', _t('CMSPageHistoryController.REVERTTOTHISVERSION', 'Revert to this version'))->setUseButtonTag(true)
));
$fields = $form->Fields();
@ -190,31 +190,38 @@ class CMSPageHistoryController extends CMSMain {
))->renderWith('CMSPageHistoryController_versions');
}
$fields = new FieldList(
new CheckboxField(
'ShowUnpublished',
_t('CMSPageHistoryController.SHOWUNPUBLISHED','Show unpublished versions'),
$showUnpublishedChecked
),
new CheckboxField(
'CompareMode',
_t('CMSPageHistoryController.COMPAREMODE', 'Compare mode (select two)'),
$compareModeChecked
),
new LiteralField('VersionsHtml', $versionsHtml),
$hiddenID = new HiddenField('ID', false, "")
);
$actions = new FieldList(
new FormAction(
'doCompare', _t('CMSPageHistoryController.COMPAREVERSIONS','Compare Versions')
),
new FormAction(
'doShowVersion', _t('CMSPageHistoryController.SHOWVERSION','Show Version')
)
);
// Use <button> to allow full jQuery UI styling
foreach($actions->dataFields() as $action) $action->setUseButtonTag(true);
$form = new Form(
$this,
'VersionsForm',
new FieldList(
new CheckboxField(
'ShowUnpublished',
_t('CMSPageHistoryController.SHOWUNPUBLISHED','Show unpublished versions'),
$showUnpublishedChecked
),
new CheckboxField(
'CompareMode',
_t('CMSPageHistoryController.COMPAREMODE', 'Compare mode (select two)'),
$compareModeChecked
),
new LiteralField('VersionsHtml', $versionsHtml),
$hiddenID = new HiddenField('ID', false, "")
),
new FieldList(
new FormAction(
'doCompare', _t('CMSPageHistoryController.COMPAREVERSIONS','Compare Versions')
),
new FormAction(
'doShowVersion', _t('CMSPageHistoryController.SHOWVERSION','Show Version')
)
)
$fields,
$actions
);
$form->loadDataFrom($this->request->requestVars());

View File

@ -129,13 +129,13 @@ class SiteConfig extends DataObject implements PermissionProvider {
function getCMSActions() {
if (Permission::check('ADMIN') || Permission::check('EDIT_SITECONFIG')) {
$actions = new FieldList(
$saveAction = new FormAction('save_siteconfig', _t('CMSMain.SAVE','Save'))
FormAction::create('save_siteconfig', _t('CMSMain.SAVE','Save'))
->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')
);
} else {
$actions = new FieldList();
}
$saveAction->addExtraClass('ss-ui-action-constructive');
$this->extend('updateCMSActions', $actions);
return $actions;

View File

@ -2041,13 +2041,14 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* @return FieldList The available actions for this page.
*/
function getCMSActions() {
$actions = new FieldList();
$minorActions = Object::create('CompositeField')->setTag('fieldset')->addExtraClass('ss-ui-buttonset');
$actions = new FieldList($minorActions);
// "readonly"/viewing version that isn't the current version of the record
$stageOrLiveRecord = Versioned::get_one_by_stage($this->class, Versioned::current_stage(), sprintf('"SiteTree"."ID" = %d', $this->ID));
if($stageOrLiveRecord && $stageOrLiveRecord->Version != $this->Version) {
$actions->push(new FormAction('email', _t('CMSMain.EMAIL', 'Email')));
$actions->push(new FormAction('rollback', _t('CMSMain.ROLLBACK', 'Roll back to this version')));
$minorActions->push(FormAction::create('email', _t('CMSMain.EMAIL', 'Email')));
$minorActions->push(FormAction::create('rollback', _t('CMSMain.ROLLBACK', 'Roll back to this version')));
// getCMSActions() can be extended with updateCMSActions() on a extension
$this->extend('updateCMSActions', $actions);
@ -2057,22 +2058,21 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if($this->isPublished() && $this->canPublish() && !$this->IsDeletedFromStage && $this->canDeleteFromLive()) {
// "unpublish"
$unpublish = FormAction::create('unpublish', _t('SiteTree.BUTTONUNPUBLISH', 'Unpublish'), 'delete');
$unpublish->describe(_t('SiteTree.BUTTONUNPUBLISHDESC', 'Remove this page from the published site'));
$unpublish->addExtraClass('unpublish');
$unpublish->addExtraClass('ss-ui-action-destructive');
$unpublish->setAttribute('buttonset', 'minoractions');
$actions->push($unpublish);
$minorActions->push(
FormAction::create('unpublish', _t('SiteTree.BUTTONUNPUBLISH', 'Unpublish'), 'delete')
->describe(_t('SiteTree.BUTTONUNPUBLISHDESC', 'Remove this page from the published site'))
->addExtraClass('ss-ui-action-destructive')->setAttribute('data-icon', 'unpublish')
);
}
if($this->stagesDiffer('Stage', 'Live') && !$this->IsDeletedFromStage) {
if($this->isPublished() && $this->canEdit()) {
// "rollback"
$rollback = FormAction::create('rollback', _t('SiteTree.BUTTONCANCELDRAFT', 'Cancel draft changes'), 'delete');
$rollback->describe(_t('SiteTree.BUTTONCANCELDRAFTDESC', 'Delete your draft and revert to the currently published page'));
$rollback->addExtraClass('delete');
$rollback->setAttribute('buttonset', 'minoractions');
$actions->push($rollback);
$minorActions->push(
FormAction::create('rollback', _t('SiteTree.BUTTONCANCELDRAFT', 'Cancel draft changes'), 'delete')
->describe(_t('SiteTree.BUTTONCANCELDRAFTDESC', 'Delete your draft and revert to the currently published page'))
->addExtraClass('delete')->setAttribute('data-icon', 'delete')
);
}
}
@ -2080,37 +2080,41 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if($this->IsDeletedFromStage) {
if($this->ExistsOnLive) {
// "restore"
$actions->push(new FormAction('revert',_t('CMSMain.RESTORE','Restore')));
$minorActions->push(FormAction::create('revert',_t('CMSMain.RESTORE','Restore')));
if($this->canDelete() && $this->canDeleteFromLive()) {
// "delete from live"
$actions->push($deleteFromLiveAction = new FormAction('deletefromlive',_t('CMSMain.DELETEFP','Delete')));
$deleteFromLiveAction->addExtraClass('ss-ui-action-destructive');
$deleteFromLiveAction->setAttribute('buttonset', 'minoractions');
$minorActions->push(
FormAction::create('deletefromlive',_t('CMSMain.DELETEFP','Delete'))->addExtraClass('ss-ui-action-destructive')
);
}
} else {
// "restore"
$actions->push(new FormAction('restore',_t('CMSMain.RESTORE','Restore')));
$minorActions->push(
FormAction::create('restore',_t('CMSMain.RESTORE','Restore'))->setAttribute('data-icon', 'decline')
);
}
} else {
if($this->canDelete()) {
// "delete"
$actions->push($deleteAction = new FormAction('delete',_t('CMSMain.DELETE','Delete draft')));
$deleteAction->addExtraClass('delete');
$deleteAction->addExtraClass('ss-ui-action-destructive');
$deleteAction->setAttribute('buttonset', 'minoractions');
$minorActions->push(
FormAction::create('delete',_t('CMSMain.DELETE','Delete draft'))->addExtraClass('delete ss-ui-action-destructive')
->setAttribute('data-icon', 'decline')
);
}
// "save"
$actions->push($saveDraftAction = new FormAction('save',_t('CMSMain.SAVEDRAFT','Save Draft')));
$saveDraftAction->addExtraClass('save-draft');
$saveDraftAction->setAttribute('buttonset', 'minoractions');
$minorActions->push(
FormAction::create('save',_t('CMSMain.SAVEDRAFT','Save Draft'))->setAttribute('data-icon', 'addpage')
);
}
}
if($this->canPublish() && !$this->IsDeletedFromStage) {
// "publish"
$actions->push($publishAction = new FormAction('publish', _t('SiteTree.BUTTONSAVEPUBLISH', 'Save & Publish')));
$publishAction->addExtraClass('ss-ui-action-constructive');
$actions->push(
FormAction::create('publish', _t('SiteTree.BUTTONSAVEPUBLISH', 'Save & Publish'))
->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')
);
}
// getCMSActions() can be extended with updateCMSActions() on a extension

View File

@ -13,7 +13,7 @@
</div>
<div class="cms-actions-row">
<a class="ss-ui-button ss-ui-action-constructive icon-add" href="#cms-page-add-form"><% _t('CMSMain.AddNewButton', 'Add new') %></a>
<a class="ss-ui-button ss-ui-action-constructive" data-icon="add" href="#cms-page-add-form"><% _t('CMSMain.AddNewButton', 'Add new') %></a>
</div>
<div class="cms-content-batchactions">

View File

@ -155,7 +155,7 @@ class CMSMainTest extends FunctionalTest {
$this->assertTrue($livePage->canDelete());
// Check that the 'restore' button exists as a simple way of checking that the correct page is returned.
$this->assertRegExp('/<input[^>]+type="submit"[^>]+name="action_(restore|revert)"/i', $response->getBody());
$this->assertRegExp('/<button[^>]+name="action_(restore|revert)"/i', $response->getBody());
}
/**

View File

@ -39,15 +39,15 @@ class SiteTreeActionsTest extends FunctionalTest {
$page->write();
$page->doPublish();
$actionsArr = $page->getCMSActions()->column('Name');
$actions = $page->getCMSActions();
$this->assertNotContains('action_save',$actionsArr);
$this->assertNotContains('action_publish',$actionsArr);
$this->assertNotContains('action_unpublish',$actionsArr);
$this->assertNotContains('action_delete',$actionsArr);
$this->assertNotContains('action_deletefromlive',$actionsArr);
$this->assertNotContains('action_rollback',$actionsArr);
$this->assertNotContains('action_revert',$actionsArr);
$this->assertNull($actions->dataFieldByName('action_save'));
$this->assertNull($actions->dataFieldByName('action_publish'));
$this->assertNull($actions->dataFieldByName('action_unpublish'));
$this->assertNull($actions->dataFieldByName('action_delete'));
$this->assertNull($actions->dataFieldByName('action_deletefromlive'));
$this->assertNull($actions->dataFieldByName('action_rollback'));
$this->assertNull($actions->dataFieldByName('action_revert'));
}
function testActionsNoDeletePublishedRecord() {
@ -70,13 +70,13 @@ class SiteTreeActionsTest extends FunctionalTest {
$editor = $this->objFromFixture('Member', 'cmsnodeleteeditor');
$this->session()->inst_set('loggedInAs', $editor->ID);
$actionsArr = $page->getCMSActions()->column('Name');
$this->assertNotContains('action_deletefromlive',$actionsArr);
$actions = $page->getCMSActions();
$this->assertNull($actions->dataFieldByName('action_deletefromlive'));
// Check that someone with the right permission can delete the page
$this->objFromFixture('Member', 'cmseditor')->logIn();
$actionsArr = $page->getCMSActions()->column('Name');
$this->assertContains('action_deletefromlive',$actionsArr);
$actions = $page->getCMSActions();
$this->assertNotNull($actions->dataFieldByName('action_deletefromlive'));
}
function testActionsPublishedRecord() {
@ -90,15 +90,15 @@ class SiteTreeActionsTest extends FunctionalTest {
$page->write();
$page->doPublish();
$actionsArr = $page->getCMSActions()->column('Name');
$actions = $page->getCMSActions();
$this->assertContains('action_save',$actionsArr);
$this->assertContains('action_publish',$actionsArr);
$this->assertContains('action_unpublish',$actionsArr);
$this->assertContains('action_delete',$actionsArr);
$this->assertNotContains('action_deletefromlive',$actionsArr);
$this->assertNotContains('action_rollback',$actionsArr);
$this->assertNotContains('action_revert',$actionsArr);
$this->assertNotNull($actions->dataFieldByName('action_save'));
$this->assertNotNull($actions->dataFieldByName('action_publish'));
$this->assertNotNull($actions->dataFieldByName('action_unpublish'));
$this->assertNotNull($actions->dataFieldByName('action_delete'));
$this->assertNull($actions->dataFieldByName('action_deletefromlive'));
$this->assertNull($actions->dataFieldByName('action_rollback'));
$this->assertNull($actions->dataFieldByName('action_revert'));
}
function testActionsDeletedFromStageRecord() {
@ -118,15 +118,15 @@ class SiteTreeActionsTest extends FunctionalTest {
$page = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $pageID");
$this->assertType('SiteTree', $page);
$actionsArr = $page->getCMSActions()->column('Name');
$actions = $page->getCMSActions();
$this->assertNotContains('action_save',$actionsArr);
$this->assertNotContains('action_publish',$actionsArr);
$this->assertNotContains('action_unpublish',$actionsArr);
$this->assertNotContains('action_delete',$actionsArr);
$this->assertContains('action_deletefromlive',$actionsArr);
$this->assertNotContains('action_rollback',$actionsArr);
$this->assertContains('action_revert',$actionsArr);
$this->assertNull($actions->dataFieldByName('action_save'));
$this->assertNull($actions->dataFieldByName('action_publish'));
$this->assertNull($actions->dataFieldByName('action_unpublish'));
$this->assertNull($actions->dataFieldByName('action_delete'));
$this->assertNotNull($actions->dataFieldByName('action_deletefromlive'));
$this->assertNull($actions->dataFieldByName('action_rollback'));
$this->assertNotNull($actions->dataFieldByName('action_revert'));
}
function testActionsChangedOnStageRecord() {
@ -143,15 +143,14 @@ class SiteTreeActionsTest extends FunctionalTest {
$page->write();
$page->flushCache();
$actionsArr = $page->getCMSActions()->column('Name');
$this->assertContains('action_save',$actionsArr);
$this->assertContains('action_publish',$actionsArr);
$this->assertContains('action_unpublish',$actionsArr);
$this->assertContains('action_delete',$actionsArr);
$this->assertNotContains('action_deletefromlive',$actionsArr);
$this->assertContains('action_rollback',$actionsArr);
$this->assertNotContains('action_revert',$actionsArr);
$actions = $page->getCMSActions();
$this->assertNotNull($actions->dataFieldByName('action_save'));
$this->assertNotNull($actions->dataFieldByName('action_publish'));
$this->assertNotNull($actions->dataFieldByName('action_unpublish'));
$this->assertNotNull($actions->dataFieldByName('action_delete'));
$this->assertNull($actions->dataFieldByName('action_deletefromlive'));
$this->assertNotNull($actions->dataFieldByName('action_rollback'));
$this->assertNull($actions->dataFieldByName('action_revert'));
}
function testActionsViewingOldVersion() {
@ -164,13 +163,13 @@ class SiteTreeActionsTest extends FunctionalTest {
// Looking at the old version, the ability to rollback to that version is available
$version = DB::query('SELECT "Version" FROM "SiteTree_versions" WHERE "Content" = \'test page first version\'')->value();
$old = Versioned::get_version('Page', $p->ID, $version);
$actions = $old->getCMSActions()->column('Name');
$this->assertNotContains('action_save', $actions);
$this->assertNotContains('action_publish', $actions);
$this->assertNotContains('action_unpublish', $actions);
$this->assertNotContains('action_delete', $actions);
$this->assertContains('action_email', $actions);
$this->assertContains('action_rollback', $actions);
$actions = $old->getCMSActions();
$this->assertNull($actions->dataFieldByName('action_save'));
$this->assertNull($actions->dataFieldByName('action_publish'));
$this->assertNull($actions->dataFieldByName('action_unpublish'));
$this->assertNull($actions->dataFieldByName('action_delete'));
$this->assertNotNull($actions->dataFieldByName('action_email'));
$this->assertNotNull($actions->dataFieldByName('action_rollback'));
}
}