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