Merge branch 'master' into new-orm

This commit is contained in:
Sam Minnee 2011-05-26 17:09:47 +12:00
commit 15d01a3472
12 changed files with 142 additions and 33 deletions

View File

@ -33,3 +33,5 @@ Object::add_extension('File', 'SiteTreeFileExtension');
// TODO Remove once we can configure CMSMenu through static, nested configuration files // TODO Remove once we can configure CMSMenu through static, nested configuration files
CMSMenu::remove_menu_item('CMSPageEditController'); CMSMenu::remove_menu_item('CMSPageEditController');
CMSMenu::remove_menu_item('CMSPageSettingsController'); CMSMenu::remove_menu_item('CMSPageSettingsController');
CMSMenu::remove_menu_item('CMSPageHistoryController');
CMSMenu::remove_menu_item('CMSPageReportsController');

View File

@ -139,7 +139,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
* Return the entire site tree as a nested set of ULs * Return the entire site tree as a nested set of ULs
*/ */
public function SiteTreeAsUL() { public function SiteTreeAsUL() {
$this->generateDataTreeHints();
$this->generateTreeStylingJS(); $this->generateTreeStylingJS();
// Pre-cache sitetree version numbers for querying efficiency // Pre-cache sitetree version numbers for querying efficiency
@ -172,8 +171,10 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$fields = new FieldSet( $fields = new FieldSet(
new TextField('Term', _t('CMSSearch.FILTERLABELTEXT', 'Content')), new TextField('Term', _t('CMSSearch.FILTERLABELTEXT', 'Content')),
$dateGroup = new FieldGroup(
$dateFrom = new DateField('LastEditedFrom', _t('CMSSearch.FilterDateFrom', 'from')), $dateFrom = new DateField('LastEditedFrom', _t('CMSSearch.FilterDateFrom', 'from')),
$dateTo = new DateField('LastEditedTo', _t('CMSSearch.FilterDateFrom', 'to')), $dateTo = new DateField('LastEditedTo', _t('CMSSearch.FilterDateFrom', 'to'))
),
new DropdownField( new DropdownField(
'FilterClass', 'FilterClass',
_t('CMSMain.SearchTreeFormPagesDropdown', 'Pages'), _t('CMSMain.SearchTreeFormPagesDropdown', 'Pages'),
@ -189,6 +190,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
) )
// new TextField('MetaTags', _t('CMSMain.SearchMetaTags', 'Meta tags')) // new TextField('MetaTags', _t('CMSMain.SearchMetaTags', 'Meta tags'))
); );
$dateGroup->subfieldParam = 'FieldHolder';
$dateFrom->setConfig('showcalendar', true); $dateFrom->setConfig('showcalendar', true);
$dateTo->setConfig('showcalendar', true); $dateTo->setConfig('showcalendar', true);
@ -210,27 +212,43 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
return $this->getsubtree($this->request); return $this->getsubtree($this->request);
} }
public function generateDataTreeHints() { /**
* Create serialized JSON string with site tree hints data to be injected into
* 'data-hints' attribute of root node of jsTree.
*
* @return String Serialized JSON
*/
public function SiteTreeHints() {
$classes = ClassInfo::subclassesFor( $this->stat('tree_class') ); $classes = ClassInfo::subclassesFor( $this->stat('tree_class') );
$def['Root'] = array(); $def['Root'] = array();
$def['Root']['disallowedChildren'] = array();
$def['Root']['disallowedParents'] = array();
foreach($classes as $class) { foreach($classes as $class) {
$obj = singleton($class); $obj = singleton($class);
if($obj instanceof HiddenClass) continue; if($obj instanceof HiddenClass) continue;
$allowedChildren = $obj->allowedChildren(); $allowedChildren = $obj->allowedChildren();
if($allowedChildren != "none") $def[$class]['allowedChildren'] = $allowedChildren; //SiteTree::allowedChildren() returns null rather than an empty array if SiteTree::allowed_chldren == 'none'
$def[$class]['defaultChild'] = $obj->defaultChild(); if ($allowedChildren == null) $allowedChildren = array();
$def[$class]['defaultParent'] = isset(SiteTree::get_by_link($obj->defaultParent())->ID) ? SiteTree::get_by_link($obj->defaultParent())->ID : null; $def[$class]['disallowedChildren'] = array_keys(array_diff($classes, $allowedChildren));
if($obj->stat('can_be_root')) { $defaultChild = $obj->defaultChild();
$def['Root']['allowedChildren'][] = $class; if ($defaultChild != 'Page' && $defaultChild != null) $def[$class]['defaultChild'] = $defaultChild;
}
$defaultParent = isset(SiteTree::get_by_link($obj->defaultParent())->ID) ? SiteTree::get_by_link($obj->defaultParent())->ID : null;
if ($defaultParent != 1 && $defaultParent != null) $def[$class]['defaultParent'] = $defaultParent;
if(is_array($def[$class]['disallowedChildren'])) foreach($def[$class]['disallowedChildren'] as $disallowedChild) {
$def[$disallowedChild]['disallowedParents'][] = $class;
} }
// Put data hints into a script tag at the top //Are any classes allowed to be parents of root?
Requirements::customScript("siteTreeHints = " . Convert::raw2json($def) . ";"); $def['Root']['disallowedParents'][] = $class;
}
return Convert::raw2xml(Convert::raw2json($def));
} }
public function generateTreeStylingJS() { public function generateTreeStylingJS() {
@ -1279,6 +1297,8 @@ JS;
$fields = new FieldSet( $fields = new FieldSet(
// new HiddenField("ParentID", false, ($this->parentRecord) ? $this->parentRecord->ID : null), // new HiddenField("ParentID", false, ($this->parentRecord) ? $this->parentRecord->ID : null),
// TODO Should be part of the form attribute, but not possible in current form API
$hintsField = new LiteralField('Hints', sprintf('<span class="hints" data-hints="%s"></span>', $this->SiteTreeHints())),
$parentField = new TreeDropdownField("ParentID", _t('CMSMain.AddFormParentLabel', 'Parent page'), 'SiteTree'), $parentField = new TreeDropdownField("ParentID", _t('CMSMain.AddFormParentLabel', 'Parent page'), 'SiteTree'),
new OptionsetField("PageType", "", $pageTypes, 'Page') new OptionsetField("PageType", "", $pageTypes, 'Page')
); );
@ -1294,6 +1314,7 @@ JS;
$this->extend('updatePageOptions', $fields); $this->extend('updatePageOptions', $fields);
$form = new Form($this, "AddForm", $fields, $actions); $form = new Form($this, "AddForm", $fields, $actions);
$form->addExtraClass('cms-add-form');
return $form; return $form;
} }

