added support to autogrid for loading paged data via callback for UIs that load their...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 16 Aug 2009 15:49:12 +0000 (15:49 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 16 Aug 2009 15:49:12 +0000 (15:49 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@13843 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 2ac090f..4c843f4 100644 (file)
@@ -286,19 +286,31 @@ __PACKAGE__->register_method(
 );
 
 sub retrieve_org_funds {
-    my($self, $conn, $auth, $org_id_list, $options) = @_;
+    my($self, $conn, $auth, $filter, $options) = @_;
     my $e = new_editor(authtoken=>$auth);
     return $e->event unless $e->checkauth;
+    $filter ||= {};
     $options ||= {};
 
     my $limit_perm = ($$options{limit_perm}) ? $$options{limit_perm} : 'ADMIN_FUND';
     return OpenILS::Event->new('BAD_PARAMS') 
         unless $limit_perm =~ /(ADMIN|MANAGE|VIEW)_FUND/;
 
-    my $org_ids = ($org_id_list and @$org_id_list) ? $org_id_list :
+    $filter->{org}  = $filter->{org} || 
         $U->user_has_work_perm_at($e, $limit_perm, {descendants =>1});
-    return undef unless @$org_ids;
-    my $funds = $e->search_acq_fund({org => $org_ids});
+    return undef unless @{$filter->{org}};
+
+
+    my $query = [
+        $filter,
+        {
+            limit => $$options{limit} || 50,
+            offset => $$options{offset} || 0,
+            order_by => $$options{order_by} || {acqf => 'name'}
+        }
+    ];
+
+    my $funds = $e->search_acq_fund($query);
 
     for my $fund (@$funds) {
         $fund->summary(retrieve_fund_summary_impl($e, $fund))
index 3e84505..f903d7a 100644 (file)
@@ -38,6 +38,7 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
                 this.initAutoEnv();
                 this.attr('structure', this._compileStructure());
                 this.setStore(this.buildAutoStore());
+                this.cachedQueryOpts = {};
 
                 if(this.showColumnPicker) {
                     if(!this.columnPickerPrefix) {
@@ -82,7 +83,10 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
                         onclick : function() { 
                             self.resetStore();
                             self.cachedQueryOpts.offset = self.displayOffset -= self.displayLimit;
-                            self.loadAll(self.cachedQueryOpts, self.cachedQuerySearch);
+                            if(self.dataLoader)
+                                self.dataLoader()
+                            else
+                                self.loadAll(self.cachedQueryOpts, self.cachedQuerySearch);
                         }
                     });
 
@@ -93,7 +97,10 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
                         onclick : function() { 
                             self.resetStore();
                             self.cachedQueryOpts.offset = self.displayOffset += self.displayLimit;
-                            self.loadAll(self.cachedQueryOpts, self.cachedQuerySearch);
+                            if(self.dataLoader)
+                                self.dataLoader()
+                            else
+                                self.loadAll(self.cachedQueryOpts, self.cachedQuerySearch);
                         }
                     });
 
@@ -108,6 +115,14 @@ if(!dojo._hasResource['openils.widget.AutoGrid']) {
                 }
             },
 
+            hideLoadProgressIndicator : function() {
+                dojo.style(this.loadProgressIndicator, 'visibility', 'hidden');
+            },
+
+            showLoadProgressIndicator : function() {
+                dojo.style(this.loadProgressIndicator, 'visibility', 'visible');
+            },
+
             /* Don't allow sorting on the selector column */
             canSort : function(rowIdx) {
                 if(rowIdx == 1 && !this.hideSelector)
index 947756f..50f65ac 100644 (file)
@@ -25,14 +25,29 @@ function getBalanceInfo(rowIndex, item) {
     return 0;
 }
 
-function loadFundGrid() {
+function loadFundGrid(year) {
     var yearStore = {identifier:'year', name:'year', items:[]};
     var yearsAdded = {}; /* don't duplicate the years in the selector */
+    lfGrid.resetStore();
+
+    if(!year) year = new Date().getFullYear().toString();
+
+    lfGrid.dataLoader = function() { loadFundGrid(year); };
 
     fieldmapper.standardRequest(
        [ 'open-ils.acq', 'open-ils.acq.fund.org.retrieve'],
        {    async: true,
-            params: [openils.User.authtoken, null, {flesh_summary:1}],
+
+            params: [
+                openils.User.authtoken, 
+                {year:year}, 
+                {
+                    flesh_summary:1, 
+                    limit: lfGrid.displayLimit,
+                    offset: lfGrid.displayOffset
+                }
+            ],
+
             onresponse : function(r) {
                 if(lf = openils.Util.readResponse(r)) {
                    openils.acq.Fund.cache[lf.id()] = lf;
@@ -44,28 +59,29 @@ function loadFundGrid() {
                     }
                 }
             },
+
             oncomplete : function(r) {
-                // sort the unique list of years and set the selector to "now" if possible
                 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();
+
+                dojo.connect(
+                    fundFilterYearSelect, 
+                    'onChange', 
+                    function() {
+                        loadFundGrid(fundFilterYearSelect.getValue());
+                    }
+                );
             }
         }
     );
 }
 
-function filterGrid() {
-    var year = fundFilterYearSelect.getValue();
-    console.log(year);
-    if(year) 
-        lfGrid.setQuery({year:year});
-    else
-        lfGrid.setQuery({id:'*'});
-    
-    lfGrid.update();
-}
 
 openils.Util.addOnLoad(loadFundGrid);
 
index 7041744..1d2c483 100644 (file)
@@ -3,45 +3,18 @@
 <!-- load the page-specific JS -->
 <script src='[% ctx.media_prefix %]/js/ui/default/acq/financial/list_funds.js'> </script>
 
-<script type="text/javascript">
-    function createFund(fields) {
-        /** Creates a new fund source */
-        openils.acq.Fund.create(
-            fields,
-            function(fundId) {
-                var evt = openils.Event.parse(fundId);
-                if(evt) {
-                    alert(evt); /* XXX */
-                    return;
-                } else {
-                    location.href =  /* go to the details page for this fund */
-                    '[% ctx.base_path %]/acq/fund/view/'+fundId;
-                }
-            }
-        );
-    }
-
-    function getName(rowIndex, item) {
-        if(!item) return;
-        var name = this.grid.store.getValue(item, 'name');
-        var id = this.grid.store.getValue(item, 'id');
-        return '<a href="[% ctx.base_path %]/acq/fund/view/'+id+'">'+name+'</a>';
-    }
-</script>
-
-
-<div class='oils-header-panel' dojoType="dijit.layout.ContentPane" layoutAlign="client">
-    <div>Funds</div>
-    <div>
-        <button dojoType='dijit.form.Button' onClick='lfGrid.showCreateDialog()'>New Fund</button>
-        <button dojoType='dijit.form.Button' onClick='lfGrid.deleteSelected()'>Delete Selected</button>
-    </div>
-</div>
-
-<div dojoType="dijit.layout.ContentPane" layoutAlign="client">
-    Year <select dojoType='dijit.form.FilteringSelect' onchange='filterGrid();'
-        jsId='fundFilterYearSelect' labelAttr='year' searchAttr='year'> </select>
-</div>
+<table style='width:100%;'>
+    <tr>
+        <!-- TODO CSS -->
+        <td style='text-align:left;font-size:130%;font-weight: bold;'>Funds</td>
+        <td style='text-align:right;width:90%;'>
+            Year <select dojoType='dijit.form.FilteringSelect'
+                jsId='fundFilterYearSelect' labelAttr='year' searchAttr='year'> </select>
+            <button dojoType='dijit.form.Button' onClick='lfGrid.showCreateDialog()'>New Fund</button>
+            <button dojoType='dijit.form.Button' onClick='lfGrid.deleteSelected()'>Delete Selected</button>
+        </td>
+    </tr>
+</table>
 
 <div dojoType="dijit.layout.ContentPane" layoutAlign="client">
     <table  jsId="lfGrid"
@@ -51,6 +24,7 @@
             query="{id: '*'}"
             defaultCellWidth='"auto"'
             fmClass='acqf'
+            showPaginator='true'
             editOnEnter='true'>
         <thead>
             <tr>