From: Bill Erickson Date: Thu, 22 Mar 2012 17:41:29 +0000 (-0400) Subject: AutoFieldWidget single-object cache repairs X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=73a6d114b56af44b8af40b28d9406d527e6f94f6;p=contrib%2FConifer.git AutoFieldWidget single-object cache repairs Caching single objects linked off the context object was failing in most cases as it was caching under the display name instead of the true value (pkey) for the linked object. This fixes that by always caching the linked object by its true value, so that future cache lookups will be looking in the right place. Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js index ad5d92b181..50d1a4f40c 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js @@ -389,14 +389,18 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { } // then try the single object cache - if(this.cache[this.auth].single[lclass] && - this.cache[this.auth].single[lclass][this.widgetValue] && - this.cache[this.auth].single[lclass][this.widgetValue][self.labelFormat || '']) { - this.widgetValue = this.cache[this.auth].single[lclass][this.widgetValue][self.labelFormat || '']; + var item; + if(this.cache[this.auth].single[lclass] && ( + item = this.cache[this.auth].single[lclass][this.widgetValue]) ) { + + this.widgetValue = (this.labelFormat) ? + this._applyLabelFormat(item.toStoreItem(), this.labelFormat) : + item[linkInfo.vfield.selector](); + return; } - console.log("Fetching sync object " + lclass + " : " + this.widgetValue); + console.log("Fetching linked object " + lclass + " : " + this.widgetValue); // if those fail, fetch the linked object this.async = true; @@ -406,22 +410,14 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { oncomplete : function(r) { var item = openils.Util.readResponse(r); - var newvalue = item[linkInfo.vfield.selector](); - - var labelCacheKey = ''; - - if(self.labelFormat) { - labelCacheKey = self.labelFormat; - self.widgetValue = self._applyLabelFormat(item.toStoreItem(), self.labelFormat); - } else { - self.widgetValue = newvalue; - } - + // cache the true object under its real value if(!self.cache[self.auth].single[lclass]) self.cache[self.auth].single[lclass] = {}; - if(!self.cache[self.auth].single[lclass][self.widgetValue]) - self.cache[self.auth].single[lclass][self.widgetValue] = {}; - self.cache[self.auth].single[lclass][self.widgetValue][labelCacheKey] = newvalue; + self.cache[self.auth].single[lclass][self.widgetValue] = item; + + self.widgetValue = (self.labelFormat) ? + self._applyLabelFormat(item.toStoreItem(), self.labelFormat) : + item[linkInfo.vfield.selector](); self.widget.startup(); self._widgetLoaded();