added support for expanding dojo grids. the util.Dojo code will almost certainly...
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 8 Apr 2008 21:36:53 +0000 (21:36 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 8 Apr 2008 21:36:53 +0000 (21:36 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9273 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/FundingSource.js
Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/util/Dojo.js
Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funding_sources.html

index f15312f..26d64f3 100644 (file)
@@ -8,6 +8,8 @@ dojo.declare('openils.acq.FundingSource', null, {
     /* add instance methods here if necessary */
 });
 
+openils.acq.FundingSource.cache = {};
+
 //openils.acq.FundingSource.loadGrid = function(domId, columns, gridBuiltHandler) {
 openils.acq.FundingSource.loadGrid = function(domId, columns) {
     /** Fetches the list of funding_sources and builds a grid from them */
@@ -22,6 +24,7 @@ openils.acq.FundingSource.loadGrid = function(domId, columns) {
         gridRefs.grid.setModel(gridRefs.model);
         while(msg = r.recv()) {
             var src = msg.content();
+            openils.acq.FundingSource.cache[src.id()] = src;
             gridRefs.store.newItem({
                 id:src.id(),
                 name:src.name(), 
@@ -37,6 +40,35 @@ openils.acq.FundingSource.loadGrid = function(domId, columns) {
     return gridRefs.grid;
 };
 
+
+openils.acq.FundingSource.loadGrid = function(grid, model) {
+    /** Fetches the list of funding_sources and builds a grid from them */
+    var ses = new OpenSRF.ClientSession('open-ils.acq');
+    var req = ses.request('open-ils.acq.funding_source.org.retrieve', 
+        oilsAuthtoken, null, {flesh_summary:1});
+
+    req.oncomplete = function(r) {
+        var msg
+        grid.setModel(model);
+        while(msg = r.recv()) {
+            var src = msg.content();
+            openils.acq.FundingSource.cache[src.id()] = src;
+            model.store.newItem({
+                id:src.id(),
+                name:src.name(), 
+                owner: findOrgUnit(src.owner()).name(),
+                currency_type:src.currency_type(),
+                balance:new String(src.summary()['balance'])
+            });
+        }
+        grid.update();
+    };
+
+    req.send();
+};
+
+
+
 /**
  * Create a new funding source object
  * @param fields Key/value pairs used to create the new funding source
index e49cafc..d27e43c 100644 (file)
@@ -45,5 +45,56 @@ util.Dojo.buildSimpleGrid = function(domId, columns, dataList, identifier, delay
 
     return {grid:grid, store:store, model:model};
 };
+
+util.Dojo.expandoGridToggle = function (gridId, inIndex, inShow) {
+    var grid = dijit.byId(gridId);
+    grid.expandedRows[inIndex] = inShow;
+    grid.updateRow(inIndex);
 }
 
+util.Dojo.buildExpandoGrid = function(domId, columns, getSubRowDetail, identColumn) {
+
+    identColumn = (identColumn) ? identColumn : 'id';
+    var grid = new dojox.Grid({}, domId);
+
+    var rowBar = {type: 'dojox.GridRowView', width: '20px' };
+
+    function onBeforeRow(inDataIndex, inRow) {
+        inRow[1].hidden = (!grid.expandedRows || !grid.expandedRows[inDataIndex]);
+    }
+
+    function getCheck(inRowIndex) {
+        var image = (this.grid.expandedRows[inRowIndex]) ? 'open.gif' : 'closed.gif';
+        var show = (this.grid.expandedRows[inRowIndex]) ? 'false' : 'true';
+        return '<img src="/oils/media/js/dojo/dojox/grid/tests/images/' + image + 
+            '" onclick="util.Dojo.expandoGridToggle(\'' + 
+                this.grid.id + '\',' + inRowIndex + ', ' + show + ')" height="11" width="11">';
+    }
+
+    /* XXX i18n name: */
+    columns.unshift({name: 'Details', width: 4.5, get: getCheck, styles: 'text-align: center;' });
+
+    var view = {
+        onBeforeRow: onBeforeRow,
+        cells: [
+            columns,
+            /* XXX i18n name: */
+            [{ name: 'Detail', colSpan: columns.length, get: getSubRowDetail }]
+        ]
+    };
+
+    grid.setStructure([rowBar, view]);
+
+    var store = new dojo.data.ItemFileWriteStore({data:{identifier:identColumn, items:[]}});
+    var model = new dojox.grid.data.DojoData(null, store, {rowsPerPage: 20, clientSort: true});
+    grid.startup();
+    grid.expandedRows = [];
+
+    return {grid:grid, model:model};
+};
+
+}
+
+
+
+
index a9c4368..46402a9 100644 (file)
 <div id='oils-acq-funding-source-grid'> </div>
 
 <script>
-    dojo.require('openils.acq.FundingSource');
-
-    /* define the layout columns */
-    var cols = [
-        {name: '${_("ID")}', field: 'id', 'class':'id-column'},
-        {name: '${_("Name")}', field: "name"}, 
-        {name: '${_("Owner")}', field: "owner"}, 
-        {name: '${_("Currency Type")}', field: "currency_type"},
-        {name: '${_("Balance")}', field: "balance"}
-    ];
+    function loadFSGrid() {
+        dojo.require('openils.acq.FundingSource');
+        var fundingSourceGrid = null;
+    
+        var gridCols = [
+            {name: '${_("ID")}', field: 'id'},
+            {name: '${_("Name")}', field: "name", width:'auto'}, 
+            {name: '${_("Owner")}', field: "owner", width:'auto'}, 
+            {name: '${_("Currency Type")}', field: "currency_type"},
+            {name: '${_("Balance")}', field: "balance"}
+        ];
 
-    /* build the funding-source grid on page load */
-    dojo.addOnLoad(
-        function(){
-            fsGrid = openils.acq.FundingSource.loadGrid('oils-acq-funding-source-grid', cols);
-            fsGrid.onRowClick = function(evt) {
-                /** XXX Need to make this more user friendly / obvious ... */
-                id = fsGrid.model.getDatum(evt.rowIndex, 0);
-                location.href = '${c.oils.acq.prefix.value}/funding_source/view/' + id;
-            };
+        function getSubRowDetail(inRowIndex) {
+            if (fundingSourceGrid.expandedRows[inRowIndex]) {
+                fsId = fundingSourceGrid.model.getDatum(inRowIndex, 0);
+                fs = openils.acq.FundingSource.cache[fsId];
+                return '<b>Viewing grid row for FS: ' + fs.name() + '</b>';
+            } else
+                return '';
         }
-    );
+    
+        var gridRefs = util.Dojo.buildExpandoGrid('oils-acq-funding-source-grid', gridCols, getSubRowDetail);
+        fundingSourceGrid = gridRefs.grid;
+        openils.acq.FundingSource.loadGrid(fundingSourceGrid, gridRefs.model);
+    }
+
+    dojo.addOnLoad(loadFSGrid);
 </script>
+
 </%def>