d6d30563066472f29b08e2ce2710a4be2193c875
[working/Evergreen.git] / Open-ILS / web / js / ui / default / conify / global / acq / provider.js
1 dojo.require('openils.widget.AutoGrid');
2 dojo.require('dijit.form.FilteringSelect');
3 dojo.require('openils.PermaCrud');
4 var provider;
5 var contactIds = [];
6 function draw() {
7     if(providerId) {
8         openils.Util.addCSSClass(dojo.byId('provider-list-div'), 'hidden');
9         drawProviderSummary();
10     } else {
11         openils.Util.addCSSClass(dojo.byId('provider-details-div'), 'hidden');
12         pListGrid.onPostCreate = function(fmObject) {
13             location.href = location.href + '/' + fmObject.id();
14         }
15         pListGrid.loadAll({order_by:{acqpro : 'name'}});
16     }
17 }
18 openils.Util.addOnLoad(draw);
19
20 function drawProviderSummary() {
21     openils.Util.removeCSSClass(dojo.byId('provider-details-div'), 'hidden');
22     var pcrud = new openils.PermaCrud();
23     pcrud.retrieve('acqpro', providerId, {
24         oncomplete : function(r) {
25             provider = openils.Util.readResponse(r);
26             var pane = new openils.widget.EditPane({fmObject:provider}, dojo.byId('provider-summary-pane'));
27             pane.startup();
28
29         }
30     });
31     paListGrid.overrideEditWidgets.provider = new
32         dijit.form.TextBox({style:'display:none', value: providerId});
33     paListGrid.loadAll({order_by:{acqpa : 'provider'}}, {provider : providerId});
34     pcListGrid.overrideEditWidgets.provider = new
35         dijit.form.TextBox({style:'display:none', value: providerId});
36     pcListGrid.loadAll(
37     {
38         order_by:{acqpc : 'name'},
39
40         oncomplete:  function(){
41             pcListGrid.store.fetch({
42                 onComplete: function(items) {
43                     dojo.forEach(items, function(item) {
44                         contactIds.push(pcListGrid.store.getValue(item, 'id')); }
45                     );
46                     console.log("contact IDs are " + js2JSON(contactIds));
47                     pcaListGrid.overrideEditWidgets.contact = new
48                         dijit.form.FilteringSelect({store: pcListGrid.store});
49                     pcaListGrid.loadAll({order_by:{acqpca : 'contact'}}, {contact: contactIds});
50                 }
51             });
52         }
53     }, {provider : providerId});
54 }
55
56 function getProviderName(rowIndex, item) {
57     if(!item) return '';
58     return '<a href="' + location.href + '/' +
59         this.grid.store.getValue(item, 'id') + '">' +
60         this.grid.store.getValue(item, 'name') + '</a>';
61 }
62