ENHANCEMENT: added notice template for outputting notices to cmsmain interfaces.

This commit is contained in:
Will Rossiter 2011-08-26 14:03:21 +12:00 committed by Ingo Schommer
parent d90ea0d236
commit f81531115f
5 changed files with 97 additions and 27 deletions

View File

@ -358,12 +358,10 @@ JS;
if($id instanceof $treeClass) { if($id instanceof $treeClass) {
return $id; return $id;
} else if($id && is_numeric($id)) { } else if($id && is_numeric($id)) {
$versionID = null;
if(isset($_REQUEST['Version'])) $versionID = (int) $_REQUEST['Version']; if(isset($_REQUEST['Version'])) $versionID = (int) $_REQUEST['Version'];
if($versionID && is_int($version)) { if($versionID) {
$record = Versioned::get_version($treeClass, $id, $version); $record = Versioned::get_version($treeClass, $id, $versionID);
} else { } else {
$record = DataObject::get_one($treeClass, "\"$treeClass\".\"ID\" = $id"); $record = DataObject::get_one($treeClass, "\"$treeClass\".\"ID\" = $id");
} }

View File

@ -22,18 +22,18 @@ class CMSPageHistoryController extends CMSMain {
); );
/** /**
* @var array * @return array
*/ */
function version() { function version() {
return array( return array(
'EditForm' => $this->ShowVersionForm( 'EditForm' => $this->ShowVersionForm(
$this->request->param('ID') $this->request->param('VersionID')
) )
); );
} }
/** /**
* @var array * @return array
*/ */
function compare() { function compare() {
return array( return array(
@ -43,9 +43,9 @@ class CMSPageHistoryController extends CMSMain {
) )
); );
} }
/** /**
* Returns the read only version of the edit form. Detaches {@link FormAction} * Returns the read only version of the edit form. Detaches all {@link FormAction}
* instances attached since only action relates to revert. * instances attached since only action relates to revert.
* *
* Permission checking is done at the {@link CMSMain::getEditForm()} level. * Permission checking is done at the {@link CMSMain::getEditForm()} level.
@ -53,44 +53,93 @@ class CMSPageHistoryController extends CMSMain {
* @param int $id ID of the record to show * @param int $id ID of the record to show
* @param array $fields optional * @param array $fields optional
* @param int $versionID * @param int $versionID
* @param int $compare Compare mode
*
* @return Form
*/ */
function getEditForm($id = null, $fields = null, $versionID = null) { function getEditForm($id = null, $fields = null, $versionID = null, $compareID = null) {
if(!$id) $id = $this->currentPageID();
$record = $this->getRecord($id, $versionID); $record = $this->getRecord($id, $versionID);
$versionID = ($record) ? $record->Version : $versionID;
$form = parent::getEditForm($record, ($record) ? $record->getCMSFields() : null); $form = parent::getEditForm($record, ($record) ? $record->getCMSFields() : null);
$form->setActions(new FieldSet(
$revert = new FormAction('doRevert', _t('CMSPageHistoryController.REVERTTOTHISVERSION', 'Revert to this version'))
));
$fields = $form->Fields(); $fields = $form->Fields();
$fields->removeByName("Status"); $fields->removeByName("Status");
$fields->push(new HiddenField("ID")); $fields->push(new HiddenField("ID"));
$fields->push(new HiddenField("Version")); $fields->push(new HiddenField("Version"));
$fields = $fields->makeReadonly(); $fields = $fields->makeReadonly();
foreach($fields->dataFields() as $field) { foreach($fields->dataFields() as $field) {
$field->dontEscape = true; $field->dontEscape = true;
$field->reserveNL = true;
} }
$form->setFields($fields->makeReadonly()); $link = Controller::join_links(
$this->Link('version'),
$id
);
// attach additional information $view = _t('CMSPageHistoryController.VIEW',"view");
if($compareID) {
$message = sprintf(
_t('CMSPageHistoryController.COMPARINGVERSION',"Comparing versions %s and %s."),
sprintf('%s (<a href="%s">%s</a>)', $versionID, Controller::join_links($link, $versionID), $view),
sprintf('%s (<a href="%s">%s</a>)', $compareID, Controller::join_links($link, $compareID), $view)
);
$revert->setReadonly(true);
}
else {
$message = sprintf(
_t('CMSPageHistoryController.VIEWINGVERSION',"Currently viewing version %s."),
sprintf('%s (<a href="%s">%s</a>)',
$versionID,
Controller::join_links($link, $versionID),
$view
)
);
}
$fields->addFieldToTab('Root.Main',
new LiteralField('CurrentlyViewingMessage', $this->customise(array(
'Content' => $message,
'Classes' => 'notice'
))->renderWith(array('CMSMain_notice'))),
"Title"
);
$form->setFields($fields->makeReadonly());
$form->loadDataFrom(array( $form->loadDataFrom(array(
"ID" => $id, "ID" => $id,
"Version" => $versionID, "Version" => $versionID,
)); ));
$form->setActions(new FieldSet( if(($record && $record->isLatestVersion())) {
$revert = new FormAction('doRevert', _t('CMSPageHistoryController.REVERTTOTHISVERSION', 'Revert to this version')) $revert->setReadonly(true);
)); }
$form->removeExtraClass('cms-content'); $form->removeExtraClass('cms-content');
return $form; return $form;
} }
/** /**
* Compare version selection form. Displays a list of previous versions * Version select form. Main interface between selecting versions to view
* and options for selecting filters on the version * and comparing multiple versions.
* *
* Because we can reload the page directly to a compare view (history/compare/1/2/3)
* this form has to adapt to those parameters as well.
*
* @return Form * @return Form
*/ */
function VersionsForm() { function VersionsForm() {
@ -98,16 +147,34 @@ class CMSPageHistoryController extends CMSMain {
$page = $this->getRecord($id); $page = $this->getRecord($id);
$versionsHtml = ''; $versionsHtml = '';
$action = $this->request->param('Action');
$versionID = $this->request->param('VersionID');
$otherVersionID = $this->request->param('OtherVersionID');
$showUnpublishedChecked = 0;
$compareModeChecked = ($action == "compare");
if($page) { if($page) {
$versions = $page->allVersions(); $versions = $page->allVersions();
if($versions) { if($versions) {
foreach($versions as $k => $version) { foreach($versions as $k => $version) {
$active = false;
if($version->Version == $versionID || $version->Version == $otherVersionID) {
$active = true;
if(!$version->WasPublished) {
$showUnpublishedChecked = 1;
}
}
$version->CMSLink = sprintf('%s/%s/%s', $version->CMSLink = sprintf('%s/%s/%s',
$this->Link('version'), $this->Link('version'),
$version->ID, $version->ID,
$version->Version $version->Version
); );
$version->Active = ($active);
} }
} }
@ -117,18 +184,20 @@ class CMSPageHistoryController extends CMSMain {
'Versions' => $versions 'Versions' => $versions
))->renderWith('CMSPageHistoryController_versions'); ))->renderWith('CMSPageHistoryController_versions');
} }
$form = new Form( $form = new Form(
$this, $this,
'VersionsForm', 'VersionsForm',
new FieldSet( new FieldSet(
new CheckboxField( new CheckboxField(
'ShowUnpublished', 'ShowUnpublished',
_t('CMSPageHistoryController.SHOWUNPUBLISHED','Show unpublished versions') _t('CMSPageHistoryController.SHOWUNPUBLISHED','Show unpublished versions'),
$showUnpublishedChecked
), ),
new CheckboxField( new CheckboxField(
'CompareMode', 'CompareMode',
_t('CMSPageHistoryController.COMPAREMODE', 'Compare mode') _t('CMSPageHistoryController.COMPAREMODE', 'Compare mode'),
$compareModeChecked
), ),
new LiteralField('VersionsHtml', $versionsHtml), new LiteralField('VersionsHtml', $versionsHtml),
new HiddenField('ID', false, $id) new HiddenField('ID', false, $id)
@ -236,7 +305,7 @@ class CMSPageHistoryController extends CMSMain {
*/ */
function ShowVersionForm($versionID = null) { function ShowVersionForm($versionID = null) {
if(!$versionID) return null; if(!$versionID) return null;
$id = $this->currentPageID(); $id = $this->currentPageID();
$form = $this->getEditForm($id, null, $versionID); $form = $this->getEditForm($id, null, $versionID);
@ -278,7 +347,7 @@ class CMSPageHistoryController extends CMSMain {
} }
if($record) { if($record) {
$form = $this->getEditForm($id, null, null); $form = $this->getEditForm($id, null, null, true);
$form->setActions(new FieldSet()); $form->setActions(new FieldSet());
$form->loadDataFrom($record); $form->loadDataFrom($record);

View File

@ -70,7 +70,7 @@
url = 'admin/page/history/version/'+ [id,to].join('/') + "/"; url = 'admin/page/history/version/'+ [id,to].join('/') + "/";
} }
// we can access this comparsion directly in the url. // we can access this comparsion directly in the url
window.History.pushState({selector: '.cms-content-fields form:first'}, '', url); window.History.pushState({selector: '.cms-content-fields form:first'}, '', url);
var data = this.serializeArray(); var data = this.serializeArray();

View File

@ -0,0 +1,3 @@
<div class="message $Classes">
<p>$Content</p>
</div>

View File

@ -10,8 +10,8 @@
<tbody> <tbody>
<% control Versions %> <% control Versions %>
<tr id="page-$RecordID-version-$Version" class="$EvenOdd $PublishedClass<% if not WasPublished %> ui-helper-hidden<% end_if %>" data-published="<% if WasPublished %>true<% else %>false<% end_if %>"data-link="$CMSLink"> <tr id="page-$RecordID-version-$Version" class="$EvenOdd $PublishedClass<% if not WasPublished %><% if not Active %> ui-helper-hidden<% end_if %><% end_if %><% if Active %> active<% end_if %>" data-published="<% if WasPublished %>true<% else %>false<% end_if %>"data-link="$CMSLink">
<td class="ui-helper-hidden"><input type="checkbox" name="Versions[]" id="cms-_$Version" value="$Version" /></td> <td class="ui-helper-hidden"><input type="checkbox" name="Versions[]" id="cms-_$Version" value="$Version"<% if Active %> checked="checked"<% end_if %> /></td>
<% control LastEdited %> <% control LastEdited %>
<td class="last-edited first-column" title="$Ago - $Nice">$Nice</td> <td class="last-edited first-column" title="$Ago - $Nice">$Nice</td>
<% end_control %> <% end_control %>