[open-ils-commits] [GIT] Evergreen ILS branch master updated. cb3125afa53716ae6642e5510e37a92f79f1ed53

Evergreen Git git at git.evergreen-ils.org
Wed Aug 24 08:49:34 EDT 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  cb3125afa53716ae6642e5510e37a92f79f1ed53 (commit)
      from  a898371a6c547b35612578f063b614f5cd0709e5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit cb3125afa53716ae6642e5510e37a92f79f1ed53
Author: Bill Erickson <berick at esilibrary.com>
Date:   Tue Aug 23 14:22:06 2011 -0400

    Support labelFormat for read-only AutoFieldWidget's
    
    Previously only worked with edit widgets (e.g. drop-downs).  This also
    takes into account the fact that different instances of AutoFieldWidget
    for the same class and value may have different labelFormat's
    
    One user-visible result of this change is the ACQ read-only fund display
    in purchase orders.  Funds will now show the code and year for funds in
    the copy grid before and after the data is rendered read-only.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
index c33b5e1..41f5b29 100644
--- a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
+++ b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
@@ -364,7 +364,12 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
                 store.fetch({query:query, onComplete:
                     function(list) {
                         if(list[0]) {
-                            self.widgetValue = store.getValue(list[0], linkInfo.vfield.selector);
+                            var item = list[0];
+                            if(self.labelFormat) {
+                                self.widgetValue = self._applyLabelFormat(item, self.labelFormat);
+                            } else {
+                                self.widgetValue = store.getValue(item, linkInfo.vfield.selector);
+                            }
                             found = true;
                         }
                     }
@@ -374,8 +379,10 @@ 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.widgetValue = this.cache[this.auth].single[lclass][this.widgetValue];
+            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 || ''];
                 return;
             }
 
@@ -388,13 +395,24 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
                 async : !this.forceSync,
                 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;
+                    }
+
                     if(!self.cache[self.auth].single[lclass])
                         self.cache[self.auth].single[lclass] = {};
-                    self.cache[self.auth].single[lclass][self.widgetValue] = newvalue;
+                    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.widgetValue = newvalue;
                     self.widget.startup();
                     self._widgetLoaded();
                 }
@@ -428,6 +446,25 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
             };
         },
 
+        _applyLabelFormat : function (item, formatList) {
+
+            try {
+
+                // formatList[1..*] are names of fields.  Pull the field
+                // values from each object to determine the values for string substitution
+                var values = [];
+                var format = formatList[0];
+                for(var i = 1; i< formatList.length; i++) 
+                    values.push(item[formatList[i]]);
+
+                return dojo.string.substitute(format, values);
+
+            } catch(E) {
+                throw new Error(
+                    "openils.widget.AutoFieldWidget: Invalid formatList ["+formatList+"] : "+E);
+            }
+        },
+
         _buildLinkSelector : function() {
             var self = this;
             var selectorInfo = this._getLinkSelector();
@@ -465,33 +502,13 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
                 if(self.searchFormat)
                     self.widget.searchAttr = '_search';
 
-                function formatString(item, formatList) {
-
-                    try {
-
-                        // formatList[1..*] are names of fields.  Pull the field
-                        // values from each object to determine the values for string substitution
-                        var values = [];
-                        var format = formatList[0];
-                        for(var i = 1; i< formatList.length; i++) 
-                            values.push(item[formatList[i]]);
-
-                        return dojo.string.substitute(format, values);
-
-                    } catch(E) {
-                        throw new Error(
-                            "openils.widget.AutoFieldWidget: Invalid formatList ["+formatList+"] : "+E);
-                    }
-
-                }
-
                 if(list) {
                     var storeData = {data:fieldmapper[linkClass].toStoreData(list)};
 
                     if(self.labelFormat) {
                         dojo.forEach(storeData.data.items, 
                             function(item) {
-                                item._label = formatString(item, self.labelFormat);
+                                item._label = self._applyLabelFormat(item, self.labelFormat);
                             }
                         );
                     }
@@ -499,7 +516,7 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
                     if(self.searchFormat) {
                         dojo.forEach(storeData.data.items, 
                             function(item) {
-                                item._search = formatString(item, self.searchFormat);
+                                item._search = self._applyLabelFormat(item, self.searchFormat);
                             }
                         );
                     }

-----------------------------------------------------------------------

Summary of changes:
 .../web/js/dojo/openils/widget/AutoFieldWidget.js  |   71 ++++++++++++--------
 1 files changed, 44 insertions(+), 27 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list