From 7a8721b5ff982b1196815898b6b69cae3223de5b Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 5 Mar 2010 16:47:53 +0000 Subject: [PATCH] added support for overriding the searchAttr in addition the labelAttr. This is necessary when using HTML labelAttrs, which do not work in type-ahead or in display fields git-svn-id: svn://svn.open-ils.org/ILS/trunk@15712 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../web/js/dojo/openils/widget/AutoFieldWidget.js | 57 ++++++++++++++-------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js index f5be9c4e77..6a3ee6d996 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js @@ -36,6 +36,11 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { * represented as field names on the remote linked object. * E.g. * labelFormat : [ '${0} (${1})', 'obj_field_1', 'obj_field_2' ] + * Note: this does not control the final display value. Only values in the drop-down. + * See searchFormat for controlling the display value + * searchFormat -- This format controls the structure of the search attribute which + * controls the text used during type-ahead searching and the displayed value in + * the filtering select. See labelFormat for the structure. * dataLoader : Bypass the default PermaCrud linked data fetcher and use this function instead. * Function arguments are (link class name, search filter, callback) * The fetched objects should be passed to the callback as an array @@ -383,34 +388,46 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { var oncomplete = function(list) { if(self.labelFormat) - self.widget.labelAttr = self.widget.searchAttr = '_label'; + self.widget.labelAttr = '_label'; - if(list) { - var storeData = {data:fieldmapper[linkClass].toStoreData(list)}; + if(self.searchFormat) + self.widget.searchAttr = '_search'; - if(self.labelFormat) { - - // set the label for each value in the store based on the provided label format. + function formatString(item, formatList) { - var format = self.labelFormat[0]; - dojo.forEach(storeData.data.items, + try { - function(item) { - var values = []; + // 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]]); - try { + return dojo.string.substitute(format, values); - // self.labelFormat[1..*] are names of fields. Pull the field - // values from each object to determine the values for string substitution - for(var i = 1; i< self.labelFormat.length; i++) - values.push(item[self.labelFormat[i]]); + } catch(E) { + throw new Error( + "openils.widget.AutoFieldWidget: Invalid formatList ["+formatList+"] : "+E); + } - item._label = dojo.string.substitute(format, values); + } - } catch(E) { - throw new Error("openils.widget.AutoFieldWidget: Invalid labelFormat [" + - self.labelFormat + "] : " + 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); + } + ); + } + + if(self.searchFormat) { + dojo.forEach(storeData.data.items, + function(item) { + item._search = formatString(item, self.searchFormat); } ); } -- 2.11.0