[open-ils-commits] r9239 - in branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb: public/oils/media/js public/oils/media/js/openils/acq public/oils/media/js/util templates/oils/default/acq/financial

svn at svn.open-ils.org svn at svn.open-ils.org
Sat Apr 5 14:56:19 EDT 2008


Author: erickson
Date: 2008-04-05 14:19:35 -0400 (Sat, 05 Apr 2008)
New Revision: 9239

Added:
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/util/
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/util/Dojo.js
Modified:
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Fund.js
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/FundingSource.js
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Provider.js
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funding_sources.html
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funds.html
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_providers.html
Log:

created a simple grid builder and put it into util.Dojo for global use
simplified the grid column definitions for the simple case




Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Fund.js
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Fund.js	2008-04-05 17:31:23 UTC (rev 9238)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Fund.js	2008-04-05 18:19:35 UTC (rev 9239)
@@ -1,61 +1,40 @@
 if(!dojo._hasResource['openils.acq.Fund']) {
 dojo._hasResource['openils.acq.Fund'] = true;
 dojo.provide('openils.acq.Fund');
+dojo.require('util.Dojo');
 
 /** Declare the Fund class with dojo */
 dojo.declare('openils.acq.Fund', null, {
     /* add instance methods here if necessary */
 });
 
-/* define some static fund methods ------- */
 
-openils.acq.Fund.createFundGrid = function(domId, structure) {
+openils.acq.Fund.loadGrid = function(domId, columns) {
     /** Fetches the list of funds and builds a grid from them */
-    openils.acq.Fund.fetchList(
-        function(funds) {
-            items = [];
-            for(var f in funds) {
-                var fund = funds[f];
-                items.push({
-                    id:fund.id(),
-                    name:fund.name(), 
-                    org: findOrgUnit(fund.org()).name(),
-                    currency_type:fund.currency_type(),
-                    year:fund.year(),
-                    combined_balance:fund.summary()['combined_balance']
-                });
-            }
-            openils.acq.Fund.buildGrid(domId, structure, items);
-        }
-    );
-}
 
-openils.acq.Fund.fetchList = function(callback) {
-    /** Retrieves the list of fund objects that I have permission to view */
     var ses = new OpenSRF.ClientSession('open-ils.acq');
     var req = ses.request('open-ils.acq.fund.org.retrieve', 
         oilsAuthtoken, null, {flesh_summary:1}); /* XXX make this a streaming call */
+
     req.oncomplete = function(r) {
-        callback(r.recv().content());
+        var funds = r.recv().content();
+        var items = [];
+
+        for(var f in funds) {
+            var fund = funds[f];
+
+            items.push({
+                id:fund.id(),
+                name:fund.name(), 
+                org: findOrgUnit(fund.org()).name(),
+                currency_type:fund.currency_type(),
+                year:fund.year(),
+                combined_balance:fund.summary()['combined_balance']
+            });
+        }
+        util.Dojo.buildSimpleGrid(domId, columns, items);
     };
     req.send();
 };
-
-openils.acq.Fund.buildGrid = function(domId, structure, dataList, identifier) {
-    /** Builds a dojo grid based on the provided data.  
-     * @param domId The DOM node where the grid lives 
-     * @param structure The layout of the grid. i.e. colums.
-     * @param dataList List of objects (hashes) to be inserted into the grid.
-     * @paramd identifier The ID field for objects in the grid.  Defaults to 'id'
-     */
-    identifier = (identifier) ? identifier : 'id';
-    var store = new dojo.data.ItemFileWriteStore({data:{identifier:identifier,items:dataList}});
-    var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true});
-    var grid = new dojox.Grid({structure: structure, model: model}, dojo.byId(domId));
-    grid.setModel(model);
-    grid.setStructure(structure);
-    grid.startup();
-    return {grid:grid, store:store, model:model};
-};
 }
 

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/FundingSource.js
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/FundingSource.js	2008-04-05 17:31:23 UTC (rev 9238)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/FundingSource.js	2008-04-05 18:19:35 UTC (rev 9239)
@@ -1,60 +1,38 @@
 if(!dojo._hasResource['openils.acq.FundingSource']) {
 dojo._hasResource['openils.acq.FundingSource'] = true;
 dojo.provide('openils.acq.FundingSource');
+dojo.require('util.Dojo');
 
 /** Declare the FundingSource class with dojo */
 dojo.declare('openils.acq.FundingSource', null, {
     /* add instance methods here if necessary */
 });
 
-/* define some static methods ------- */
-
-openils.acq.FundingSource.createFundingSourceGrid = function(domId, structure) {
+openils.acq.FundingSource.loadGrid = function(domId, columns) {
     /** Fetches the list of funding_sources and builds a grid from them */
-    openils.acq.FundingSource.fetchList(
-        function(srcs) {
-            items = [];
-            for(var f in srcs) {
-                var src = srcs[f];
-                items.push({
-                    id:src.id(),
-                    name:src.name(), 
-                    owner: findOrgUnit(src.owner()).name(),
-                    currency_type:src.currency_type(),
-                    balance:src.summary()['balance']
-                });
-            }
-            openils.acq.FundingSource.buildGrid(domId, structure, items);
-        }
-    );
-}
 
-openils.acq.FundingSource.fetchList = function(callback) {
-    /** Retrieves the list of fund objects that I have permission to view */
     var ses = new OpenSRF.ClientSession('open-ils.acq');
     var req = ses.request('open-ils.acq.funding_source.org.retrieve', 
         oilsAuthtoken, null, {flesh_summary:1}); /* XXX make this a streaming call */
+
     req.oncomplete = function(r) {
-        callback(r.recv().content());
+        srcs = r.recv().content();
+        var items = [];
+
+        for(var f in srcs) {
+            var src = srcs[f];
+            items.push({
+                id:src.id(),
+                name:src.name(), 
+                owner: findOrgUnit(src.owner()).name(),
+                currency_type:src.currency_type(),
+                balance:src.summary()['balance']
+            });
+        }
+
+        util.Dojo.buildSimpleGrid(domId, columns, items);
     };
     req.send();
 };
-
-openils.acq.FundingSource.buildGrid = function(domId, structure, dataList, identifier) {
-    /** Builds a dojo grid based on the provided data.  
-     * @param domId The DOM node where the grid lives 
-     * @param structure The layout of the grid. i.e. colums.
-     * @param dataList List of objects (hashes) to be inserted into the grid.
-     * @paramd identifier The ID field for objects in the grid.  Defaults to 'id'
-     */
-    identifier = (identifier) ? identifier : 'id';
-    var store = new dojo.data.ItemFileWriteStore({data:{identifier:identifier,items:dataList}});
-    var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true});
-    var grid = new dojox.Grid({structure: structure, model: model}, dojo.byId(domId));
-    grid.setModel(model);
-    grid.setStructure(structure);
-    grid.startup();
-    return {grid:grid, store:store, model:model};
-};
 }
 

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Provider.js
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Provider.js	2008-04-05 17:31:23 UTC (rev 9238)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Provider.js	2008-04-05 18:19:35 UTC (rev 9239)
@@ -1,6 +1,7 @@
 if(!dojo._hasResource['openils.acq.Provider']) {
 dojo._hasResource['openils.acq.Provider'] = true;
 dojo.provide('openils.acq.Provider');
+dojo.require('util.Dojo');
 
 /** Declare the Provider class with dojo */
 dojo.declare('openils.acq.Provider', null, {
@@ -9,50 +10,28 @@
 
 /* define some static provider methods ------- */
 
-openils.acq.Provider.createProviderGrid = function(domId, structure) {
+openils.acq.Provider.loadGrid = function(domId, columns) {
     /** Fetches the list of providers and builds a grid from them */
-    openils.acq.Provider.fetchList(
-        function(providers) {
-            items = [];
-            for(var p in providers) {
-                var prov = providers[p];
-                items.push({
-                    id:prov.id(),
-                    name:prov.name(), 
-                    owner: findOrgUnit(prov.owner()).name(),
-                    currency_type:prov.currency_type()
-                });
-            }
-            openils.acq.Provider.buildGrid(domId, structure, items);
-        }
-    );
-}
 
-openils.acq.Provider.fetchList = function(callback) {
-    /** Retrieves the list of provider objects that I have permission to view */
     var ses = new OpenSRF.ClientSession('open-ils.acq');
     var req = ses.request('open-ils.acq.provider.org.retrieve', oilsAuthtoken); /* XXX make this a streaming call */
+
     req.oncomplete = function(r) {
-        callback(r.recv().content());
+        var providers = r.recv().content();
+        var items = [];
+
+        for(var p in providers) {
+            var prov = providers[p];
+            items.push({
+                id:prov.id(),
+                name:prov.name(), 
+                owner: findOrgUnit(prov.owner()).name(),
+                currency_type:prov.currency_type()
+            });
+        }
+        util.Dojo.buildSimpleGrid(domId, columns, items);
     };
     req.send();
 };
-
-openils.acq.Provider.buildGrid = function(domId, structure, dataList, identifier) {
-    /** Builds a dojo grid based on the provided data.  
-     * @param domId The DOM node where the grid lives 
-     * @param structure The layout of the grid. i.e. colums.
-     * @param dataList List of objects (hashes) to be inserted into the grid.
-     * @paramd identifier The ID field for objects in the grid.  Defaults to 'id'
-     */
-    identifier = (identifier) ? identifier : 'id';
-    var store = new dojo.data.ItemFileWriteStore({data:{identifier:identifier,items:dataList}});
-    var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true});
-    var grid = new dojox.Grid({structure: structure, model: model}, dojo.byId(domId));
-    grid.setModel(model);
-    grid.setStructure(structure);
-    grid.startup();
-    return {grid:grid, store:store, model:model};
-};
 }
 

Added: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/util/Dojo.js
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/util/Dojo.js	                        (rev 0)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/util/Dojo.js	2008-04-05 18:19:35 UTC (rev 9239)
@@ -0,0 +1,42 @@
+if(!dojo._hasResource['util.Dojo']) {
+dojo._hasResource['util.Dojo'] = true;
+dojo.provide('util.Dojo');
+
+/**
+ * General purpose Dojo utility functions 
+ */
+
+dojo.declare('util.Dojo', null, {
+    /* add instance methods here if necessary */
+});
+
+
+util.Dojo.buildSimpleGrid = function(domId, columns, dataList, identifier) {
+    /** Builds a dojo grid based on the provided data.  
+     * @param domId The ID of the DOM node where the grid lives.
+     * @param structure List of column header objects.
+     * @param dataList List of objects (hashes) to be inserted into the grid.
+     * @paramd identifier The identifier field for objects in the grid.  Defaults to 'id'
+     */
+    identifier = (identifier) ? identifier : 'id';
+    domNode = dojo.byId(domId);
+
+    var colWidth = (dojo.coords(domNode.parentNode).w / columns.length) - 30;
+    for(var i in columns) {
+        if(columns[i].width == undefined)
+            columns[i].width = colWidth + 'px';
+    }
+
+    layout = [{cells : [columns]}];
+
+    var store = new dojo.data.ItemFileWriteStore({data:{identifier:identifier,items:dataList}});
+    var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true});
+    var grid = new dojox.Grid({structure: layout, model: model}, domId);
+    grid.setModel(model);
+    grid.setStructure(layout);
+    grid.startup();
+
+    return {grid:grid, store:store, model:model};
+};
+}
+

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funding_sources.html
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funding_sources.html	2008-04-05 17:31:23 UTC (rev 9238)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funding_sources.html	2008-04-05 18:19:35 UTC (rev 9239)
@@ -16,18 +16,16 @@
     dojo.require('openils.acq.FundingSource');
 
     /* define the layout columns */
