plugged in initial xpath parsing for provider attr defs. fixed some grid height issue...
[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 dojo.require('openils.MarcXPathParser');
6
7
8 var provider;
9 var xpathParser = new openils.MarcXPathParser();
10 var subFields= [];
11
12 function draw() {
13     if(providerId) {
14         openils.Util.addCSSClass(dojo.byId('provider-list-div'), 'hidden');
15         console.log('in draw');
16         var pcrud = new openils.PermaCrud();
17         pcrud.retrieve('acqpro', providerId, {
18                 oncomplete : function(r) {
19                     provider = openils.Util.readResponse(r);
20                     console.log('provider is' + js2JSON(provider));
21                     var pane = new openils.widget.EditPane({fmObject:provider}, dojo.byId('provider-summary-pane'));
22                     pane.startup();
23                     console.log("pane started");
24                     dojo.connect(providerTabs, 'selectChild', drawProviderSummary);                        
25                 }
26  
27             });
28       
29         drawProviderSummary();
30     } else {
31         console.log('in else block');
32         openils.Util.addCSSClass(dojo.byId('provider-details-div'), 'hidden');
33         pListGrid.loadAll({order_by:{acqpro : 'name'}});       
34         pListGrid.onPostCreate = function(fmObject) {
35             location.href = location.href + '/' + fmObject.id();
36         }
37         
38     }
39    
40 }
41 function drawProviderSummary(child) {
42     console.log(child);
43     openils.Util.addCSSClass(dojo.byId('provider-details-div'), 'visible');
44     console.log("hidden provider-details");
45   
46     var loadedTabs = {'provider-address' : true};
47     if(child){   
48         if(loadedTabs[child.id]) return;
49         loadedTabs[child.id] = true;
50         switch(child.id) {
51         case 'tab-pro-contact': 
52             pcListGrid.overrideEditWidgets.provider = new
53                 dijit.form.TextBox({disabled: 'true', value: providerId});
54             openils.Util.removeCSSClass(dojo.byId('contact-addr-div'), 'hidden');
55             pcListGrid.resetStore();
56             pcListGrid.loadAll( {oncomplete:function(r){
57             var count = 0; 
58             pcListGrid.store.fetch( {onComplete:function(list) { 
59                         count =  list.length
60                             if(count>=1){
61                                 var contactIds = [];                           
62                                 dojo.forEach(list, function(item) {
63                                         contactIds.push(pcListGrid.store.getValue(item, 'id')); }
64                                     );
65                                 openils.Util.addCSSClass(dojo.byId('contact-addr-div'), 'visible');
66                                 pcaListGrid.overrideEditWidgets.contact = new
67                                 dijit.form.FilteringSelect({store: pcListGrid.store});
68                                 pcaListGrid.resetStore();
69                                 pcaListGrid.loadAll({order_by:{acqpca : 'contact'}}, {contact: contactIds});
70                             }else{ 
71                                 return;
72                             }            
73                     }
74                 }
75                 );
76                     }
77                 }, {provider : providerId});
78             
79             break;
80         case 'tab-attr': 
81             padListGrid.overrideEditWidgets.provider = new
82                 dijit.form.TextBox({disabled: 'true', value: providerId});
83             padListGrid.resetStore();
84             padListGrid.loadAll({order_by:{acqlipad : 'provider'}}, {provider : providerId});
85             break;
86         case 'tab-hold': 
87             phsListGrid.overrideEditWidgets.provider = new
88                 dijit.form.TextBox({disabled: 'true', value: providerId});
89             phsListGrid.overrideEditWidgets.name = name;
90             phsListGrid.resetStore();
91             phsListGrid.loadAll({order_by:{acqphsm : 'provider'}}, {provider : providerId});
92             break;
93         default:
94             paListGrid.overrideEditWidgets.provider = new
95                 dijit.form.TextBox({disabled: 'true', value: providerId});
96             paListGrid.resetStore();
97             paListGrid.loadAll({order_by:{acqpa:'provider'}}, {provider: providerId}); 
98         }
99         
100     } else {
101         paListGrid.overrideEditWidgets.provider = new
102             dijit.form.TextBox({disabled: 'true', value: providerId});
103         paListGrid.resetStore();
104         paListGrid.loadAll({order_by:{acqpa:'provider'}}, {provider: providerId}); 
105     }
106 }
107
108
109 function getParsedTag(rowIndex, item) {
110     console.log("in getParsedTag");
111     console.log(item);
112     return item && xpathParser.parse(padListGrid.store.getValue(item, 'xpath')).tags;
113 }
114
115
116 function getParsedSubf(rowIndex, item) {
117
118     if(item) {
119         var subfields = xpathParser.parse(padListGrid.store.getValue(item, 'xpath')).subfields;
120         return subfields.join(',');
121     }
122     return'';
123 }
124 openils.Util.addOnLoad(draw);