From: Bill Erickson Date: Mon, 28 Jan 2013 15:37:33 +0000 (-0500) Subject: ACQ upload form persist scratch X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1099f6dff56ce69c8f13fb1d86314becddfcdd48;p=evergreen%2Fequinox.git ACQ upload form persist scratch Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/web/js/ui/default/acq/common/vlagent.js b/Open-ILS/web/js/ui/default/acq/common/vlagent.js index a4db898faf..a3d5c8daff 100644 --- a/Open-ILS/web/js/ui/default/acq/common/vlagent.js +++ b/Open-ILS/web/js/ui/default/acq/common/vlagent.js @@ -2,6 +2,13 @@ dojo.require('openils.widget.AutoFieldWidget'); dojo.require('openils.PermaCrud'); dojo.require('openils.XUL'); +/** + * readCachedValue and writeCachedValue are defined + * in acq/picklist/upload.js. If this file is + * otherwise needed, those funcs will need local + * stubs or to be moved to a more generic location + */ + function VLAgent(args) { args = args || {}; for (var key in args) { @@ -24,35 +31,35 @@ function VLAgent(args) { ]; this.loaded = false; - var xulStorage = openils.XUL.localStorage(); - var storekey = 'eg.acq.'; this.init = function() { var self = this; dojo.forEach(this.widgets, function(widg) { + var key = widg.key; - var cval = xulStorage.getItem(storekey + widg.key); if (widg.cls) { // selectors new openils.widget.AutoFieldWidget({ fmClass : widg.cls, selfReference : true, orgLimitPerms : [self.limitPerm || 'CREATE_PURCHASE_ORDER'], - parentNode : dojo.byId('acq_vl:' + widg.key), + parentNode : dojo.byId('acq_vl:' + key), searchFilter : (widg.cls == 'vbq') ? {queue_type : 'acq'} : null, useWriteStore : (widg.cls == 'vbq') }).build(function(dij) { widg.dijit = dij; - if (cval) widg.dijit.attr('value', cval); + if (!key.match(/queue/)) + readCachedValue(dij, key); self.attachOnChange(widg); }); } else { // bools - widg.dijit = dijit.byId('acq_vl:' + widg.key); + widg.dijit = dijit.byId('acq_vl:' + key); if (!widg.dijit) return; // some fields optional - if (cval) widg.dijit.attr('value', cval); + if (!key.match(/queue/)) + readCachedValue(widg.dijit, key); self.attachOnChange(widg); } } @@ -143,11 +150,8 @@ function VLAgent(args) { function(widg) { if (widg.dijit) { values[widg.key] = widg.dijit.attr('value'); - if (values[widg.key]) { - xulStorage.setItem(storekey + widg.key, values[widg.key]); - } else { - xulStorage.removeItem(storekey + widg.key); - } + if (!widg.key.match(/queue/)) + writeCachedValue(widg.dijit, widg.key); } } ); diff --git a/Open-ILS/web/js/ui/default/acq/picklist/upload.js b/Open-ILS/web/js/ui/default/acq/picklist/upload.js index 1eb2933632..fed74d38d2 100644 --- a/Open-ILS/web/js/ui/default/acq/picklist/upload.js +++ b/Open-ILS/web/js/ui/default/acq/picklist/upload.js @@ -19,18 +19,26 @@ var orderAgencyWidget; var vlAgent; var usingNewPl = false; +var xulStorage = openils.XUL.localStorage(); +var storekey = 'eg.acq.upload.'; + function init() { dojo.byId('acq-pl-upload-ses').value = openils.User.authtoken; loadYearSelector(); + var val; + new openils.widget.AutoFieldWidget({ fmClass : 'acqpo', fmField : 'provider', orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'], parentNode : dojo.byId('acq-pl-upload-provider'), }).build( - function(w) { providerWidget = w } + function(w) { + providerWidget = w; + readCachedValue(w, 'provider'); + } ); new openils.widget.AutoFieldWidget({ @@ -41,10 +49,14 @@ function init() { }).build( function(w) { orderAgencyWidget = w + readCachedValue(w, 'ordering_agency'); dojo.connect(orderAgencyWidget, 'onChange', setDefaultFiscalYear); } ); + readCachedValue(acqPlUploadCreatePo, 'create_po'); + readCachedValue(acqPlUploadActivatePo, 'activate_po'); + vlAgent = new VLAgent(); vlAgent.init(); @@ -61,6 +73,24 @@ function init() { ); } +function readCachedValue(dij, key) { + // TODO: check for org settings first + var val = xulStorage.getItem(storekey + key); + if (dij && val) dij.attr('value', val); + return val; +} + +function writeCachedValue(dij, key) { + // TODO: if org settings exist for key, do not store + var val = dij.attr('value'); + if (val === null || val === false || val == '') { + xulStorage.removeItem(storekey + key); + } else { + xulStorage.setItem(storekey + key, val); + } +} + + function setDefaultFiscalYear(org) { org = org || orderAgencyWidget.attr('value'); @@ -131,6 +161,12 @@ function acqHandlePostUpload(key, plId) { fiscal_year : acqUploadYearSelector.attr('value') }; + + writeCachedValue(acqPlUploadCreatePo, 'create_po'); + writeCachedValue(acqPlUploadActivatePo, 'activate_po'); + writeCachedValue(providerWidget, 'provider'); + writeCachedValue(orderAgencyWidget, 'ordering_agency'); + fieldmapper.standardRequest( ['open-ils.acq', 'open-ils.acq.process_upload_records'], { async: true,