-    var cols = [{   
-        cells : [[
-            {name: '${_("ID")}', field: 'id'},
-            {name: '${_("Name")}', field: "name"}, 
-            {name: '${_("Owner")}', field: "owner"}, 
-            {name: '${_("Currency Type")}', field: "currency_type"},
-            {name: '${_("Balance")}', field: "balance"}
-        ]]
-    }];
+    var cols = [
+        {name: '${_("ID")}', field: 'id'},
+        {name: '${_("Name")}', field: "name"}, 
+        {name: '${_("Owner")}', field: "owner"}, 
+        {name: '${_("Currency Type")}', field: "currency_type"},
+        {name: '${_("Balance")}', field: "balance"}
+    ];
 
     /* build the funding-source grid on page load */
     dojo.addOnLoad(function(){
-        openils.acq.FundingSource.createFundingSourceGrid('oils-acq-funding-source-grid', cols)});
+        openils.acq.FundingSource.loadGrid('oils-acq-funding-source-grid', cols)});
 </script>
 </%def>

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funds.html
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funds.html	2008-04-05 17:31:23 UTC (rev 9238)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funds.html	2008-04-05 18:19:35 UTC (rev 9239)
@@ -16,19 +16,16 @@
     dojo.require('openils.acq.Fund');
 
     /* define the layout columns */
