From 4741e95fb70a0da93777cc6c322df32307273cde Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 8 Apr 2008 21:36:53 +0000 Subject: [PATCH] added support for expanding dojo grids. the util.Dojo code will almost certainly live somewhere else in the repo, but I want to get it down on paper for now... need to flesh out the expanded column for funding_sources git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9273 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../oils/media/js/openils/acq/FundingSource.js | 32 ++++++++++++++ .../oilsweb/public/oils/media/js/util/Dojo.js | 51 ++++++++++++++++++++++ .../acq/financial/list_funding_sources.html | 46 ++++++++++--------- 3 files changed, 109 insertions(+), 20 deletions(-) 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 index f15312f1a9..26d64f3c09 100644 --- 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 @@ -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 diff --git a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/util/Dojo.js b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/util/Dojo.js index e49cafceae..d27e43cb72 100644 --- a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/util/Dojo.js +++ b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/util/Dojo.js @@ -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 ''; + } + + /* 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}; +}; + +} + + + + diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funding_sources.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funding_sources.html index a9c43681f7..46402a9563 100644 --- a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funding_sources.html +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funding_sources.html @@ -75,27 +75,33 @@
+ -- 2.11.0