From 5692f2c58cc9599ce4d239a29df40e720d823701 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Wed, 12 Sep 2012 14:02:49 -0400 Subject: [PATCH] Filter loading: gracefully skip unknown fields, remove inital empty row Signed-off-by: Lebbeous Fogle-Weekley --- .../web/js/dojo/openils/widget/PCrudFilterPane.js | 49 ++++++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js b/Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js index 08a26413eb..4b071a6161 100644 --- a/Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js +++ b/Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js @@ -251,20 +251,58 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) { 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(); }; @@ -572,7 +610,6 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) { }; 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); @@ -588,6 +625,10 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) { } }; + this.is_unset = function() { + return !Boolean(this.field_selector.attr("value")); + }; + this._init.apply(this, arguments); } -- 2.11.0