-    var cols = [{   
-        cells : [[
-            {name: '${_("ID")}', field: 'id'},
-            {name: '${_("Name")}', field: "name"}, 
-            {name: '${_("Owner")}', field: "org"}, 
-            {name: '${_("Year")}', field: "year"},
-            {name: '${_("Currency Type")}', field: "currency_type"},
-            {name: '${_("Balance")}', field: "combined_balance"}
-        ]]
-    }];
+    var cols = [
+        {name: '${_("ID")}', field: 'id'},
+        {name: '${_("Name")}', field: "name"}, 
+        {name: '${_("Owner")}', field: "org"}, 
+        {name: '${_("Year")}', field: "year"},
+        {name: '${_("Currency Type")}', field: "currency_type"},
+        {name: '${_("Balance")}', field: "combined_balance"}
+    ];
 
     /* build the fund grid on page load */
-    dojo.addOnLoad(function(){
-        openils.acq.Fund.createFundGrid('oils-acq-fund-grid', cols)});
+    dojo.addOnLoad(function(){openils.acq.Fund.loadGrid('oils-acq-fund-grid', cols)});
 </script>
 </%def>

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_providers.html
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_providers.html	2008-04-05 17:31:23 UTC (rev 9238)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_providers.html	2008-04-05 18:19:35 UTC (rev 9239)
@@ -15,17 +15,14 @@
     dojo.require('openils.acq.Provider');
 
     /* define the layout columns */
-    var cols = [{   
-        cells : [[
-            {name: '${_("ID")}', field: 'id'},
-            {name: '${_("Name")}', field: "name"}, 
-            {name: '${_("Owner")}', field: "owner"}, 
-            {name: '${_("Currency Type")}', field: "currency_type"}
-        ]]
-    }];
+    var cols = [
+        {name: '${_("ID")}', field: 'id'},
+        {name: '${_("Name")}', field: "name"}, 
+        {name: '${_("Owner")}', field: "owner"}, 
+        {name: '${_("Currency Type")}', field: "currency_type"}
+    ];
 
     /* build the provider grid on page load */
-    dojo.addOnLoad(function(){
-        openils.acq.Provider.createProviderGrid('oils-acq-provider-grid', cols)});
+    dojo.addOnLoad(function(){openils.acq.Provider.loadGrid('oils-acq-provider-grid', cols)});
 </script>
 </%def>



More information about the open-ils-commits mailing list