| 14 | | <div id='oils-acq-fund-grid'> </div> |
| | 10 | <script type="text/javascript"> |
| | 11 | dojo.require("dijit.Dialog"); |
| | 12 | dojo.require("dijit.form.FilteringSelect"); |
| | 13 | dojo.require('openils.acq.Fund'); |
| | 14 | dojo.require('openils.Event'); |
| | 15 | dojo.require('openils.acq.CurrencyType'); |
| | 16 | dojo.require('openils.widget.OrgUnitFilteringSelect'); |
| | 17 | |
| | 18 | function createFund(fields) { |
| | 19 | /** Creates a new fund source */ |
| | 20 | openils.acq.Fund.create( |
| | 21 | fields, |
| | 22 | function(fundId) { |
| | 23 | var evt = openils.Event.parse(fundId); |
| | 24 | if(evt) { |
| | 25 | alert(evt); /* XXX */ |
| | 26 | return; |
| | 27 | } else { |
| | 28 | location.href = /* go to the details page for this fund */ |
| | 29 | '${c.oils.acq.prefix.value}/fund/view/'+fundId; |
| | 30 | } |
| | 31 | } |
| | 32 | ); |
| | 33 | } |
| | 34 | </script> |
| | 35 | |
| | 36 | <div class='oils-acq-actions-div'> |
| | 37 | <div dojoType="dijit.form.DropDownButton"> |
| | 38 | <span>${('New Fund')}</span> |
| | 39 | |
| | 40 | <div dojoType="dijit.TooltipDialog" execute="createFund(arguments[0]);"> |
| | 41 | <script type='dojo/connect' event='onOpen'> |
| | 42 | openils.acq.CurrencyType.loadSelectWidget(fundCurrencySelector); |
| | 43 | openils.User.buildPermOrgSelector('ADMIN_FUND', fundOwnerSelect); |
| | 44 | </script> |
| | 45 | |
| | 46 | <table class='dijitTooltipTable'> |
| | 47 | <tr> |
| | 48 | <td><label for="name">${_('Name:')} </label></td> |
| | 49 | <td><input dojoType="dijit.form.TextBox" name="name"></td> |
| | 50 | </tr> |
| | 51 | <tr> |
| | 52 | <td><label for="year">${_('Year:')} </label></td> |
| | 53 | <td><input dojoType="dijit.form.TextBox" name="year"></td> |
| | 54 | </tr> |
| | 55 | <tr> |
| | 56 | <td><label for="currency_type">${_('Currency Type:')}</label></td> |
| | 57 | <td> |
| | 58 | <input jsId='fundCurrencySelector' name="currency_type" |
| | 59 | dojoType="dijit.form.FilteringSelect" searchAttr='code' labelAttr='code'> |
| | 60 | </input> |
| | 61 | </td> |
| | 62 | </tr> |
| | 63 | <tr> |
| | 64 | <td valign='top'><label for="org">${_('Owning Location:')}</label></td> |
| | 65 | <td> |
| | 66 | <input dojoType="openils.widget.OrgUnitFilteringSelect" jsId='fundOwnerSelect' |
| | 67 | searchAttr="shortname" name="org" autocomplete="true" labelAttr='shortname'> </input> |
| | 68 | </td> |
| | 69 | </tr> |
| | 70 | <tr> |
| | 71 | <td colspan='2' align='center'> |
| | 72 | <button dojoType=dijit.form.Button type="submit">${_('Create')}</button> |
| | 73 | </td> |
| | 74 | </tr> |
| | 75 | </table> |
| | 76 | </div> |
| | 77 | </div> |
| | 78 | |
| | 79 | <button dojoType="dijit.form.Button" |
| | 80 | onclick="openils.acq.Fund.deleteFromGrid( |
| | 81 | fundListGrid, function(){location.href = location.href})"> |
| | 82 | ${_('Delete Selected')} |
| | 83 | </button> |
| | 84 | </div> |
| | 85 | |
| | 86 | <!-- The main grid lives here --> |
| | 87 | <div jsId='fundListGrid' dojoType="dojox.Grid"></div> |
| | 88 | |
| 18 | | /* define the layout columns */ |
| 19 | | var cols = [ |
| 20 | | {name: '${_("ID")}', field: 'id'}, |
| 21 | | {name: '${_("Name")}', field: "name"}, |
| 22 | | {name: '${_("Owner")}', field: "org"}, |
| 23 | | {name: '${_("Year")}', field: "year"}, |
| 24 | | {name: '${_("Currency Type")}', field: "currency_type"}, |
| 25 | | {name: '${_("Balance")}', field: "combined_balance"} |
| 26 | | ]; |
| | 91 | function loadFundGrid() { |
| | 92 | openils.User.getBySession(); |
| 28 | | /* build the fund grid on page load */ |
| 29 | | dojo.addOnLoad(function(){openils.acq.Fund.loadGrid('oils-acq-fund-grid', cols)}); |
| | 94 | /** define how the primary grid is rendered */ |
| | 95 | |
| | 96 | function getOrgInfo(rowIndex) { |
| | 97 | data = fundListGrid.model.getRow(rowIndex); |
| | 98 | if(!data) return; |
| | 99 | return fieldmapper.aou.findOrgUnit(data.org).shortname(); |
| | 100 | } |
| | 101 | |
| | 102 | function getBalanceInfo(rowIndex) { |
| | 103 | data = fundListGrid.model.getRow(rowIndex); |
| | 104 | if(!data) return; |
| | 105 | return new String(openils.acq.Fund.cache[data.id].summary().combined_balance); |
| | 106 | } |
| | 107 | |
| | 108 | function getName(rowIndex) { |
| | 109 | data = fundListGrid.model.getRow(rowIndex); |
| | 110 | if(!data) return; |
| | 111 | return '<a href="${c.oils.acq.prefix.value}/fund/view/'+data.id+'">'+data.name+'</a>'; |
| | 112 | } |
| | 113 | |
| | 114 | var gridStructure = [{ |
| | 115 | cells : [[ |
| | 116 | {name: '${_("ID")}', field: 'id'}, |
| | 117 | {name: '${_("Name")}', width:'auto', get:getName}, |
| | 118 | {name: '${_("Year")}', field: "year"}, |
| | 119 | {name: '${_("Location")}', get:getOrgInfo}, |
| | 120 | {name: '${_("Currency Type")}', field: "currency_type"}, |
| | 121 | {name: '${_("Combined Balance")}', get:getBalanceInfo} |
| | 122 | ]] |
| | 123 | }]; |
| | 124 | |
| | 125 | openils.acq.Fund.createStore( |
| | 126 | function(storeData) { |
| | 127 | var store = new dojo.data.ItemFileReadStore({data:storeData}); |
| | 128 | var model = new dojox.grid.data.DojoData(null, store, |
| | 129 | {rowsPerPage: 20, clientSort: true, query:{id:'*'}}); |
| | 130 | fundListGrid.setStructure(gridStructure); |
| | 131 | fundListGrid.setModel(model); |
| | 132 | fundListGrid.update(); |
| | 133 | } |
| | 134 | ); |
| | 135 | } |
| | 136 | |
| | 137 | dojo.addOnLoad(loadFundGrid); |