From: Bill Erickson Date: Fri, 28 Sep 2012 19:48:22 +0000 (-0400) Subject: AutoFieldWidget support external copy loc retrieval X-Git-Tag: sprint4-merge-nov22~3635 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b5826950c8deb7d20819e1cd4b5c18f608894ffe;p=working%2FEvergreen.git AutoFieldWidget support external copy loc retrieval When rendering a collection of copy locations, AFW fetches locations relevant to the context org unit. While rendering an AFW for an existing object, though, whose copy location is outside of that scope, the code will now append the non-local copy location to the selector and tag it with the owning lib (to avoid dupes). Signed-off-by: Bill Erickson Signed-off-by: Kathy Lussier Signed-off-by: Jason Stephenson --- diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js index 6e4c88f271..f5e5a99ad3 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js @@ -697,26 +697,74 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { this.widget = new dijit.form.FilteringSelect(this.dijitArgs, this.parentNode); this.widget.searchAttr = this.widget.labalAttr = 'name'; this.widget.valueAttr = 'id'; - - if(this.cache.copyLocStore) { - this.widget.store = this.cache.copyLocStore; - this.widget.startup(); - this.async = false; - return true; - } - + // my orgs var ws_ou = openils.User.user.ws_ou(); var orgs = fieldmapper.aou.findOrgUnit(ws_ou).orgNodeTrail().map(function (i) { return i.id() }); orgs = orgs.concat(fieldmapper.aou.descendantNodeList(ws_ou).map(function (i) { return i.id() })); var self = this; - new openils.PermaCrud().search('acpl', {owning_lib : orgs}, { + var search = {owning_lib : orgs}; + + if(this.cache.copyLocStore) { + var store = this.cache.copyLocStore; + var allGood = false; + var locIds = []; + + // make sure the copy location the caller cares + // about (our value) is present in the cache. + // if not, fetch the list, adding our value to + // the set of locations to fetch. + + var allGood = false; + if (this.widgetValue) { + + store.fetch({ + onComplete : function(list) { + dojo.forEach(list, function(item) { + var id = store.getValue(item, 'id'); + if (id == self.widgetValue) + allGood = true; + locIds.push(id); + }); + } + }); + + } else { + allGood = true; + } + + if (allGood) { + this.widget.store = this.cache.copyLocStore; + this.widget.startup(); + this.async = false; + return true; + + } else { + // cached IDs plus id of this.widgetValue; + locIds.push(this.widgetValue); + search = {id : locIds}; + } + } + + + new openils.PermaCrud().search('acpl', search, { async : !this.forceSync, order_by : {"acpl": "name"}, oncomplete : function(r) { var list = openils.Util.readResponse(r, false, true); if(!list) return; + + // if we are including any copy locations outside our org + // unit scope, tag them with a context org unit to prevent + // confusion caused by having multiple like-named entries + dojo.forEach(list, function(loc) { + if (orgs.indexOf(loc.owning_lib()) < 0) { + loc.name(loc.name() + ' (' + + fieldmapper.aou.findOrgUnit(loc.owning_lib()).shortname() + ')'); + } + }); + self.widget.store = new self.storeConstructor({data:fieldmapper.acpl.toStoreData(list)}); self.cache.copyLocStore = self.widget.store;