moved fund and funding_source list pages to grids
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 5 Apr 2008 17:31:23 +0000 (17:31 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sat, 5 Apr 2008 17:31:23 +0000 (17:31 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9238 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/oilsweb/oilsweb/controllers/acq/fund.py
Open-ILS/web/oilsweb/oilsweb/controllers/acq/funding_source.py
Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Fund.js [new file with mode: 0644]
Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/FundingSource.js [new file with mode: 0644]
Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funding_sources.html
Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funds.html

index 2c2d705..857a226 100644 (file)
@@ -38,17 +38,7 @@ class FundController(BaseController):
         return r.render('acq/financial/view_fund.html')
 
     def list(self):
-        r = RequestMgr()
-        ses = ClientSession(oils.const.OILS_APP_ACQ)
-        funds = ses.request(
-            'open-ils.acq.fund.org.retrieve', 
-            r.ctx.core.authtoken.value, None, {"flesh_summary":1}).recv().content()
-        Event.parse_and_raise(funds)
-        for f in funds:
-            f.org(OrgUtil.get_org_unit(f.org()))
-        r.ctx.acq.fund_list.value = funds
-        return r.render('acq/financial/list_funds.html')
-            
+        return RequestMgr().render('acq/financial/list_funds.html')
 
     def create(self):
         r = RequestMgr()
index 79de9b4..ec9e1b4 100644 (file)
@@ -26,20 +26,7 @@ class FundingSourceController(BaseController):
         return r.render('acq/financial/view_funding_source.html')
 
     def list(self):
-        r = RequestMgr()
-        ses = ClientSession(oils.const.OILS_APP_ACQ)
-
-        sources = ses.request(
-            'open-ils.acq.funding_source.org.retrieve', 
-            r.ctx.core.authtoken.value, None, {"flesh_summary":1}).recv().content()
-
-        Event.parse_and_raise(sources)
-        r.ctx.acq.funding_source_list.value = sources
-
-        for source in sources:
-            source.owner(OrgUtil.get_org_unit(source.owner()))
-        return r.render('acq/financial/list_funding_sources.html')
-            
+        return RequestMgr().render('acq/financial/list_funding_sources.html')
 
     def create(self):
         r = RequestMgr()
diff --git a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Fund.js b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Fund.js
new file mode 100644 (file)
index 0000000..bbdde67
--- /dev/null
@@ -0,0 +1,61 @@
+if(!dojo._hasResource['openils.acq.Fund']) {
+dojo._hasResource['openils.acq.Fund'] = true;
+dojo.provide('openils.acq.Fund');
+
+/** 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) {
+    /** 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());
+    };
+    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};
+};
+}
+
diff --git a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/FundingSource.js b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/FundingSource.js
new file mode 100644 (file)
index 0000000..bd887b6
--- /dev/null
@@ -0,0 +1,60 @@
+if(!dojo._hasResource['openils.acq.FundingSource']) {
+dojo._hasResource['openils.acq.FundingSource'] = true;
+dojo.provide('openils.acq.FundingSource');
+
+/** 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) {
+    /** 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());
+    };
+    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};
+};
+}
+
index e496c75..8c2060c 100644 (file)
@@ -7,29 +7,27 @@
 <div id='oils-acq-list-header' class='container'>
     <div id='oils-acq-list-header-label'>${_('Funding Sources')}</div>
     <div id='oils-acq-list-header-actions'>
-        <a href='${c.oils.acq.prefix.value}/funding_source/create'>${_('New Funding Source')}</a>
+        <a href='${c.oils.acq.prefix.value}/funding-sourceing_source/create'>${_('New Funding Source')}</a>
     </div>
 </div>
 
+<div id='oils-acq-funding-source-grid'> </div>
+<script>
+    dojo.require('openils.acq.FundingSource');
 
-<table class='oils-admin-table'>
-    <thead>
-        <tr>
-            <td>${_('Funding Source Name')}</td>
-            <td>${_('Funding Source Owner')}</td>
-            <td>${_('Funding Source Currency Type')}</td>
-            <td>${_('Funding Source Balance')}</td>
-        </tr>
-    </thead>
-    <tbody>
-        % for source in c.oils.acq.funding_source_list.value:
-        <tr>
-            <td><a href='${c.oils.acq.prefix.value}/funding_source/view/${source.id()}'>${source.name()}</a></td>
-            <td>${source.owner().name()}</td> 
-            <td>${source.currency_type()}</td> 
-            <td>${source.summary()['balance']}</td> 
-        </tr>
-        %endfor
-    </tbody>
-</table>
+    /* 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"}
+        ]]
+    }];
+
+    /* build the funding-source grid on page load */
+    dojo.addOnLoad(function(){
+        openils.acq.FundingSource.createFundingSourceGrid('oils-acq-funding-source-grid', cols)});
+</script>
 </%def>
index ec1ae65..e186133 100644 (file)
     </div>
 </div>
 
+<div id='oils-acq-fund-grid'> </div>
+<script>
+    dojo.require('openils.acq.Fund');
 
-<table class='oils-admin-table'>
-    <thead>
-        <tr>
-            <td>${_('Fund Name')}</td>
-            <td>${_('Fund Owner')}</td>
-            <td>${_('Fund Year')}</td>
-            <td>${_('Fund Balance')}</td>
-        </tr>
-    </thead>
-    <tbody>
-        % for fund in c.oils.acq.fund_list.value:
-        <tr>
-            <td><a href='${c.oils.acq.prefix.value}/fund/view/${fund.id()}'>${fund.name()}</a></td>
-            <td>${fund.org().name()}</td> 
-            <td>${fund.year()}</td> 
-            <td>${fund.summary()['combined_balance']}</td> 
-        </tr>
-        %endfor
-    </tbody>
-</table>
+    /* 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"}
+        ]]
+    }];
+
+    /* build the fund grid on page load */
+    dojo.addOnLoad(function(){
+        openils.acq.Fund.createFundGrid('oils-acq-fund-grid', cols)});
+</script>
 </%def>