From 990df40fceb4e73dc529727b74f07443fe45163f Mon Sep 17 00:00:00 2001 From: Scott Prater Date: Wed, 18 Jan 2012 14:30:00 -0600 Subject: [PATCH] Patron Stat Cat Enhancements: Enforce stat_cat "allow_freetext" flag in patron registration screen If a patron statistical category is flagged to disallow user-provided entries, make the category form field a FilteringSelect box; otherwise, make it a ComboBox. Signed-off-by: Scott Prater Signed-off-by: Ben Shum Signed-off-by: Thomas Berezansky --- Open-ILS/web/js/ui/default/actor/user/register.js | 33 ++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/Open-ILS/web/js/ui/default/actor/user/register.js b/Open-ILS/web/js/ui/default/actor/user/register.js index bcdf18bd33..523639b025 100644 --- a/Open-ILS/web/js/ui/default/actor/user/register.js +++ b/Open-ILS/web/js/ui/default/actor/user/register.js @@ -804,6 +804,7 @@ function loadAllAddrs() { } function loadStatCats() { + var sc_widget; statCats = fieldmapper.standardRequest( ['open-ils.circ', 'open-ils.circ.stat_cat.actor.retrieve.all'], @@ -814,6 +815,7 @@ function loadStatCats() { for(var idx in statCats) { var stat = statCats[idx]; var required = openils.Util.isTrue(stat.required()); + var allow_freetext = openils.Util.isTrue(stat.allow_freetext()); var row = statCatTemplate.cloneNode(true); row.id = 'stat-cat-row-' + idx; row.setAttribute('stat_cat_owner',stat.owner()); @@ -830,32 +832,39 @@ function loadStatCats() { var span = valtd.appendChild(document.createElement('span')); var store = new dojo.data.ItemFileReadStore( {data:fieldmapper.actsc.toStoreData(stat.entries())}); - var comboBox = new dijit.form.ComboBox({store:store,scrollOnFocus:false,fetchProperties:{sort:[{attribute: 'value'}]}}, span); + + if(allow_freetext) { + sc_widget = new dijit.form.ComboBox({store:store,scrollOnFocus:false,fetchProperties:{sort:[{attribute: 'value'}]}}, span); + } else { + sc_widget = new dijit.form.FilteringSelect({store:store,scrollOnFocus:false,fetchProperties:{sort:[{attribute: 'value'}]}}, span); + } + if(required) { - comboBox.isValid = function() { + sc_widget.isValid = function() { // Must contain a word character if(this.attr("value").match(/\w/)) { return true; } else return false; }; - comboBox.attr('required', true); + sc_widget.attr('required', true); } - comboBox.labelAttr = 'value'; - comboBox.searchAttr = 'value'; - comboBox._wtype = 'statcat'; - comboBox._statcat = stat.id(); + sc_widget.labelAttr = 'value'; + sc_widget.searchAttr = 'value'; + + sc_widget._wtype = 'statcat'; + sc_widget._statcat = stat.id(); // populate existing cats var map = patron.stat_cat_entries().filter( function(mp) { return (mp.stat_cat() == stat.id()) })[0]; - if(map) comboBox.attr('value', map.stat_cat_entry()); + if(map) sc_widget.attr('value', map.stat_cat_entry()); - comboBox._hasBeenBlurred = true; - if(comboBox.validate) - comboBox.validate(); + sc_widget._hasBeenBlurred = true; + if(sc_widget.validate) + sc_widget.validate(); - widgetPile.push(comboBox); + widgetPile.push(sc_widget); } } -- 2.11.0