return result;
};
- this.add_row = function(initializer) {
+ this._validate_initializer = function(initializer, onsuccess) {
+ this.field_store.fetchItemByIdentity({
+ "identity": initializer.field,
+ "onItem": dojo.hitch(this, function(item) {
+ if (item) {
+ onsuccess();
+ } else {
+ console.debug(
+ "skipping initializer for field " +
+ initializer.field + " not present here"
+ );
+ }
+ })
+ });
+ };
+
+ this._proceed_add_row = function(initializer) {
+ var row_id_list = openils.Util.objectProperties(this.rows);
+
+ /* Kill initial empty row when adding pre-initialized rows. */
+ if (row_id_list.length == 1 && initializer) {
+ var existing_row_id = row_id_list.shift();
+ if (this.rows[existing_row_id].is_unset())
+ this.remove_row(existing_row_id, true /* no_apply */);
+ }
+
this.hide_empty_placeholder();
var row_id = this.row_index++;
this.rows[row_id] = new PCrudFilterRow(this, row_id, initializer);
};
- this.remove_row = function(row_id) {
+ this.add_row = function(initializer) {
+ if (initializer) {
+ this._validate_initializer(
+ initializer,
+ dojo.hitch(this, function() {
+ this._proceed_add_row(initializer);
+ })
+ );
+ } else {
+ this._proceed_add_row(initializer);
+ }
+ };
+
+ this.remove_row = function(row_id, no_apply) {
this.rows[row_id].destroy();
delete this.rows[row_id];
if (openils.Util.objectProperties(this.rows).length < 1)
this.show_empty_placeholder();
- if (this.compact)
+ if (this.compact && !no_apply)
this.do_apply();
};
};
this.initialize = function(initializer) {
- console.log("initializer is " + dojo.toJson(initializer));
this.field_selector.attr("value", initializer.field);
this.operator_selector.attr("value", initializer.operator);
}
};
+ this.is_unset = function() {
+ return !Boolean(this.field_selector.attr("value"));
+ };
+
this._init.apply(this, arguments);
}