[open-ils-commits] SPAM: r9283 - in
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb:
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
Wed Apr 9 15:09:39 EDT 2008
Author: erickson
Date: 2008-04-09 14:32:20 -0400 (Wed, 09 Apr 2008)
New Revision: 9283
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/util/Dojo.js
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funding_sources.html
Log:
now using fieldmapper.dojoData to build the data store for funding sources (thanks, mike). updated version of grid sub-row code. this actually builds a sub-grid on the fly (as an example), but could be extended to support arbitrary dom nodes. needs considerable tidying..
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-09 17:26:19 UTC (rev 9282)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/FundingSource.js 2008-04-09 18:32:20 UTC (rev 9283)
@@ -8,67 +8,32 @@
/* add instance methods here if necessary */
});
+/** cached funding_source objects */
openils.acq.FundingSource.cache = {};
-//openils.acq.FundingSource.loadGrid = function(domId, columns, gridBuiltHandler) {
-openils.acq.FundingSource.loadGrid = function(domId, columns) {
+openils.acq.FundingSource.createStore = function(onComplete) {
/** Fetches the list of funding_sources and builds a grid from them */
-
- var gridRefs = util.Dojo.buildSimpleGrid(domId, columns, [], 'id', true);
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
- gridRefs.grid.setModel(gridRefs.model);
+ var items = [];
+ var src = null;
while(msg = r.recv()) {
- var src = msg.content();
+ src = msg.content();
openils.acq.FundingSource.cache[src.id()] = src;
- gridRefs.store.newItem({
- id:src.id(),
- name:src.name(),
- owner: findOrgUnit(src.owner()).name(),
- currency_type:src.currency_type(),
- balance:new String(src.summary()['balance'])
- });
+ items.push(src);
}
- gridRefs.grid.update();
+ onComplete(acqfs.toStoreData(items));
};
req.send();
- 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
Modified: 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 2008-04-09 17:26:19 UTC (rev 9282)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/util/Dojo.js 2008-04-09 18:32:20 UTC (rev 9283)
@@ -52,13 +52,14 @@
grid.updateRow(inIndex);
}
-util.Dojo.buildExpandoGrid = function(domId, columns, getSubRowDetail, identColumn) {
+/**
+ * Constructs an expandable dojox.Grid
+ * @param getSubRowDetail called when the sub-row is expanded. Should return HTML
+ */
+util.Dojo.buildExpandoGrid = function(domId, columns, getSubRowDetail) {
- 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]);
}
@@ -66,6 +67,7 @@
function getCheck(inRowIndex) {
var image = (this.grid.expandedRows[inRowIndex]) ? 'open.gif' : 'closed.gif';
var show = (this.grid.expandedRows[inRowIndex]) ? 'false' : 'true';
+ /* XXX JS var for JS root */
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">';
@@ -78,19 +80,15 @@
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};
+ return grid;
};
}
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-09 17:26:19 UTC (rev 9282)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funding_sources.html 2008-04-09 18:32:20 UTC (rev 9283)
@@ -6,11 +6,6 @@
<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>
- </div>
- -->
</div>
<script>var fsGrid = null;</script>
@@ -34,79 +29,165 @@
</script>
<div class='oils-acq-actions-div'>
-<div dojoType="dijit.form.DropDownButton">
- <span>${('New Funding Source')}</span>
- <div dojoType="dijit.TooltipDialog" execute="createFS(arguments[0]);">
- <table class='dijitTooltipTable'>
- <tr>
- <td><label for="name">${_('Name:')} </label></td>
- <td><input dojoType="dijit.form.TextBox" name="name"></td>
- </tr>
- <tr>
- <td><label for="loc">${_('Owning Location:')} </label></td>
- <td>
- <select name="owner" dojoType="dijit.form.FilteringSelect" autocomplete="false" >
- <!-- XXX get orgs from DB... -->
- <option value='2'>SYS1</option>
- <option value='3'>SYS2</option>
- <option value='7'>BR4</option>
- </select>
- </td>
- </tr>
- <tr>
- <td><label for="currency_type">${_('Currency Type:')}</label></td>
- <td>
- <select name="currency_type" dojoType="dijit.form.FilteringSelect" autocomplete="false" >
- <!-- XXX get-currency-types from DB... -->
- <option value='CAN'>CAN</option>
- <option value='EUR'>EUR</option>
- <option value='USD'>USD</option>
- </select>
- </td>
- </tr>
- <tr>
- <td colspan='2' align='center'>
- <button dojoType=dijit.form.Button type="submit">${_('Create')}</button>
- </td>
- </tr>
- </table>
- </div>
-</div>
+ <div dojoType="dijit.form.DropDownButton">
+ <span>${('New Funding Source')}</span>
+ <div dojoType="dijit.TooltipDialog" execute="createFS(arguments[0]);">
+ <table class='dijitTooltipTable'>
+ <tr>
+ <td><label for="name">${_('Name:')} </label></td>
+ <td><input dojoType="dijit.form.TextBox" name="name"></td>
+ </tr>
+ <tr>
+ <td><label for="loc">${_('Owning Location:')} </label></td>
+ <td>
+ <select name="owner" dojoType="dijit.form.FilteringSelect" autocomplete="false" >
+ <!-- XXX get orgs from DB... -->
+ <option value='2'>SYS1</option>
+ <option value='3'>SYS2</option>
+ <option value='7'>BR4</option>
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td><label for="currency_type">${_('Currency Type:')}</label></td>
+ <td>
+ <select name="currency_type" dojoType="dijit.form.FilteringSelect" autocomplete="false" >
+ <!-- XXX get-currency-types from DB... -->
+ <option value='CAN'>CAN</option>
+ <option value='EUR'>EUR</option>
+ <option value='USD'>USD</option>
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td colspan='2' align='center'>
+ <button dojoType=dijit.form.Button type="submit">${_('Create')}</button>
+ </td>
+ </tr>
+ </table>
+ </div>
+ </div>
-<button dojoType="dijit.form.Button"
- onclick="openils.acq.FundingSource.deleteFromGrid(fundingSourceGrid, function(){location.href = location.href})">
- ${_('Delete Selected')}
-</button>
-
+ <button dojoType="dijit.form.Button"
+ onclick="openils.acq.FundingSource.deleteFromGrid(fundingSourceGrid, function(){location.href = location.href})">
+ ${_('Delete Selected')}
+ </button>
</div>
+<!-- The actual grid lives here -->
<div id='oils-acq-funding-source-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);
+ if(!data) return;
+ return findOrgUnit(data.owner).name(); /* XXX show shortname by default, but needs fetching */
+ }
+
+ function getBalanceInfo(rowIndex) {
+ data = fundingSourceGrid.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'},
+ {name: '${_("Owner")}', field: "owner", width:'auto', get:getOrgInfo},
{name: '${_("Currency Type")}', field: "currency_type"},
- {name: '${_("Balance")}', field: "balance"}
+ {name: '${_("Balance")}', field: "balance", get:getBalanceInfo}
];
- 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 subGridCells = [{
+ noscroll: true,
+ cells: [[
+ {name: "Total Credit"},
+ {name: "Total Allocation"},
+ {name: "Actions", width:'auto'}
+ ]]
+ }];
+
+ 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);
+ }
}
-
- var gridRefs = util.Dojo.buildExpandoGrid('oils-acq-funding-source-grid', gridCols, getSubRowDetail);
- fundingSourceGrid = gridRefs.grid;
- openils.acq.FundingSource.loadGrid(fundingSourceGrid, gridRefs.model);
+
+ // 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();
+ }
+ );
}
dojo.addOnLoad(loadFSGrid);
More information about the open-ils-commits
mailing list