backporting -r13845:13848. fund year list api call, suppresse linked fields, fund...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 17 Aug 2009 16:16:22 +0000 (16:16 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Mon, 17 Aug 2009 16:16:22 +0000 (16:16 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_1_6@13849 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Acq/Financials.pm
Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
Open-ILS/web/js/dojo/openils/widget/AutoGrid.js
Open-ILS/web/js/ui/default/acq/financial/list_funds.js

index 4c843f4..54e7a72 100644 (file)
@@ -285,6 +285,11 @@ __PACKAGE__->register_method(
     }
 );
 
+__PACKAGE__->register_method(
+       method => 'retrieve_org_funds',
+       api_name        => 'open-ils.acq.fund.org.years.retrieve');
+
+
 sub retrieve_org_funds {
     my($self, $conn, $auth, $filter, $options) = @_;
     my $e = new_editor(authtoken=>$auth);
@@ -300,7 +305,6 @@ sub retrieve_org_funds {
         $U->user_has_work_perm_at($e, $limit_perm, {descendants =>1});
     return undef unless @{$filter->{org}};
 
-
     my $query = [
         $filter,
         {
@@ -310,6 +314,19 @@ sub retrieve_org_funds {
         }
     ];
 
+    if($self->api_name =~ /years/) {
+        # return the distinct set of fund years covered by the selected funds
+        my $data = $e->json_query({
+            select => {
+                acqf => [{column => 'year', transform => 'distinct'}]
+            }, 
+            from => 'acqf', 
+            where => $filter}
+        );
+
+        return [map { $_->{year} } @$data];
+    }
+
     my $funds = $e->search_acq_fund($query);
 
     for my $fund (@$funds) {
index 569b37e..0b4a242 100644 (file)
@@ -33,6 +33,7 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
             if(this.fmObject) 
                 this.fmClass = this.fmObject.classname;
             this.fmIDL = fieldmapper.IDL.fmclasses[this.fmClass];
+            this.suppressLinkedFields = args.suppressLinkedFields || [];
 
             if(!this.idlField) {
                 this.fmIDL = fieldmapper.IDL.fmclasses[this.fmClass];
@@ -200,6 +201,10 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) {
             if(this.idlField.datatype == 'org_unit')
                 return false; // we already handle org_units, no need to re-fetch
 
+            // user opted to bypass fetching this linked data
+            if(this.suppressLinkedFields.indexOf(this.idlField.name) > -1)
+                return false;
+
             var linkInfo = this._getLinkSelector();
             if(!(linkInfo && linkInfo.vfield && linkInfo.vfield.selector)) 
                 return false;
index f903d7a..f57f36a 100644 (file)
@@ -26,6 +26,7 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
             displayLimit : 15,
             displayOffset : 0,
             showPaginator : false,
+            suppressLinkedFields : null, // list of fields whose linked display data should not be fetched from the server
 
             /* by default, don't show auto-generated (sequence) fields */
             showSequenceFields : false, 
@@ -538,7 +539,8 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
             fmClass: this.grid.fmClass,
             fmField: this.field,
             widgetValue : val,
-            readOnly : true
+            readOnly : true,
+            suppressLinkedFields : this.grid.suppressLinkedFields
         });
 
         var _this = this;
index 50f65ac..e44d747 100644 (file)
@@ -25,13 +25,15 @@ function getBalanceInfo(rowIndex, item) {
     return 0;
 }
 
-function loadFundGrid(year) {
-    var yearStore = {identifier:'year', name:'year', items:[]};
-    var yearsAdded = {}; /* don't duplicate the years in the selector */
-    lfGrid.resetStore();
+function initPage() {
+    loadYearSelector();
+    loadFundGrid();
+}
 
-    if(!year) year = new Date().getFullYear().toString();
+function loadFundGrid(year) {
 
+    lfGrid.resetStore();
+    year = year || new Date().getFullYear().toString();
     lfGrid.dataLoader = function() { loadFundGrid(year); };
 
     fieldmapper.standardRequest(
@@ -52,29 +54,40 @@ function loadFundGrid(year) {
                 if(lf = openils.Util.readResponse(r)) {
                    openils.acq.Fund.cache[lf.id()] = lf;
                    lfGrid.store.newItem(acqf.toStoreItem(lf));
-                    var year = lf.year();
-                    if(!(year in yearsAdded)) {
-                        yearStore.items.push({year:year});
-                        yearsAdded[year] = 1;
-                    }
                 }
             },
 
             oncomplete : function(r) {
+                lfGrid.hideLoadProgressIndicator();
+            }
+        }
+    );
+}
+
+function loadYearSelector() {
+
+    fieldmapper.standardRequest(
+        ['open-ils.acq', 'open-ils.acq.fund.org.years.retrieve'],
+        {   async : true,
+            params : [openils.User.authtoken],
+            oncomplete : function(r) {
+
+                var yearList = openils.Util.readResponse(r);
+                if(!yearList) return;
+                yearList = yearList.map(function(year){return {year:year+''};}); // dojo wants strings
+
+                var yearStore = {identifier:'year', name:'year', items:yearList};
                 yearStore.items = yearStore.items.sort().reverse();
                 fundFilterYearSelect.store = new dojo.data.ItemFileReadStore({data:yearStore});
-                var today = new Date().getFullYear().toString();
 
-                if(today in yearsAdded)
-                    fundFilterYearSelect.setValue(today);
-
-                lfGrid.hideLoadProgressIndicator();
+                // default to this year
+                fundFilterYearSelect.setValue(new Date().getFullYear().toString());
 
                 dojo.connect(
                     fundFilterYearSelect, 
                     'onChange', 
                     function() {
-                        loadFundGrid(fundFilterYearSelect.getValue());
+                        loadFundGrid(fundFilterYearSelect.attr('value'));
                     }
                 );
             }
@@ -82,6 +95,5 @@ function loadFundGrid(year) {
     );
 }
 
-
-openils.Util.addOnLoad(loadFundGrid);
+openils.Util.addOnLoad(initPage);