ENHANCEMENT Using chosen.js for group selection in Member->getCMSFields()

This commit is contained in:
Ingo Schommer 2012-03-02 18:11:02 +01:00
parent 8fa266462f
commit 46628721fe
3 changed files with 22 additions and 7 deletions

View File

@ -363,9 +363,9 @@ jQuery.noConflict();
* we can fix the height cropping.
*/
$('.cms .field.dropdown').entwine({
$('.cms .field.dropdown, .cms .field.checkboxset').entwine({
onmatch: function() {
$(this).find("select:not(.no-chzn)").chosen();
$(this).find("select:not(.no-chzn)").data('placeholder', ' ').chosen();
$(this).addClass("has-chzn");
this._super();

View File

@ -1133,12 +1133,16 @@ class Member extends DataObject {
// Groups relation will get us into logical conflicts because
// Members are displayed within group edit form in SecurityAdmin
$fields->removeByName('Groups');
if(Permission::check('EDIT_PERMISSIONS')) {
$groupsField = new TreeMultiselectField('Groups', false, 'Group');
$fields->findOrMakeTab('Root.Groups', singleton('Group')->i18n_plural_name());
$fields->addFieldToTab('Root.Groups', $groupsField);
$groupsMap = DataList::create('Group')->map('ID', 'Breadcrumbs')->toArray();
asort($groupsMap);
$fields->addFieldToTab('Root.Main',
Object::create('CheckboxSetField', 'Groups', singleton('Group')->i18n_plural_name())
->setTemplate('CheckboxSetField_Select')
->setSource($groupsMap)
);
// Add permission field (readonly to avoid complicated group assignment logic).
// This should only be available for existing records, as new records start
// with no permissions until they have a group assignment anyway.

View File

@ -0,0 +1,11 @@
<%-- Renders a CheckboxField with $multiple=true as a select element which can save into relations.--%>
<%-- TODO Make relation saving available on ListboxField --%>
<select id="$ID" class="$extraClass" name="$Name[]" multiple="true">
<% if Options.Count %>
<% control Options %>
<option class="$Class" value="$Value"<% if isChecked %> selected="selected"<% end_if %>>
$Title
</option>
<% end_control %>
<% end_if %>
</select>