diff --git a/install/ui/ipa.css b/install/ui/ipa.css
index 71cad4206..3e443d54e 100644
--- a/install/ui/ipa.css
+++ b/install/ui/ipa.css
@@ -1294,6 +1294,21 @@ table.scrollable tbody {
width: 400px;
}
+.option_widget {
+ list-style-type: none;
+ margin: 0;
+ padding: 0;
+}
+
+.option_widget.nested {
+ padding-left: 40px;
+}
+
+.option_widget.inline,
+.option_widget.inline > li {
+ display: inline;
+}
+
.combobox-widget-input {
display: inline-block;
position: relative;
diff --git a/install/ui/src/freeipa/aci.js b/install/ui/src/freeipa/aci.js
index 383848ec6..b6825d136 100644
--- a/install/ui/src/freeipa/aci.js
+++ b/install/ui/src/freeipa/aci.js
@@ -477,7 +477,7 @@ IPA.attributes_widget = function(spec) {
'class': 'aci-attribute-table-container'
}).appendTo(container);
- that.table = $('
', {
+ that.$node = that.table = $('', {
id:id,
'class':'search-table aci-attribute-table scrollable'
}).
@@ -520,9 +520,12 @@ IPA.attributes_widget = function(spec) {
var tr = $('
').appendTo(tbody);
var td = $(' | ').appendTo(tr);
+ var name = that.get_input_name();
+ var id = that.option_next_id + name;
td.append($('',{
+ id: id,
type: 'checkbox',
- name: that.name,
+ name: name,
value: value,
'class': 'aci-attribute',
change: function() {
@@ -531,8 +534,10 @@ IPA.attributes_widget = function(spec) {
}));
td = $(' | ').appendTo(tr);
td.append($('',{
- text: value
+ text: value,
+ 'for': id
}));
+ that.new_option_id();
}
};
@@ -553,7 +558,7 @@ IPA.attributes_widget = function(spec) {
that.populate(that.object_type);
that.append();
- that.checkboxes_update(values);
+ that.owb_update(values);
};
that.populate = function(object_type) {
@@ -567,6 +572,7 @@ IPA.attributes_widget = function(spec) {
var aciattrs = metadata.aciattrs;
+ that.options = that.prepare_options(aciattrs);
that.create_options(aciattrs);
};
@@ -585,6 +591,7 @@ IPA.attributes_widget = function(spec) {
}
if (unmatched.length > 0 && !that.skip_unmatched) {
+ that.options.push.apply(that.options, that.prepare_options(unmatched));
that.create_options(unmatched);
}
};
diff --git a/install/ui/src/freeipa/rule.js b/install/ui/src/freeipa/rule.js
index 888fd4508..436e934ca 100644
--- a/install/ui/src/freeipa/rule.js
+++ b/install/ui/src/freeipa/rule.js
@@ -43,7 +43,8 @@ IPA.rule_details_widget = function(spec) {
that.enable_radio.value_changed.attach(that.on_enable_radio_changed);
};
- that.on_enable_radio_changed = function(value) {
+ that.on_enable_radio_changed = function() {
+ var value = that.enable_radio.save();
if(value.length > 0) {
var enabled = ('' === value[0]);
for (var i=0; i.
*/
-define(['./ipa', './jquery'], function(IPA, $) {
+define(['dojo/_base/array', './ipa', './jquery'], function(array, IPA, $) {
IPA.checkbox_column_width = 22;
IPA.required_indicator = '*';
@@ -616,147 +616,395 @@ IPA.multivalued_widget = function(spec) {
return that;
};
-IPA.checkbox_widget = function (spec) {
+/**
+ * Widget base for checkboxes and radios. Doesn't handle dirty state's but
+ * its supposed to be nestable.
+ *
+ * Nesting rules:
+ * 1. parent should be checked when one of its child is checked
+ * Consequences:
+ * * childs get unchecked when parent gets unchecked
+ * * parent will be checked when child is checked even when input
+ * values don't contain parent's value.
+ * 2. parent can be configured not to include it's value when children are
+ * checked
+ * 3. each subtree containing a checked input has to return at least one value
+ * on save()
+ * 4. each option has to have unique value
+ *
+ * Has subset of widget interface - overrides the values in widget
+ * * save(): get values
+ * * update(values): set values
+ * * value_changed: event when change happens
+ * * create: creates HTML
+ */
+IPA.option_widget_base = function(spec, that) {
spec = spec || {};
- var that = IPA.input_widget(spec);
+ // when that is specified, this constructor behaves like a mixin
+ that = that || {};
- // default value
- that.checked = spec.checked || false;
+ // classic properties
+ that.name = spec.name;
+ that.label = spec.label;
+ that.tooltip = spec.tooltip;
+ that.value_changed = IPA.observer();
+ that.default_value = spec.default_value || null;
- that.create = function(container) {
+ /**
+ * Jquery reference to current node
+ */
+ that.$node = null;
- that.widget_create(container);
+ /**
+ * Type of rendered inputs: ['checkbox', 'radio']
+ */
+ that.input_type = spec.input_type || 'checkbox';
- container.addClass('checkbox-widget');
+ /**
+ * CSS class for container
+ */
+ that.css_class = spec.css_class || '';
- that.input = $('', {
- type: 'checkbox',
- name: that.name,
- checked: that.checked,
- title: that.tooltip,
- change: function() {
- that.value_changed.notify([that.save()], that);
+ /**
+ * If it's nested widget
+ */
+ that.nested = !!spec.nested;
+
+ /**
+ * How items should be rendered.
+ *
+ * values: ['inline', 'vertical']
+ */
+ that.layout = spec.layout || 'vertical';
+
+ // private properties
+ that._child_widgets = [];
+ that._input_name = null;
+ that._selector = null;
+ that._option_next_id = 0;
+
+
+ /**
+ * Normalizes options spec
+ */
+ that.prepare_options = function(options) {
+
+ var ret = [];
+
+ if (!options) return options;
+
+ for (var i=0; i');
+ };
+
+ that._create_option = function(option, container) {
+ var input_name = that.get_input_name();
+ var id = that._option_next_id + input_name;
+
+ $('', {
+ id: id,
+ type: that.input_type,
+ name: input_name,
+ value: option.value,
+ title: option.tooltip || that.tooltip,
+ change: that.on_input_change
}).appendTo(container);
- if (that.undo) {
- that.create_undo(container);
+ $('', {
+ text: option.label,
+ title: option.tooltip || that.tooltip,
+ 'for': id
+ }).appendTo(container);
+
+ that.new_option_id();
+ };
+
+ that.create_option = function(option, container) {
+
+ that._create_option(option, container);
+
+ if (option.widget) {
+ option.widget.create(container);
}
-
- that.create_error_link(container);
};
- that.save = function() {
- var value = that.input.is(':checked');
- return [value];
+ that.new_option_id = function() {
+ that._option_next_id++;
};
- that.update = function(values) {
- var value;
+ that.get_input_name = function() {
- if (values && values.length) {
- value = values[0];
+ if (!that._input_name) {
+ var name = that.name;
+ if (that.input_type === 'radio') {
+ name = IPA.html_util.get_next_id(name);
+ }
+ that._input_name = name;
+ that._selector = 'input[name="'+name+'"]';
}
-
- if (typeof value !== 'boolean') {
- // use default value
- value = that.checked;
- }
-
- that.input.prop('checked', value);
+ return that._input_name;
};
- that.clear = function() {
- that.input.prop('checked', false);
- };
-
- that.checkbox_save = that.save;
-
- return that;
-};
-
-IPA.checkboxes_widget = function (spec) {
-
- spec = spec || {};
-
- var that = IPA.input_widget(spec);
-
- that.options = spec.options || [];
- that.direction = spec.direction || 'vertical';
-
that.create = function(container) {
+ that.destroy();
+ that.create_options(that.$node);
+ var css_class = [that.css_class, 'option_widget', that.layout,
+ that.nested ? 'nested': ''].join(' ');
- that.widget_create(container);
+ that.$node = $('', { 'class': css_class });
+ that.create_options(that.$node);
- container.addClass('checkboxes-widget');
+ if (container) that.$node.appendTo(container);
+ };
- var vertical = that.direction === 'vertical';
+ that.destroy = function() {
+ if (that.$node) {
+ that.$node.empty();
+ that.$node.remove();
+ }
+ for (var i=0; i< that._child_widgets.length; i++) {
+ that._child_widgets[i].destroy();
+ }
+ };
+
+ that.get_option = function(value) {
for (var i=0; i', {
- type: 'checkbox',
- name: that.name,
- value: option.value,
- title: that.tooltip
- }).appendTo(container);
+ if (option.value === value) return option;
+ }
+ return null;
+ };
- $('', {
- text: option.label,
- title: that.tooltip
- }).appendTo(container);
+ /**
+ * Get values for specific option and its children.
+ *
+ * If option is not specified, gets values of all options and children.
+ */
+ that.get_values = function(option) {
- if (vertical) {
- $('
').appendTo(container);
+ var values = [];
+ if (option) {
+ values.push(option.value);
+ if (option.widget) {
+ values.push.apply(values, option.widget.get_values());
+ }
+ } else {
+ for (var i=0; i 0) {
+
+ var parents_selected = [];
+
+ $(that._selector+':checked', that.container).each(function() {
+ var value = $(this).val();
+ var option = that.get_option(value);
+ if (option && option.nested) {
+ parents_selected.push(value);
+ }
+ });
+
+ for (var i=0; i -1;
+ option.widget.set_enabled(selected);
+ }
+ }
}
-
- var input = $('input[name="'+that.name+'"]', that.container);
- input.change(function() {
- that.value_changed.notify([that.save()], that);
- });
-
- that.create_error_link(container);
+ that.value_changed.notify([], that);
};
that.save = function() {
+
var values = [];
- $('input[name="'+that.name+'"]:checked', that.container).each(function() {
- values.push($(this).val());
- });
+ if (that.$node) {
+
+ $(that._selector+':checked', that.container).each(function() {
+ var value = $(this).val();
+ var child_values = [];
+ var option = that.get_option(value);
+
+ if (option.widget) {
+ child_values = option.widget.save();
+ values.push.apply(values, child_values);
+ }
+
+ // don't use value if cannot be combined with children's value
+ if (!(child_values.length > 0 && !option.combine_values)) {
+ values.push(value);
+ }
+ });
+ }
return values;
};
that.update = function(values) {
- var inputs = $('input[name="'+that.name+'"]', that.container);
- inputs.prop('checked', false);
- for (var j=0; values && j 0) {
+
+ // check the option when option or some of its child should be
+ // checked
+ for (var i=0; i -1;
+ });
+
+ if (has_opt) {
+ check(that._selector+'[value="'+ option.value +'"]');
+ }
+ if (option.widget) {
+ option.widget.set_enabled(has_opt);
+ }
+ }
+ } else {
+ // select default if none specified
+ if (that.default_value !== null) {
+ check(that._selector+'[value="'+that.default_value+'"]');
+ } else {
+ // otherwise select empty
+ check(that._selector+'[value=""]');
+ }
+ }
+
+ for (var j=0; j', {
- id: id,
- type: 'radio',
- name: name,
- value: option.value
- }).appendTo(container);
-
- $('', {
- text: option.label,
- 'for': id
- }).appendTo(container);
- }
-
if (that.undo) {
that.create_undo(container);
}
- var input = $(that.selector, that.container);
- input.change(function() {
- that.value_changed.notify([that.save()], that);
- });
-
that.create_error_link(container);
};
+ return that;
+};
+
+IPA.checkbox_widget = function (spec) {
+
+ var checked = 'checked';
+
+ spec = spec || {};
+ spec.input_type = spec.input_type || 'checkbox';
+
+ if (!spec.options) {
+ spec.options = [ { value: checked, label: '' } ];
+ }
+
+ if (spec.checked) spec.default_value = spec.checked;
+
+ var that = IPA.radio_widget(spec);
that.save = function() {
- var input = $(that.selector+':checked', that.container);
- if (!input.length) return [];
- return [input.val()];
+ var values = that.owb_save();
+ return [values.length > 0];
};
that.update = function(values) {
+ var value = values ? values[0] : '';
- $(that.selector, that.container).each(function() {
- var input = this;
- input.checked = false;
- });
-
- var value = values && values.length ? values[0] : '';
- var input = $(that.selector+'[value="'+value+'"]', that.container);
- if (input.length) {
- input.prop('checked', true);
- } else if (that.default_value) {
- input = $(that.selector+'[value="'+that.default_value+'"]', that.container);
- input.prop('checked', true);
+ if (typeof value !== 'boolean') {
+ value = that.default_value || '';
+ } else {
+ value = value ? checked : '';
}
-
- that.value_changed.notify([that.save()], that);
+ that.owb_update([value]);
};
- that.clear = function() {
- $(that.selector, that.container).prop('checked', false);
-
- if (that.default_value) {
- var input = $(that.selector+'[value="'+that.default_value+'"]', that.container);
- input.prop('checked', true);
- }
- };
-
- // methods that should be invoked by subclasses
- that.radio_create = that.create;
- that.radio_save = that.save;
+ return that;
+};
+IPA.checkboxes_widget = function (spec) {
+ spec = spec || {};
+ spec.input_type = spec.input_type || 'checkbox';
+ spec.layout = spec.layout || 'vertical';
+ var that = IPA.radio_widget(spec);
return that;
};