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) {
];
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);
}
}
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);
}
}
);
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({
}).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();
);
}
+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');
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,