[open-ils-commits] r15712 - trunk/Open-ILS/web/js/dojo/openils/widget (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Mar 5 11:47:56 EST 2010
Author: erickson
Date: 2010-03-05 11:47:53 -0500 (Fri, 05 Mar 2010)
New Revision: 15712
Modified:
trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
Log:
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
Modified: trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js 2010-03-05 16:43:49 UTC (rev 15711)
+++ trunk/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js 2010-03-05 16:47:53 UTC (rev 15712)
@@ -36,6 +36,11 @@
* 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,38 +388,50 @@
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);
+ }
+ );
+ }
+
self.widget.store = new dojo.data.ItemFileReadStore(storeData);
self.cache[self.auth].list[linkClass] = self.widget.store;
More information about the open-ils-commits
mailing list