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

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Apr 11 18:05:36 EDT 2008


Author: erickson
Date: 2008-04-11 17:28:00 -0400 (Fri, 11 Apr 2008)
New Revision: 9315

Modified:
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq/funding_source.py
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/FundingSource.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/view_funding_source.html
Log:
funding source list page is now a basic grid with some actions along the top.  select a funding source, it takes to the details page, where you get a breakdown of credits and allocations.

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq/funding_source.py
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq/funding_source.py	2008-04-11 18:14:13 UTC (rev 9314)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq/funding_source.py	2008-04-11 21:28:00 UTC (rev 9315)
@@ -13,16 +13,7 @@
 
     def view(self, **kwargs):
         r = RequestMgr()
-        ses = ClientSession(oils.const.OILS_APP_ACQ)
-        r.ctx.core.org_tree.value = OrgUtil.fetch_org_tree()
-
-        source = ses.request(
-            'open-ils.acq.funding_source.retrieve', 
-            r.ctx.core.authtoken.value, kwargs.get('id'), {"flesh_summary":1}).recv().content()
-        Event.parse_and_raise(source)
-
-        source.owner(OrgUtil.get_org_unit(source.owner())) # flesh the owner
-        r.ctx.acq.funding_source.value = source
+        r.ctx.acq.funding_source_id = kwargs['id']
         return r.render('acq/financial/view_funding_source.html')
 
     def list(self):

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-11 18:14:13 UTC (rev 9314)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/FundingSource.js	2008-04-11 21:28:00 UTC (rev 9315)
@@ -50,14 +50,33 @@
     req.oncomplete = function(r) {
         var msg = r.recv();
         var id = msg.content();
-        fs.id(id); /* XXX check for event */
         if(onCreateComplete)
-            onCreateComplete(fs);
+            onCreateComplete(id);
     };
     req.send();
 };
 
 
