ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MRovere/ReferenceWebGUI/uploadWindow_UI.js
Revision: 1.4
Committed: Tue May 18 09:33:52 2010 UTC (14 years, 11 months ago) by rovere
Content type: application/javascript
Branch: MAIN
CVS Tags: JSON-release-pp-2012Nov23, JSON-release-pp-20121026, HEAD
Changes since 1.3: +180 -293 lines
Error occurred while calculating annotation data.
Log Message:
* browseWindow_UI.js, dbsCombo_UI.js, goodForRun_UI.js,
localTagCombo_UI.js, subSysCombo_UI.js, uploadWindow_UI.js,
xmlTextArea_UI.js: All the logic of the connections between the
component of the window has been moved the the new Event Manager.
Minor stylish changes.

File Contents

# Content
1 Ext.ns('uploadWindow_UI');
2
3 Ext.BLANK_IMAGE_URL = '/ext/resources/images/default/s.gif';
4
5 uploadWindow_UI.Window = Ext.extend(
6 Ext.Window,
7 {
8 constructor:function(config)
9 {
10 // hard coded config - cannot be changed from outside
11 var cfg =
12 {
13 items:{ xtype:'form',
14 id: 'newRecordFormId',
15 frame:true,
16 defaults:{anchor:'-10'},
17 fileUpload: true,
18 items:[{ xtype: 'dbscombo',
19 noCache: false,
20 consoleLog: false},
21 { xtype: 'localtagcombo',
22 noCache:true,
23 consoleLog: false,
24 forceSelection:false
25 },
26 { xtype:'subsyscombo',
27 noCache: true,
28 consoleLog: false,
29 forceSelection: false},
30 { xtype:'goodforrunUI',
31 fieldLabel: 'Since',
32 buttonLabel: 'First Available',
33 id: 'since'},
34 { xtype: 'xmlTextAreaUI',
35 consoleLog:false,
36 parentForm: 'newRecordFormId',
37 grow: false}]},
38 buttons:[{ text: 'Commit',
39 handler: this.commit,
40 scope: this},
41 { text: 'Close',
42 handler: function(){window.location.href = '.';}}], // oe buttons items
43 height: 'auto'
44 }; // eo config
45 // apply config
46 config = Ext.apply(cfg, config) ;
47
48 //call parent
49 uploadWindow_UI.Window.superclass.constructor.call(this, config);
50 if(this.consoleLog)
51 console.log('uploadWindow_UI.Window constructor called');
52 } // eo function constructor
53
54 ,consoleLog:false
55 // The next function MUST be called as a callback
56 // method of the show method. This is so because
57 // I need to refer to some components that are not there after the window rendered
58 // but are there only after the window is shown (the button
59 // for the goodRun new widget
60 ,setConnections:function()
61 {
62 if(this.consoleLog)
63 console.log('uploadWindow_UI.setConnections called') ;
64
65 this.loadMask = new Ext.LoadMask(Ext.getBody(), {msg:'Working...<br/>Please wait.'});
66
67 // Install proper hooks to main windows components that have to communicate
68 // each others.
69 // We put them here because they already exists in the HTML document
70 var dbIndex = this.items.itemAt(0).items.findIndex('xtype', 'dbscombo') ;
71 this.db = this.items.itemAt(0).items.itemAt(dbIndex);
72 if(this.consoleLog)
73 console.log('uploadWindow_UI.onRender the Database cmp should be ', this.db) ;
74
75 var tagsIndex = this.items.itemAt(0).items.findIndex('xtype', 'localtagcombo') ;
76 this.tags = this.items.itemAt(0).items.itemAt(tagsIndex);
77 if(this.consoleLog)
78 console.log('uploadWindow_UI.onRender the local tags cmp should be ', this.tags) ;
79
80 var subsysIndex = this.items.itemAt(0).items.findIndex('xtype', 'subsyscombo') ;
81 this.subsystems = this.items.itemAt(0).items.itemAt(subsysIndex);
82 if(this.consoleLog)
83 console.log('uploadWindow_UI.onRender the subsystems cmp should be ', this.subsystems) ;
84
85 var sinceIndex = this.items.itemAt(0).items.findIndex('fieldLabel', 'Since') ;
86 this.since = this.items.itemAt(0).items.itemAt(sinceIndex);
87 if(this.consoleLog)
88 console.log('uploadWindow_UI.onRender the since cmp should be ', this.since) ;
89
90 var xmlUI = this.items.itemAt(0).items.findIndex('xtype', 'xmlTextAreaUI') ;
91 this.xmlTextArea = this.items.itemAt(0).items.itemAt(xmlUI);
92 this.loadFromPreviousBtn = this.items.itemAt(0).items.itemAt(xmlUI).loadFromPreviousButton;
93 if(this.consoleLog)
94 console.log('uploadWindow_UI.onRender the loadFromPrevious should be ', this.loadFromPreviousBtn) ;
95
96 var goodrunIndex = this.items.itemAt(0).items.findIndex('xtype', 'goodforrunUI') ;
97 this.goodRun = this.items.itemAt(0).items.itemAt(goodrunIndex);
98 if(this.consoleLog)
99 console.log('browseWindow_UI.onRender the main GoodRun cmp should be ', this.goodRun) ;
100
101 // install communication between components using event handlers!!!!
102 MyApp.eventManager.on('selectedDB', function(value)
103 { this.subsystems.store.setBaseParam('dbname', value);
104 this.tags.store.setBaseParam('dbname', value);
105 this.tags.clearValue();
106 this.subsystems.clearValue();
107 this.since.setValue('') ;}, this);
108 // LOAD FROM PREVIOUS BUTTON BEHAVIOUR
109 this.loadFromPreviousBtn.on(
110 { scope: this,
111 click:function(btn, event){
112 if (this.consoleLog)
113 console.log('RefuploadForm loadFromPreviousBtn fired a click event');
114 if (this.checkForm() ==0){
115 this.loadMask.show() ;
116 Ext.Ajax.request({ url : '/cgi-bin/ReferencePythonCLI/driver.py',
117 method : 'post',
118 params : { action: 'getPreviousXML',
119 dbname: this.db.getValue(),
120 localtag: this.tags.getValue(),
121 subsystem: this.subsystems.getValue(),
122 specificRun: this.since.getValue()},
123 success: function(response, request){ this.loadMask.hide() ;
124 var obj = Ext.util.JSON.decode(response.responseText);
125 if (obj.rows.length > 0) {
126 this.xmlTextArea.setValue(Base64.decode(obj.rows[0].XML));
127 if(this.consoleLog)
128 console.log('uploadForm: setting xmlTextArea.validated to true');
129 this.xmlTextArea.validated = true ;
130 } else { Ext.Msg.show({ title: 'Error',
131 msg: 'No data Available',
132 icon: Ext.MessageBox.INFO,
133 buttons: Ext.Msg.OK});}},
134 scope:this});}}});
135
136 // GOOD_FOR_RUN BEHAVIUOR
137 if(this.consoleLog)
138 console.log('browseWindow_UI.onRender: Button for selecting the next available run is: ', this.goodRun.testButton) ;
139
140 this.goodRun.testButton.on({
141 scope: this,
142 click: function() {
143 if (! this.db.getValue()) {
144 Ext.Msg.show({ title: 'Error',
145 msg: 'No Data Source Selected',
146 icon: Ext.MessageBox.INFO,
147 buttons: Ext.Msg.OK});return;}
148 if(! this.tags.getValue()) {
149 Ext.Msg.show({ title: 'Error',
150 msg: 'No LocalTag Selected.',
151 icon: Ext.MessageBox.INFO,
152 buttons: Ext.Msg.OK});return;}
153 this.loadMask.show();
154 Ext.Ajax.request({ url: '/cgi-bin/ReferencePythonCLI/driver.py',
155 method: 'post',
156 params: { action: 'getNextAvailableRun',
157 dbname: this.db.getValue(),
158 localtag: this.tags.getValue()},
159 success: function(response, request){
160 this.loadMask.hide();
161 var obj = Ext.util.JSON.decode(response.responseText);
162 this.since.setValue(obj.rows[0].nextAvailable);
163 Ext.Msg.show({ title: 'Tag Status',
164 msg: obj.rows[0].Mesg,
165 icon: Ext.MessageBox.INFO,
166 buttons: Ext.Msg.OK});},
167 scope:this});}});
168 } // eo function setConnections
169
170 ,addBaseParams:function()
171 {
172 if(this.consoleLog)
173 console.log('uploadWindow_UI installing db name to stores\' base params: ', this.db.getValue());
174 this.tags.store.setBaseParam('dbname', this.db.getValue());
175 this.subsystems.store.setBaseParam('dbname', this.db.getValue());
176 }
177 ,checkForm: function()
178 {
179 var errors = '' ;
180 if(!this.db.getValue())
181 errors += 'Database is mandatory';
182 if(!this.tags.getValue())
183 errors += '<br/>LocalTag is mandatory';
184 if(!this.subsystems.getValue())
185 errors += '<br/>SubSystem is mandatory';
186 if(!this.since.getValue())
187 errors += '<br/>Since is mandatory';
188 if(errors !=='')
189 {
190 Ext.Msg.show(
191 {
192 title: 'Errors'
193 ,msg: errors
194 ,icon: Ext.MessageBox.QUESTION
195 ,buttons: Ext.Msg.OK
196 ,width: 350
197 }) ;
198 return 1;
199 }
200 return 0;
201 } // eo function checkForm
202 ,checkXML: function()
203 {
204 var errors = '' ;
205 if(!this.xmlTextArea.getValue())
206 errors += 'XML file is mandatory';
207 if(errors !=='')
208 {
209 Ext.Msg.show(
210 {
211 title: 'Errors'
212 ,msg: errors
213 ,icon: Ext.MessageBox.QUESTION
214 ,buttons: Ext.Msg.OK
215 ,width: 350
216 }) ;
217 return 1;
218 }
219 return 0;
220 } // eo function checkXML
221 ,commit: function(button, event)
222 {
223 // just quit if there are non filled form values
224 // the detailed alert message is displayed by
225 // the checkForm function
226 if(this.checkForm()==1)
227 return ;
228 if(this.checkXML() == 1)
229 return ;
230 if(!this.xmlTextArea.validated)
231 {
232 Ext.Msg.show(
233 {
234 title: 'Warning'
235 ,msg: 'Please validate XML before commiting to DB'
236 ,icon: Ext.MessageBox.QUESTION
237 ,buttons: Ext.Msg.OK
238 ,width: 350
239 }) ;
240 return ;
241 }
242 // Ask confirmation to the user and display a brief
243 // summary of what is going to be uploaded into DB
244 var mesg = 'Databse: ' + this.db.getValue() ;
245 mesg += '<br/>LocalTag: ' + this.tags.getValue() ;
246 mesg += '<br/>SubSystem: ' + this.subsystems.getValue() ;
247 mesg += '<br/>Since: ' + this.since.getValue() ;
248 Ext.Msg.show(
249 {
250 title: 'Summary'
251 ,msg: mesg
252 ,icon: Ext.MessageBox.QUESTION
253 ,buttons: Ext.Msg.YESNO
254 ,width: 350
255 ,fn: this.doCommit
256 ,scope: this
257 }) ;
258 }// eo function commit
259 ,doCommit:function(btn, text)
260 {
261 if(btn == 'yes')
262 {
263 Ext.Ajax.request(
264 {
265 url : '/cgi-bin/ReferencePythonCLI/driver.py'
266 ,method : 'post'
267 ,params :
268 {
269 action: 'commit'
270 ,xmlString : Base64.encode(this.xmlTextArea.getValue())
271 ,dbname: this.db.getValue()
272 ,localtag: this.tags.getValue()
273 ,subsystem: this.subsystems.getValue()
274 ,specificRun: this.since.getValue()
275 }
276 ,scope:this
277 ,success: this.parseCommitResponse
278 // failure: function() {Debbie.connectionLost(380,500) ;}
279 }
280 );
281 }
282 } //eo function doCommit
283 ,parseCommitResponse: function(response, request)
284 {
285 var obj = Ext.util.JSON.decode(response.responseText) ;
286 var mesg = obj.loaded ? "OK" : "Failed" ;
287 if(!obj.loaded)
288 mesg += '<br/>Reason: ' + obj.err_msg ;
289 Ext.Msg.show(
290 {
291 title: 'Info'
292 ,msg: mesg
293 ,icon: Ext.MessageBox.INFO
294 ,buttons: Ext.Msg.OK
295 // ,width: 350
296 }) ;
297 }
298 }
299 );
300
301 Ext.reg('uploadwindow', uploadWindow_UI.Window);
302
303