Default to current fiscal year in ACQ order upload
[transitory.git] / Open-ILS / web / js / ui / default / acq / picklist / upload.js
index 1361685..1eb2933 100644 (file)
@@ -39,7 +39,10 @@ function init() {
         orgLimitPerms : ['CREATE_PICKLIST', 'CREATE_PURCHASE_ORDER'],
         parentNode : dojo.byId('acq-pl-upload-agency'),
     }).build(
-        function(w) { orderAgencyWidget = w }
+        function(w) { 
+            orderAgencyWidget = w 
+            dojo.connect(orderAgencyWidget, 'onChange', setDefaultFiscalYear);
+        }
     );
 
     vlAgent = new VLAgent();
@@ -58,6 +61,24 @@ function init() {
     );
 }
 
+function setDefaultFiscalYear(org) {
+    org = org || orderAgencyWidget.attr('value');
+
+    if (org) {
+
+        fieldmapper.standardRequest(
+            ['open-ils.acq', 'open-ils.acq.org_unit.current_fiscal_year'],
+            {   params : [openils.User.authtoken, org],
+                async : true,
+                oncomplete : function(r) {
+                    var year = openils.Util.readResponse(r);
+                    acqUploadYearSelector.attr('value', year);
+                }
+            }
+        );
+    }
+}
+
 function acqUploadRecords() {
     openils.Util.show('acq-pl-upload-progress');
     var picklist = acqPlUploadPlSelector.attr('value');
@@ -180,9 +201,9 @@ function loadYearSelector() {
                 yearStore.items = yearStore.items.sort().reverse();
                 acqUploadYearSelector.store = new dojo.data.ItemFileReadStore({data:yearStore});
 
-                // default to this year
-                // TODO: current fiscal year
-                acqUploadYearSelector.setValue(new Date().getFullYear().toString());
+                // until an ordering agency is selected, default to the 
+                // fiscal year of the workstation
+                setDefaultFiscalYear(new openils.User().user.ws_ou());
             }
         }
     );