From: erickson Date: Sat, 5 Apr 2008 18:19:35 +0000 (+0000) Subject: created a simple grid builder and put it into util.Dojo for global use X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=eb04f3e950636f9c6a41afceec18fd0a8b4cce3a;p=Evergreen.git created a simple grid builder and put it into util.Dojo for global use simplified the grid column definitions for the simple case git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9239 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Fund.js b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Fund.js index bbdde67669..e49f74438c 100644 --- a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Fund.js +++ b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Fund.js @@ -1,61 +1,40 @@ if(!dojo._hasResource['openils.acq.Fund']) { dojo._hasResource['openils.acq.Fund'] = true; dojo.provide('openils.acq.Fund'); +dojo.require('util.Dojo'); /** Declare the Fund class with dojo */ dojo.declare('openils.acq.Fund', null, { /* add instance methods here if necessary */ }); -/* define some static fund methods ------- */ -openils.acq.Fund.createFundGrid = function(domId, structure) { +openils.acq.Fund.loadGrid = function(domId, columns) { /** Fetches the list of funds and builds a grid from them */ - openils.acq.Fund.fetchList( - function(funds) { - items = []; - for(var f in funds) { - var fund = funds[f]; - items.push({ - id:fund.id(), - name:fund.name(), - org: findOrgUnit(fund.org()).name(), - currency_type:fund.currency_type(), - year:fund.year(), - combined_balance:fund.summary()['combined_balance'] - }); - } - openils.acq.Fund.buildGrid(domId, structure, items); - } - ); -} -openils.acq.Fund.fetchList = function(callback) { - /** Retrieves the list of fund objects that I have permission to view */ var ses = new OpenSRF.ClientSession('open-ils.acq'); var req = ses.request('open-ils.acq.fund.org.retrieve', oilsAuthtoken, null, {flesh_summary:1}); /* XXX make this a streaming call */ + req.oncomplete = function(r) { - callback(r.recv().content()); + var funds = r.recv().content(); + var items = []; + + for(var f in funds) { + var fund = funds[f]; + + items.push({ + id:fund.id(), + name:fund.name(), + org: findOrgUnit(fund.org()).name(), + currency_type:fund.currency_type(), + year:fund.year(), + combined_balance:fund.summary()['combined_balance'] + }); + } + util.Dojo.buildSimpleGrid(domId, columns, items); }; req.send(); }; - -openils.acq.Fund.buildGrid = function(domId, structure, dataList, identifier) { - /** Builds a dojo grid based on the provided data. - * @param domId The DOM node where the grid lives - * @param structure The layout of the grid. i.e. colums. - * @param dataList List of objects (hashes) to be inserted into the grid. - * @paramd identifier The ID field for objects in the grid. Defaults to 'id' - */ - identifier = (identifier) ? identifier : 'id'; - 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: structure, model: model}, dojo.byId(domId)); - grid.setModel(model); - grid.setStructure(structure); - grid.startup(); - return {grid:grid, store:store, model:model}; -}; } 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 bd887b6e25..094f507c88 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 @@ -1,60 +1,38 @@ if(!dojo._hasResource['openils.acq.FundingSource']) { dojo._hasResource['openils.acq.FundingSource'] = true; dojo.provide('openils.acq.FundingSource'); +dojo.require('util.Dojo'); /** Declare the FundingSource class with dojo */ dojo.declare('openils.acq.FundingSource', null, { /* add instance methods here if necessary */ }); -/* define some static methods ------- */ - -openils.acq.FundingSource.createFundingSourceGrid = function(domId, structure) { +openils.acq.FundingSource.loadGrid = function(domId, columns) { /** Fetches the list of funding_sources and builds a grid from them */ - openils.acq.FundingSource.fetchList( - function(srcs) { - items = []; - for(var f in srcs) { - var src = srcs[f]; - items.push({ - id:src.id(), - name:src.name(), - owner: findOrgUnit(src.owner()).name(), - currency_type:src.currency_type(), - balance:src.summary()['balance'] - }); - } - openils.acq.FundingSource.buildGrid(domId, structure, items); - } - ); -} -openils.acq.FundingSource.fetchList = function(callback) { - /** Retrieves the list of fund objects that I have permission to view */ 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) { - callback(r.recv().content()); + srcs = r.recv().content(); + var items = []; + + for(var f in srcs) { + var src = srcs[f]; + items.push({ + id:src.id(), + name:src.name(), + owner: findOrgUnit(src.owner()).name(), + currency_type:src.currency_type(), + balance:src.summary()['balance'] + }); + } + + util.Dojo.buildSimpleGrid(domId, columns, items); }; req.send(); }; - -openils.acq.FundingSource.buildGrid = function(domId, structure, dataList, identifier) { - /** Builds a dojo grid based on the provided data. - * @param domId The DOM node where the grid lives - * @param structure The layout of the grid. i.e. colums. - * @param dataList List of objects (hashes) to be inserted into the grid. - * @paramd identifier The ID field for objects in the grid. Defaults to 'id' - */ - identifier = (identifier) ? identifier : 'id'; - 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: structure, model: model}, dojo.byId(domId)); - grid.setModel(model); - grid.setStructure(structure); - grid.startup(); - return {grid:grid, store:store, model:model}; -}; } diff --git a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Provider.js b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Provider.js index bc23948165..669ba9ad94 100644 --- a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Provider.js +++ b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/openils/acq/Provider.js @@ -1,6 +1,7 @@ if(!dojo._hasResource['openils.acq.Provider']) { dojo._hasResource['openils.acq.Provider'] = true; dojo.provide('openils.acq.Provider'); +dojo.require('util.Dojo'); /** Declare the Provider class with dojo */ dojo.declare('openils.acq.Provider', null, { @@ -9,50 +10,28 @@ dojo.declare('openils.acq.Provider', null, { /* define some static provider methods ------- */ -openils.acq.Provider.createProviderGrid = function(domId, structure) { +openils.acq.Provider.loadGrid = function(domId, columns) { /** Fetches the list of providers and builds a grid from them */ - openils.acq.Provider.fetchList( - function(providers) { - items = []; - for(var p in providers) { - var prov = providers[p]; - items.push({ - id:prov.id(), - name:prov.name(), - owner: findOrgUnit(prov.owner()).name(), - currency_type:prov.currency_type() - }); - } - openils.acq.Provider.buildGrid(domId, structure, items); - } - ); -} -openils.acq.Provider.fetchList = function(callback) { - /** Retrieves the list of provider objects that I have permission to view */ var ses = new OpenSRF.ClientSession('open-ils.acq'); var req = ses.request('open-ils.acq.provider.org.retrieve', oilsAuthtoken); /* XXX make this a streaming call */ + req.oncomplete = function(r) { - callback(r.recv().content()); + var providers = r.recv().content(); + var items = []; + + for(var p in providers) { + var prov = providers[p]; + items.push({ + id:prov.id(), + name:prov.name(), + owner: findOrgUnit(prov.owner()).name(), + currency_type:prov.currency_type() + }); + } + util.Dojo.buildSimpleGrid(domId, columns, items); }; req.send(); }; - -openils.acq.Provider.buildGrid = function(domId, structure, dataList, identifier) { - /** Builds a dojo grid based on the provided data. - * @param domId The DOM node where the grid lives - * @param structure The layout of the grid. i.e. colums. - * @param dataList List of objects (hashes) to be inserted into the grid. - * @paramd identifier The ID field for objects in the grid. Defaults to 'id' - */ - identifier = (identifier) ? identifier : 'id'; - 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: structure, model: model}, dojo.byId(domId)); - grid.setModel(model); - grid.setStructure(structure); - grid.startup(); - return {grid:grid, store:store, model:model}; -}; } 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 new file mode 100644 index 0000000000..90afcbacb8 --- /dev/null +++ b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/js/util/Dojo.js @@ -0,0 +1,42 @@ +if(!dojo._hasResource['util.Dojo']) { +dojo._hasResource['util.Dojo'] = true; +dojo.provide('util.Dojo'); + +/** + * General purpose Dojo utility functions + */ + +dojo.declare('util.Dojo', null, { + /* add instance methods here if necessary */ +}); + + +util.Dojo.buildSimpleGrid = function(domId, columns, dataList, identifier) { + /** 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' + */ + identifier = (identifier) ? identifier : 'id'; + domNode = dojo.byId(domId); + + var colWidth = (dojo.coords(domNode.parentNode).w / columns.length) - 30; + for(var i in columns) { + if(columns[i].width == undefined) + columns[i].width = colWidth + 'px'; + } + + layout = [{cells : [columns]}]; + + 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); + grid.setModel(model); + grid.setStructure(layout); + grid.startup(); + + return {grid:grid, store:store, 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 8c2060c066..760864f189 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 @@ -16,18 +16,16 @@ dojo.require('openils.acq.FundingSource'); /* define the layout columns */ - var cols = [{ - cells : [[ - {name: '${_("ID")}', field: 'id'}, - {name: '${_("Name")}', field: "name"}, - {name: '${_("Owner")}', field: "owner"}, - {name: '${_("Currency Type")}', field: "currency_type"}, - {name: '${_("Balance")}', field: "balance"} - ]] - }]; + var cols = [ + {name: '${_("ID")}', field: 'id'}, + {name: '${_("Name")}', field: "name"}, + {name: '${_("Owner")}', field: "owner"}, + {name: '${_("Currency Type")}', field: "currency_type"}, + {name: '${_("Balance")}', field: "balance"} + ]; /* build the funding-source grid on page load */ dojo.addOnLoad(function(){ - openils.acq.FundingSource.createFundingSourceGrid('oils-acq-funding-source-grid', cols)}); + openils.acq.FundingSource.loadGrid('oils-acq-funding-source-grid', cols)}); diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funds.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funds.html index e186133028..860aae5f93 100644 --- a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funds.html +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_funds.html @@ -16,19 +16,16 @@ dojo.require('openils.acq.Fund'); /* define the layout columns */ - var cols = [{ - cells : [[ - {name: '${_("ID")}', field: 'id'}, - {name: '${_("Name")}', field: "name"}, - {name: '${_("Owner")}', field: "org"}, - {name: '${_("Year")}', field: "year"}, - {name: '${_("Currency Type")}', field: "currency_type"}, - {name: '${_("Balance")}', field: "combined_balance"} - ]] - }]; + var cols = [ + {name: '${_("ID")}', field: 'id'}, + {name: '${_("Name")}', field: "name"}, + {name: '${_("Owner")}', field: "org"}, + {name: '${_("Year")}', field: "year"}, + {name: '${_("Currency Type")}', field: "currency_type"}, + {name: '${_("Balance")}', field: "combined_balance"} + ]; /* build the fund grid on page load */ - dojo.addOnLoad(function(){ - openils.acq.Fund.createFundGrid('oils-acq-fund-grid', cols)}); + dojo.addOnLoad(function(){openils.acq.Fund.loadGrid('oils-acq-fund-grid', cols)}); diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_providers.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_providers.html index 800e567490..19b7acd790 100644 --- a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_providers.html +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/financial/list_providers.html @@ -15,17 +15,14 @@ dojo.require('openils.acq.Provider'); /* define the layout columns */ - var cols = [{ - cells : [[ - {name: '${_("ID")}', field: 'id'}, - {name: '${_("Name")}', field: "name"}, - {name: '${_("Owner")}', field: "owner"}, - {name: '${_("Currency Type")}', field: "currency_type"} - ]] - }]; + var cols = [ + {name: '${_("ID")}', field: 'id'}, + {name: '${_("Name")}', field: "name"}, + {name: '${_("Owner")}', field: "owner"}, + {name: '${_("Currency Type")}', field: "currency_type"} + ]; /* build the provider grid on page load */ - dojo.addOnLoad(function(){ - openils.acq.Provider.createProviderGrid('oils-acq-provider-grid', cols)}); + dojo.addOnLoad(function(){openils.acq.Provider.loadGrid('oils-acq-provider-grid', cols)});