+openils.acq.FundingSource.createCredit = function(fields, onCreateComplete) {
+
+    var fsc = new acqfscred()
+    for(var field in fields) 
+        fsc[field](fields[field]);
+
+    var ses = new OpenSRF.ClientSession('open-ils.acq');
+    var req = ses.request(
+        'open-ils.acq.funding_source_credit.create', oilsAuthtoken, fsc);
+
+    req.oncomplete = function(r) {
+        var msg = r.recv();
+        var id = msg.content();
+        if(onCreateComplete)
+            onCreateComplete(id);
+    };
+    req.send();
+};
+
+
 openils.acq.FundingSource.deleteFromGrid = function(grid, onComplete) {
     var list = []
     var selected = grid.selection.getSelected();
@@ -73,8 +92,11 @@
 openils.acq.FundingSource._deleteList = function(list, idx, onComplete) {
     if(idx >= list.length)    
         return onComplete();
+
     var ses = new OpenSRF.ClientSession('open-ils.acq');
     var req = ses.request('open-ils.acq.funding_source.delete', oilsAuthtoken, list[idx]);
+    delete openils.acq.FundingSource.cache[list[idx]];
+
     req.oncomplete = function(r) {
         msg = r.recv()
         stat = msg.content();

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-11 18:14:13 UTC (rev 9314)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funding_sources.html	2008-04-11 21:28:00 UTC (rev 9315)
@@ -8,21 +8,17 @@
     <div id='oils-acq-list-header-label'>${_('Funding Sources')}</div>
 </div>
 
-<script>var fsGrid = null;</script>
-
-
 <script type="text/javascript">
     dojo.require("dijit.Dialog");
     dojo.require("dijit.form.FilteringSelect");
-    
-    /** Creates a new funding source */
+    dojo.require('openils.acq.FundingSource');
     function createFS(fields) {
+        /** Creates a new funding source */
         openils.acq.FundingSource.create(
             fields, 
             function(fsId) {
-                /** The grid won't update after it's been drawn, 
-                    at least not in FF, so refresh the page... */
-                location.href = location.href;
+                location.href =  /* go to the details page for this fs */
+                    '${c.oils.acq.prefix.value}/funding_source/view/'+fsId;
             }
         );
     }
@@ -69,123 +65,54 @@
     </div> 
 
     <button dojoType="dijit.form.Button" 
-            onclick="openils.acq.FundingSource.deleteFromGrid(fundingSourceGrid, function(){location.href = location.href})">
+            onclick="openils.acq.FundingSource.deleteFromGrid(
+                fundingSourceListGrid, function(){location.href = location.href})">
         ${_('Delete Selected')}
     </button>
 </div>
 
 <!-- The actual grid lives here -->
-<div id='oils-acq-funding-source-grid'> </div>
+<div id="oils-acq-funding-source-list-grid" jsId='fundingSourceListGrid' dojoType="dojox.Grid"></div>
 
 <script>
-    var fundingSourceGrid = null;
 
     function loadFSGrid() {
-        dojo.require('openils.acq.FundingSource');
 
-        function getDetailData(rowIndex) {
-            var fsId = fundingSourceGrid.model.getRow(this.grid.myDataRow).id;
-            var fs = openils.acq.FundingSource.cache[fsId];
-            switch(this.index) {
-                case 0:
-                    return fs.summary().credit_total;
-                case 1:
-                    return fs.summary().allocation_total;
-                }
-        }
-
         function getOrgInfo(rowIndex) {
-            data = fundingSourceGrid.model.getRow(rowIndex);
+            data = fundingSourceListGrid.model.getRow(rowIndex);
             if(!data) return;
             return findOrgUnit(data.owner).name(); /* XXX show shortname by default, but needs fetching */
         }
 
         function getBalanceInfo(rowIndex) {
-            data = fundingSourceGrid.model.getRow(rowIndex);
+            data = fundingSourceListGrid.model.getRow(rowIndex);
             if(!data) return;
             return new String(openils.acq.FundingSource.cache[data.id].summary().balance);
         }
-    
-        var gridCols = [
-            {name: '${_("ID")}', field: 'id'},
-            {name: '${_("Name")}', field: "name", width:'auto'}, 
-            {name: '${_("Owner")}', field: "owner", width:'auto', get:getOrgInfo}, 
-            {name: '${_("Currency Type")}', field: "currency_type"},
-            {name: '${_("Balance")}', field: "balance", get:getBalanceInfo}
-        ];
 
-        var subGridCells = [{
-            noscroll: true,
-            cells: [[
-                {name: "Total Credit"}, 
-                {name: "Total Allocation"}, 
-                {name: "Actions", width:'auto'}
+        function getName(rowIndex) {
+            data = fundingSourceListGrid.model.getRow(rowIndex);
+            if(!data) return;
+            return '<a href="${c.oils.acq.prefix.value}/funding_source/view/'+data.id+'">'+data.name+'</a>';
+        }
+    
+        var gridStructure = [{
+            cells : [[
+                {name: '${_("ID")}', field: 'id'},
+                {name: '${_("Name")}', field: "name", width:'auto', get:getName}, 
+                {name: '${_("Owner")}', field: "owner", width:'auto', get:getOrgInfo}, 
+                {name: '${_("Currency Type")}', field: "currency_type"},
+                {name: '${_("Balance")}', field: "balance", get:getBalanceInfo}
             ]]
         }];
 
-        var subGridProps = {
-            structure: subGridCells, 
-            rowCount: 1, 
-            autoHeight: true, 
-            autoRender: false,
-            "get": getDetailData
-        };
-
-
-        function buildSubgrid(inRowIndex, inCell) {
-            var n = inCell.getNode(inRowIndex).firstChild;
-            var id = makeSubgridId(inRowIndex);
-            var subGrid = dijit.byId(id);
-            if (subGrid) {
-                n.appendChild(subGrid.domNode);
-            } else {
-                subGridProps.widgetId = id;
-                subGrid = new dojox.VirtualGrid(subGridProps, n);
-                subGrid.myDataRow = inRowIndex;
-            }
-            if (subGrid) {
-                subGrid.render();
-                subGrid.cacheHeight = subGrid.domNode.offsetHeight;
-                inCell.grid.rowHeightChanged(inRowIndex);
-            }
-        }
-
-        // identify subgrids by their row indices
-        function makeSubgridId(inRowIndex) {
-            return "fundingSourceGrid_subGrid_" + inRowIndex;
-        }
-
-        // if a subgrid exists at inRowIndex, detach it from the DOM
-        function detachSubgrid(inRowIndex) {
-            var subGrid = dijit.byId(makeSubgridId(inRowIndex));
-            if (subGrid)
-                dojox.grid.removeNode(subGrid.domNode);
-        }
-
-        // provide html for the Detail cell in the master grid
-        function getDetail(inRowIndex) {
-            var cell = this;
-            setTimeout(function() { buildSubgrid(inRowIndex, cell); }, 1);
-            var subGrid = dijit.byId(makeSubgridId(inRowIndex));
-            var h = (subGrid ? subGrid.cacheHeight : "120") + "px";
-            return '<div></div>';
-        }
-
-        // destroy subgrid at inRowIndex
-        function destroySubgrid(inRowIndex) {
-            var subGrid = dijit.byId(makeSubgridId(inRowIndex));
-            if (subGrid) subGrid.destroy();
-        }
-
-        fundingSourceGrid = util.Dojo.buildExpandoGrid(
-            'oils-acq-funding-source-grid', gridCols, getDetail);
-
         openils.acq.FundingSource.createStore(
             function(storeData) {
                 var store = new dojo.data.ItemFileWriteStore({data:storeData});
-                var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true});
-                fundingSourceGrid.setModel(model);
-                fundingSourceGrid.update();
+                var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
+                fundingSourceListGrid.setStructure(gridStructure);
+                fundingSourceListGrid.setModel(model);
+                fundingSourceListGrid.update();
             }
         );
     }

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_funding_source.html
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_funding_source.html	2008-04-11 18:14:13 UTC (rev 9314)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/view_funding_source.html	2008-04-11 21:28:00 UTC (rev 9315)
@@ -4,37 +4,190 @@
 <%def name="page_title()">${_('View Funding Source')}</%def>
 <%def name="block_content()">
 
-<% source = c.oils.acq.funding_source.value %>
+<script>
+    dojo.require("dijit.Dialog");
+    dojo.require('dijit.layout.TabContainer');
+    dojo.require('dijit.layout.ContentPane');
+    dojo.require("dijit.form.FilteringSelect");
+    dojo.require("dijit.form.Textarea");
+    dojo.require("dijit.form.CurrencyTextBox");
+    dojo.require('openils.acq.FundingSource');
+    
+    var fundingSourceID = ${c.oils.acq.funding_source_id};
+    var fundingSource = null;
 
+    /** creates a new funding_source_credit from the dialog ----- */
+    function applyFSCredit(fields) {
+        fields.funding_source = fundingSourceID;
+        openils.acq.FundingSource.createCredit(
+            fields, 
+            function(fscId) {
+                location.href = location.href;
+            }
+        );
+    }
+
+    /** fetch the fleshed funding source ----- */
+    function loadFS() {
+        var ses = new OpenSRF.ClientSession('open-ils.acq');
+        var req = ses.request(
+            'open-ils.acq.funding_source.retrieve',
+            oilsAuthtoken, 
+            fundingSourceID, 
+            {flesh_summary:1, flesh_credits:1,flesh_allocations:1}
+        );
+
+        req.oncomplete = function(r) {
+            var msg = req.recv();
+            fundingSource = msg.content();
+            loadFSGrid();
+        }
+        req.send();
+    }
+
+    /** Some grid rendering accessor functions ----- */
+    function getOrgInfo(rowIndex) {
+        data = fundingSourceGrid.model.getRow(rowIndex);
+        if(!data) return;
+        return findOrgUnit(data.owner).name(); /* XXX show shortname by default, but needs fetching */
+    }
+
+    function getSummaryInfo(rowIndex) {
+        switch(this.index) {
+            case 2: return new String(fundingSource.summary().balance);
+            case 3: return new String(fundingSource.summary().credit_total);
+            case 4: return new String(fundingSource.summary().allocation_total);
+        }
+    }
+
+    /** builds the credits grid ----- */
+    function loadFSGrid() {
+        var store = new dojo.data.ItemFileReadStore({data:acqfs.toStoreData([fundingSource])});
+        var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
+        model.query = {id:'*'};
+        fundingSourceGrid.setModel(model);
+        fundingSourceGrid.update();
+    }
+
+
+    /** builds the credits grid ----- */
+    function loadCreditGrid() {
+        if(fsCreditGrid.isLoaded) return;
+        var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fundingSource.credits())});
+        var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
+        fsCreditGrid.setModel(model);
+        fsCreditGrid.update();
+        fsCreditGrid.isLoaded = true;
+    }
+
+    /** builds the credits grid ----- */
+    function loadAllocationGrid() {
+        if(fsAllocationGrid.isLoaded) return;
+        var store = new dojo.data.ItemFileReadStore({data:acqfa.toStoreData(fundingSource.allocations())});
+        var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true, query:{id:'*'}});
+        fsAllocationGrid.setModel(model);
+        fsAllocationGrid.update();
+        fsAllocationGrid.isLoaded = true;
+    }
+
+    dojo.addOnLoad(loadFS);
+</script>
+
+
+
 <div id='oils-acq-list-header' class='container'>
