From bf43e8670e2971d96888fb4e57fc64b47ee46c74 Mon Sep 17 00:00:00 2001
From: Bill Erickson <berick@esilibrary.com>
Date: Fri, 10 Feb 2012 10:40:17 -0500
Subject: [PATCH] AutoFieldWidget gets new useWriteStore option

If the useWriteStore attribute is set to true, the underlying data store
for dynamically create data will live in an ItemFileWriteStore instead
of a ReadStore, which allows the caller to modify the data after the
widget is rendered.  It's useful for in-place additions of newly created
items.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>
---
 Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
index 41f5b2957c..ad5d92b181 100644
--- a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
+++ b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
@@ -46,6 +46,9 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
          *      The fetched objects should be passed to the callback as an array
          *  disableQuery : dojo.data query passed to FilteringTreeSelect-based widgets to disable
          *      (but leave visible) certain options.  
+         *  useWriteStore : tells AFW to use a dojo.data.ItemFileWriteStore instead of a ReadStore for
+         *      data stores created with dynamic data.  This allows the caller to add/remove items from 
+         *      the store.
          */
         constructor : function(args) {
             for(var k in args)
@@ -102,6 +105,13 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
             this.cache[this.auth] = this.cache[this.auth] || {};
             this.cache[this.auth].single = this.cache[this.auth].single || {};
             this.cache[this.auth].list = this.cache[this.auth].list || {};
+
+            if (this.useWriteStore) {
+                dojo.require('dojo.data.ItemFileWriteStore');
+                this.storeConstructor = dojo.data.ItemFileWriteStore;
+            } else {
+                this.storeConstructor = dojo.data.ItemFileReadStore;
+            }
         },
 
         /**
@@ -521,7 +531,7 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
                         );
                     }
 
-                    self.widget.store = new dojo.data.ItemFileReadStore(storeData);
+                    self.widget.store = new self.storeConstructor(storeData);
                     self.cache[self.auth].list[linkClass] = self.widget.store;
 
                 } else {
@@ -703,7 +713,7 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
                     var list = openils.Util.readResponse(r, false, true);
                     if(!list) return;
                     self.widget.store = 
-                        new dojo.data.ItemFileReadStore({data:fieldmapper.acpl.toStoreData(list)});
+                        new self.storeConstructor({data:fieldmapper.acpl.toStoreData(list)});
                     self.cache.copyLocStore = self.widget.store;
                     self.widget.startup();
                     self._widgetLoaded();
-- 
2.11.0