MINOR Selection bugfixes for CMSMain.AddForm.js, more efficient tree metadata

This commit is contained in:
Ingo Schommer 2012-01-05 17:01:48 +01:00
parent 6dd0535442
commit 6887b88099
2 changed files with 15 additions and 7 deletions

View File

@ -230,7 +230,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$classes = ClassInfo::subclassesFor( $this->stat('tree_class') );
$def['Root'] = array();
$def['Root']['disallowedChildren'] = array();
$def['Root']['disallowedParents'] = array();
foreach($classes as $class) {
@ -242,8 +241,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// SiteTree::allowedChildren() returns null rather than an empty array if SiteTree::allowed_chldren == 'none'
if($allowedChildren == null) $allowedChildren = array();
$def[$class]['disallowedChildren'] = array_keys(array_diff($classes, $allowedChildren));
$allowedChildren = array_keys(array_diff($classes, $allowedChildren));
if($allowedChildren) $def[$class]['disallowedChildren'] = $allowedChildren;
$defaultChild = $obj->defaultChild();
@ -255,7 +254,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
if ($defaultParent != 1 && $defaultParent != null) $def[$class]['defaultParent'] = $defaultParent;
if(is_array($def[$class]['disallowedChildren'])) {
if(isset($def[$class]['disallowedChildren'])) {
foreach($def[$class]['disallowedChildren'] as $disallowedChild) {
$def[$disallowedChild]['disallowedParents'][] = $class;
}

View File

@ -32,6 +32,7 @@
this.find('#ParentID .TreeDropdownField').bind('change', function() {
self.updateTypeList();
});
this.updateTypeList();
},
/**
@ -42,7 +43,7 @@
var hints = this.find('.hints').data('hints'),
metadata = this.find('#ParentID .TreeDropdownField').data('metadata'),
id = this.find('#ParentID .TreeDropdownField').getValue(),
newClassName = metadata.ClassName,
newClassName = metadata ? metadata.ClassName : null,
disallowedChildren = hints[newClassName ? newClassName : 'Root'].disallowedChildren || [],
defaultChildClass = hints[newClassName ? newClassName : 'Root'].defaultChild || null;
@ -64,12 +65,20 @@
});
$(".cms-add-form #PageType li").entwine({
onclick: function() {
this.setSelected(true);
},
setSelected: function(bool) {
this.toggleClass('selected', bool);
if(bool) {
this.siblings().setSelected(false);
this.find('input').attr('checked', 'checked');
}
},
setEnabled: function(bool) {
$(this).toggleClass('disabled', bool);
$(this).find('input').attr('disabled', bool ? '' : 'disabled');
$(this).toggleClass('disabled', !bool);
if(!bool) $(this).find('input').attr('disabled', 'disabled').removeAttr('checked');
else $(this).find('input').removeAttr('disabled');
}
});