"innerHTML": "[+]", /* XXX i18n? */
"onclick": dojo.hitch(this, function() {
_add_or_at_least_select(
- this._value_of_widget(entry_widget),
+ this._value_for_compile(entry_widget),
value_widget
);
entry_widget.widget.attr("value", ""); /* clear */
return widg;
};
- this._value_of_widget = function(widg) {
+ this._value_for_serialize = function(widg) {
+ if (!widg.widget) /* widg is <select> */
+ return dojo.filter(
+ widg.options,
+ function(o) { return o.selected; }
+ ).map(
+ function(o) { return o.value; }
+ );
+ else
+ return widg.widget.attr("value");
+ };
+
+ this._value_for_compile = function(widg) {
if (!widg.widget) /* widg is <select> */
return dojo.filter(
widg.options,
this.get_selected_operator_name = function() {
var item = this.get_selected_operator();
- if (item)
- return this.operator_selector.store.getValue(item, "name")
- else
+ if (item) {
+ return this.operator_selector.store.getValue(item, "name");
+ } else {
console.warn(
"Could not determine selected operator. " +
"Something is about to break."
);
+ }
};
this.update_selected_operator = function(value) {
if (this.value_widgets) {
values = this.value_widgets.map(
- function(widg) { return widg.widget.attr("value"); }
+ dojo.hitch(
+ this, function(w) {
+ return this._value_for_serialize(w);
+ }
+ )
);
}
+ /* The following grew organically to be very silly and confusing.
+ * Could use a rethink (PCrudFilterRow.initialize() would also need
+ * matching changes). */
if (values.length == 1) {
- serialized.value = values[0];
+ if (dojo.isArray(values[0]))
+ serialized.values = values[0];
+ else
+ serialized.value = values[0];
} else if (values.length > 1) {
serialized.values = values;
}
this.compile = function() {
if (this.value_widgets) {
var values = this.value_widgets.map(
- dojo.hitch(this, this._value_of_widget)
+ dojo.hitch(this, this._value_for_compile)
);
if (!values.length) {
}
initializer.values = initializer.values || [];
- for (var i = 0; i < initializer.values.length; i++) {
- this.value_widgets[i].widget.attr(
- "value", initializer.values[i]
+ if (initializer.operator.match(/^(not ?)in$/)) {
+ /* "in" and "not in" need special treatement */
+ dojo.forEach(
+ initializer.values, dojo.hitch(this, function(v) {
+ _add_or_at_least_select(
+ v, this.value_widgets[0]
+ );
+ })
);
+ } else {
+ /* other operators work this way: */
+ for (var i = 0; i < initializer.values.length; i++) {
+ this.value_widgets[i].widget.attr(
+ "value", initializer.values[i]
+ );
+ }
}
}
);