/* add instance methods here if necessary */
});
+//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 */
+ 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}); /* XXX make this a streaming call */
req.oncomplete = function(r) {
srcs = r.recv().content();
- var items = [];
for(var f in srcs) {
var src = srcs[f];
- items.push({
+ gridRefs.store.newItem({
id:src.id(),
name:src.name(),
owner: findOrgUnit(src.owner()).name(),
});
}
- util.Dojo.buildSimpleGrid(domId, columns, items);
+ /* set the model after loading all of the data */
+ gridRefs.grid.setModel(gridRefs.model);
};
req.send();
+ //return gridRefs;
+ return gridRefs.grid;
};
}
});
-util.Dojo.buildSimpleGrid = function(domId, columns, dataList, identifier) {
+util.Dojo.buildSimpleGrid = function(domId, columns, dataList, identifier, delayed) {
/** Builds a dojo grid based on the provided data.
* @param domId The ID of the DOM node where the grid lives.
* @param structure List of column header objects.
* @param dataList List of objects (hashes) to be inserted into the grid.
- * @paramd identifier The identifier field for objects in the grid. Defaults to 'id'
+ * @param identifier The identifier field for objects in the grid. Defaults to 'id'
+ * @param delayed If true, method returns before the model is linked to the grid.
+ * The purpose of this is to allow the client to fill the grid with data
+ * before rendering to get past dojo grid display bugs
*/
identifier = (identifier) ? identifier : 'id';
domNode = dojo.byId(domId);
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: layout, model: model}, domId);
+ var grid = new dojox.Grid({structure: layout}, domId);
+
+ if(delayed)
+ return {grid:grid, store:store, model:model};
+
grid.setModel(model);
grid.setStructure(layout);
grid.startup();
</div>
<div id='oils-acq-funding-source-grid'> </div>
+
<script>
dojo.require('openils.acq.FundingSource');
/* define the layout columns */
var cols = [
- {name: '${_("ID")}', field: 'id'},
+ {name: '${_("ID")}', field: 'id', 'class':'id-column'},
{name: '${_("Name")}', field: "name"},
{name: '${_("Owner")}', field: "owner"},
{name: '${_("Currency Type")}', field: "currency_type"},
];
/* build the funding-source grid on page load */
- dojo.addOnLoad(function(){
- openils.acq.FundingSource.loadGrid('oils-acq-funding-source-grid', cols)});
+ dojo.addOnLoad(
+ function(){
+ var 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;
+ };
+ }
+ );
</script>
</%def>