grid getter fixes for 1.3
[working/Evergreen.git] / Open-ILS / web / js / ui / default / conify / global / acq / distribution_formula.js
1 dojo.require('openils.widget.AutoGrid');
2 dojo.require('dijit.form.FilteringSelect');
3 dojo.require('openils.PermaCrud');
4 var formula;
5 var formCache = [];
6
7 function draw() {
8
9     if(formulaId) {
10         openils.Util.hide('formula-list-div');
11         drawFormulaSummary();
12     } else {
13
14         openils.Util.hide('formula-entry-div');
15         fListGrid.onPostCreate = function(fmObject) {
16             location.href = location.href + '/' + fmObject.id();
17         }
18
19         fieldmapper.standardRequest(
20             ['open-ils.acq', 'open-ils.acq.distribution_formula.ranged.retrieve'],
21             {   async: true,
22                 params: [openils.User.authtoken],
23                 onresponse: function (r) { 
24                     var form = openils.Util.readResponse(r);
25                     formCache[form.id()] = form;
26                     fListGrid.store.newItem(form.toStoreItem());
27                 }
28             }
29         );
30
31     }
32 }
33 openils.Util.addOnLoad(draw);
34
35 function drawFormulaSummary() {
36     openils.Util.show('formula-entry-div');
37     dfeListGrid.overrideEditWidgets.formula = new
38         dijit.form.TextBox({style:'display:none', value: formulaId});
39     dfeListGrid.loadAll({order_by:{acqdfe : 'formula'}}, {formula : formulaId});
40     var pcrud = new openils.PermaCrud;
41     var formulaName = pcrud.retrieve('acqdf', formulaId);
42     dojo.byId('formula_head').innerHTML = formulaName.name();
43 }
44
45 function getItemCount(rowIndex, item) {
46     if(!item) return '';
47     var form = formCache[this.grid.store.getValue(item, "id")];
48     if(!form) return 0;
49     var count = 0;
50     dojo.forEach(form.entries(), function(e) { count = count + e.item_count(); });
51     return count;
52 }
53