View File

@ -7,7 +7,15 @@ class CMSPageEditController extends CMSMain {
function getEditForm($id = null, $fields = null) { function getEditForm($id = null, $fields = null) {
$record = $this->getRecord($id ? $id : $this->currentPageID()); $record = $this->getRecord($id ? $id : $this->currentPageID());
return parent::getEditForm($record, ($record) ? $record->getCMSFields() : null); $form = parent::getEditForm($record, ($record) ? $record->getCMSFields() : null);
// TODO Replace with preview button
$form->Fields()->addFieldToTab(
'Root.Main',
new LiteralField('SwitchView', sprintf('<div class="cms-switch-view field"><label>Preview:</label><div class="middleColumn">%s</div></div>', $this->SwitchView()))
);
return $form;
} }
} }

View File

@ -0,0 +1,12 @@
<?php
class CMSPageHistoryController extends CMSMain {
static $url_segment = 'page/history';
static $url_rule = '/$Action/$ID/$OtherID';
static $url_priority = 42;
function getEditForm($id = null, $fields = null) {
return "Not implemented yet";
}
}

View File

@ -0,0 +1,12 @@
<?php
class CMSPageReportsController extends CMSMain {
static $url_segment = 'page/reports';
static $url_rule = '/$Action/$ID/$OtherID';
static $url_priority = 42;
function getEditForm($id = null, $fields = null) {
return "Not implemented yet";
}
}

View File

@ -7,10 +7,11 @@
abstract class SiteTreeDecorator extends SiteTreeExtension { abstract class SiteTreeDecorator extends SiteTreeExtension {
public function __construct() { public function __construct() {
user_error( // TODO Re-enable before we release 3.0 beta, for now it "breaks" too many modules
'SiteTreeDecorator is deprecated, please use SiteTreeExtension instead.', // user_error(
E_USER_NOTICE // 'SiteTreeDecorator is deprecated, please use SiteTreeExtension instead.',
); // E_USER_NOTICE
// );
parent::__construct(); parent::__construct();
} }

View File

@ -20,7 +20,57 @@
this._super(); this._super();
}, },
onclick: function() { onclick: function() {
this.parents('li:first').addClass('selected').siblings().removeClass('selected'); var el = this.parents('li:first');
el.setSelected(true);
el.siblings().setSelected(false);
}
});
$(".cms-add-form").entwine({
onmatch: function() {
var self = this;
this.find('#ParentID .TreeDropdownField').bind('change', function() {
self.updateTypeList();
});
},
/**
* Limit page type selection based on parent class.
* Similar implementation to LeftAndMain.Tree.js.
*/
updateTypeList: function() {
var hints = this.find('.hints').data('hints'),
metadata = this.find('#ParentID .TreeDropdownField').data('metadata'),
id = this.find('#ParentID .TreeDropdownField').getValue(),
newClassName = metadata[0].ClassName,
disallowedChildren = hints[newClassName ? newClassName : 'Root'].disallowedChildren || [],
defaultChildClass = hints[newClassName ? newClassName : 'Root'].defaultChild || null;
// Limit selection
this.find('#PageType li').each(function() {
var className = $(this).find('input').val(), isAllowed = ($.inArray(className, disallowedChildren) == -1);
$(this).setEnabled(isAllowed);
});
// Set default child selection, or fall back to first available option
if(defaultChildClass) {
var selectedEl = this.find('#PageType li input[value=' + defaultChildClass + ']').parents('li:first');
} else {
var selectedEl = this.find('#PageType li:not(.disabled):first');
}
selectedEl.setSelected(true);
selectedEl.siblings().setSelected(false);
}
});
$(".cms-add-form #PageType li").entwine({
setSelected: function(bool) {
this.toggleClass('selected', bool);
this.find('input').attr('checked', bool ? 'checked' : null);
},
setEnabled: function(bool) {
$(this).toggleClass('disabled', bool);
$(this).find('input').attr('disabled', bool ? '' : 'disabled');
} }
}); });