-    <div id='oils-acq-list-header-label'>${source.name()}</div>
-    <div id='oils-acq-list-header-actions'>
-        <a href='${c.oils.acq.prefix.value}/funding_source/create_credit?${c.oils.acq.funding_source_id.cgi_name}=${source.id()}'>${_('Add Credit')}</a>
+    <div id='oils-acq-list-header-label'>${_('Funding Source Details')}</div>
+</div>
+
+<div class='oils-acq-actions-div' style='margin:8px;'> <!-- XXX CSS -->
+
+    <!-- Dropdown menu for creating a new funding source credit -->
+    <div dojoType="dijit.form.DropDownButton">
+        <span>${('Apply Credit')}</span>
+        <div dojoType="dijit.TooltipDialog" execute="applyFSCredit(arguments[0]);">
+            <table class='dijitTooltipTable'>
+                <tr>
+                    <td><label for="amount">${_('Amount:')} </label></td>
+                    <td>
+                        <!-- XXX get currency from from funding source ... -->
+                        <input dojoType="dijit.form.CurrencyTextBox" name="amount" currency='USD'> </input>
+                    </td>
+                </tr>
+                <tr>
+                    <td><label for="note">${_('Note:')} </label></td>
+                    <td>
+                        <input dojoType="dijit.form.TextBox" name="note"> </input>
+                        <!-- XXX textarea makes more sense, but it's buggy in the dropdown dialog .. perhaps a height issue?
+                        <textarea dojoType='dijit.form.Textarea' name="note" style='min-height:6em'> 
+                        </textarea>
+                        -->
+                    </td>
+                </tr>
+                <tr>
+                    <td colspan='2' align='center'>
+                        <button dojoType=dijit.form.Button type="submit">${_('Apply')}</button>
+                    </td>
+                </tr>
+            </table>
+        </div>
+    </div> 
+</div>
+
+<style>
+    .oils-acq-detail-content-pane {height:500px;width:100%}
+</style>
+
+<div dojoType="dijit.layout.ContentPane" layoutAlign="top">
+    <div dojoType="dijit.layout.TabContainer">
+        <div dojoType="dijit.layout.ContentPane" class='oils-acq-detail-content-pane' title="${_('Summary')}" selected='true'>
+            <script>
+                /** Define the columns for the funding source grid ----- */
+                var fundingSourceGridLayout = [{
+                    cells : [[
+                        {name: '${_("ID")}', field: 'id'},
+                        {name: '${_("Name")}', field: "name", width:'auto'}, 
+                        {name: '${_("Balance")}', get:getSummaryInfo},
+                        {name: '${_("Total Credits")}', get:getSummaryInfo},
+                        {name: '${_("Total Debits")}', get:getSummaryInfo},
+                        {name: '${_("Currency Type")}', field: "currency_type"},
+                        {name: '${_("Owner")}', field: "owner", width:'auto', get:getOrgInfo}, 
+                    ]]
+                }];
+            </script>
+            <div jsId='fundingSourceGrid' dojoType="dojox.Grid" structure='fundingSourceGridLayout'> </div>
+        </div>
+        <div dojoType="dijit.layout.ContentPane" class='oils-acq-detail-content-pane' title="${_('Credits')}">
+            <script type='dojo/connect' event='onShow'>loadCreditGrid();</script>
+            <script>
+                /** Define the columns for the funding source credits grid ----- */
+                var fsCreditGridLayout = [{
+                    cells : [[
+                        {name: '${_("ID")}', field: 'id'},
+                        {name: '${_("Amount")}', field: "amount"}, 
+                        {name: '${_("Note")}', field: "note", width:'auto'}, 
+                    ]]
+                }];
+            </script>
+            <div jsId='fsCreditGrid' dojoType="dojox.Grid" structure='fsCreditGridLayout'> </div>
+        </div>
+        <div dojoType="dijit.layout.ContentPane" class='oils-acq-detail-content-pane' title="${_('Allocations')}">
+            <script type='dojo/connect' event='onShow'>loadAllocationGrid();</script>
+            <script>
+                /** Define the columns for the funding source allocations grid ----- */
+                var fsAllocationGridLayout = [{
+                    cells : [[
+                        {name: '${_("ID")}', field: 'id'},
+                        {name: '${_("Fund")}', field: "fund"}, 
+                        {name: '${_("Amount")}', field: "amount"}, 
+                        {name: '${_("Percent")}', field: "percent"}, 
+                        {name: '${_("Allocated By")}', field: "allocator"}, 
+                        {name: '${_("Note")}', field: "note", width:'auto'}, 
+                    ]]
+                }];
+            </script>
+            <div jsId='fsAllocationGrid' dojoType="dojox.Grid" structure='fsAllocationGridLayout'> </div>
+        </div>
     </div>
 </div>
 
-<table class='oils-admin-table'>
-    <tbody>
-        <tr>
-            <td class='oils-admin-label'>${_('Funding Source Owner')}</td>
-            <td>${source.owner().name()}</td> 
-        </tr>
-        <tr>
-            <td class='oils-admin-label'>${_('Funding Source Currency Type')}</td>
-            <td>${source.currency_type()}</td> 
-        </tr>
-        <tr>
-            <td class='oils-admin-label'>${_('Funding Source Credit Total')}</td>
-            <td>${source.summary()['credit_total']}</td> 
-        </tr>
-        <tr>
-            <td class='oils-admin-label'>${_('Funding Source Allocation Total')}</td>
-            <td>${source.summary()['allocation_total']}</td> 
-        </tr>
-        <tr>
-            <td class='oils-admin-label'>${_('Funding Source Balance')}</td>
-            <td>${source.summary()['balance']}</td> 
-        </tr>
-    </tbody>
-</table>
 </%def>



More information about the open-ils-commits mailing list