mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
ENHANCEMENT Limiting page types based on SiteTree::$allowed_children in CMSMain.AddForm.js
This commit is contained in:
parent
b4366c9ca9
commit
26151f2e4c
@ -1297,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')
|
||||||
);
|
);
|
||||||
@ -1312,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;
|
||||||
}
|
}
|
||||||
|
@ -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');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user