View File

@ -173,21 +173,22 @@
* Toggle display of group dropdown in "access" tab, * Toggle display of group dropdown in "access" tab,
* based on selection of radiobuttons. * based on selection of radiobuttons.
*/ */
$('.cms-edit-form #CanViewType, .cms-edit-form #CanEditType').entwine({ $('.cms-edit-form #CanViewType, .cms-edit-form #CanEditType, .cms-edit-form #CanCreateTopLevelType').entwine({
// Constructor: onmatch // Constructor: onmatch
onmatch: function() { onmatch: function() {
// TODO Decouple // TODO Decouple
var dropdown; var dropdown;
if(this.attr('id') == 'CanViewType') dropdown = $('#ViewerGroups'); if(this.attr('id') == 'CanViewType') dropdown = $('#ViewerGroups');
else if(this.attr('id') == 'CanEditType') dropdown = $('#EditorGroups'); else if(this.attr('id') == 'CanEditType') dropdown = $('#EditorGroups');
else if(this.attr('id') == 'CanCreateTopLevelType') dropdown = $('#CreateTopLevelGroups');
this.find('.optionset :input').bind('change', function(e) { this.find('.optionset :input').bind('change', function(e) {
dropdown.toggle(e.target.value == 'OnlyTheseUsers'); dropdown[e.target.value == 'OnlyTheseUsers' ? 'show' : 'hide']();
}); });
// initial state // initial state
var currentVal = this.find('input[name=' + this.attr('id') + ']:checked').val(); var currentVal = this.find('input[name=' + this.attr('id') + ']:checked').val();
dropdown.toggle(currentVal == 'OnlyTheseUsers'); dropdown[currentVal == 'OnlyTheseUsers' ? 'show' : 'hide']();
this._super(); this._super();
} }

View File

@ -35,10 +35,10 @@
$EditForm $EditForm
</div> </div>
<div id="cms-content-treeview"> <div id="cms-content-treeview">
... <i>Not implemented yet</i>
</div> </div>
<div id="cms-content-galleryview"> <div id="cms-content-galleryview">
... <i>Not implemented yet</i>
</div> </div>
</div> </div>

View File

@ -0,0 +1,3 @@
<div class="cms-content center">
<i>Not implemented yet</i>
</div>

View File

@ -0,0 +1,3 @@
<div class="cms-content center">
<i>Not implemented yet</i>
</div>

View File

@ -34,14 +34,10 @@
<% include CMSPagesController_ContentToolbar %> <% include CMSPagesController_ContentToolbar %>
</div> </div>
<div class="cms-tree" data-url-tree="$Link(getsubtree)" data-url-savetreenode="$Link(savetreenode)"> <div class="cms-tree" data-url-tree="$Link(getsubtree)" data-url-savetreenode="$Link(savetreenode)" data-hints="$SiteTreeHints">
$SiteTreeAsUL $SiteTreeAsUL
</div> </div>
<div class="cms-content-toolbar">
<% include CMSPagesController_ContentToolbar %>
</div>
<div class="ss-dialog cms-page-add-form-dialog" id="cms-page-add-form" title="<% _t('CMSMain.ChoosePageType', 'Choose a page type') %>"> <div class="ss-dialog cms-page-add-form-dialog" id="cms-page-add-form" title="<% _t('CMSMain.ChoosePageType', 'Choose a page type') %>">
$AddForm $AddForm
</div> </div>
@ -49,11 +45,11 @@
</div> </div>
<div id="cms-content-listview"> <div id="cms-content-listview">
... <i>Not implemented yet</i>
</div> </div>
<div id="cms-content-galleryview"> <div id="cms-content-galleryview">
... <i>Not implemented yet</i>
</div> </div>
</div> </div>