abfe064569576c51cac4916936ccbed81fcfb2db
[working/Evergreen.git] / Open-ILS / web / js / ui / default / conify / global / acq / provider.js
1 dojo.require('dijit.layout.TabContainer');
2 dojo.require('openils.widget.AutoGrid');
3 dojo.require('dijit.form.FilteringSelect');
4 dojo.require('openils.PermaCrud');
5 var provider;
6
7 function draw() {
8     if(providerId) {
9         openils.Util.addCSSClass(dojo.byId('provider-list-div'), 'hidden');
10         console.log('in draw');
11         var pcrud = new openils.PermaCrud();
12         pcrud.retrieve('acqpro', providerId, {
13                 oncomplete : function(r) {
14                     provider = openils.Util.readResponse(r);
15                     console.log('provider is' + js2JSON(provider));
16                     var pane = new openils.widget.EditPane({fmObject:provider}, dojo.byId('provider-summary-pane'));
17                     pane.startup();
18                     console.log("pane started");
19                     dojo.connect(providerTabs, 'selectChild', drawProviderSummary);                        
20                 }
21  
22             });
23       
24         drawProviderSummary();
25     } else {
26         console.log('in else block');
27         openils.Util.addCSSClass(dojo.byId('provider-details-div'), 'hidden');
28         pListGrid.loadAll({order_by:{acqpro : 'name'}});       
29         pListGrid.onPostCreate = function(fmObject) {
30             location.href = location.href + '/' + fmObject.id();
31         }
32         
33     }
34    
35 }
36 function drawProviderSummary(child) {
37     console.log(child);
38     openils.Util.addCSSClass(dojo.byId('provider-details-div'), 'visible');
39     console.log("hidden provider-details");
40   
41     var loadedTabs = {'provider-address' : true};
42     if(child){   
43         if(loadedTabs[child.id]) return;
44         loadedTabs[child.id] = true;
45         switch(child.id) {
46         case 'tab-pro-contact': 
47             pcListGrid.overrideEditWidgets.provider = new
48                 dijit.form.TextBox({disabled: 'true', value: providerId});
49             openils.Util.removeCSSClass(dojo.byId('contact-addr-div'), 'hidden');
50             pcListGrid.resetStore();
51             pcListGrid.loadAll( {oncomplete:function(r){
52             var count = 0; 
53             pcListGrid.store.fetch( {onComplete:function(list) { 
54                         count =  list.length
55                             if(count>=1){
56                                 var contactIds = [];                           
57                                 dojo.forEach(list, function(item) {
58                                         contactIds.push(pcListGrid.store.getValue(item, 'id')); }
59                                     );
60                                 openils.Util.addCSSClass(dojo.byId('contact-addr-div'), 'visible');
61                                 pcaListGrid.overrideEditWidgets.contact = new
62                                 dijit.form.FilteringSelect({store: pcListGrid.store});
63                                 pcaListGrid.resetStore();
64                                 pcaListGrid.loadAll({order_by:{acqpca : 'contact'}}, {contact: contactIds});
65                             }else{ 
66                                 return;
67                             }            
68                     }
69                 }
70                 );
71                     }
72                 }, {provider : providerId});
73             
74             break;
75         case 'tab-attr': 
76             padListGrid.overrideEditWidgets.provider = new
77                 dijit.form.TextBox({disabled: 'true', value: providerId});
78             padListGrid.resetStore();
79             padListGrid.loadAll({order_by:{acqlipad : 'provider'}}, {provider : providerId});
80             break;
81         case 'tab-hold': 
82             phsListGrid.overrideEditWidgets.provider = new
83                 dijit.form.TextBox({disabled: 'true', value: providerId});
84             phsListGrid.overrideEditWidgets.name = nameSelect;
85             phsListGrid.resetStore();
86             phsListGrid.loadAll({order_by:{acqphsm : 'provider'}}, {provider : providerId});
87             break;
88         default:
89             paListGrid.overrideEditWidgets.provider = new
90                 dijit.form.TextBox({disabled: 'true', value: providerId});
91             paListGrid.resetStore();
92             paListGrid.loadAll({order_by:{acqpa:'provider'}}, {provider: providerId}); 
93         }
94         
95     } else {
96         paListGrid.overrideEditWidgets.provider = new
97             dijit.form.TextBox({disabled: 'true', value: providerId});
98         paListGrid.resetStore();
99         paListGrid.loadAll({order_by:{acqpa:'provider'}}, {provider: providerId}); 
100     }
101 }
102
103 function getProviderName(rowIndex, item) {
104     if(!item) return '';
105     return '<a href="' + location.href + '/' +
106         this.grid.store.getValue(item, 'id') + '">' +
107         this.grid.store.getValue(item, 'name') + '</a>';
108 }
109
110 openils.Util.addOnLoad(draw);