1 | /** |
---|
2 | * ----------------------------------------------------------------------------- |
---|
3 | * file: estatIM.js |
---|
4 | * file version: 1.0.0 |
---|
5 | * date: 2011-12-02 |
---|
6 | * |
---|
7 | * Import Manager |
---|
8 | */ |
---|
9 | |
---|
10 | |
---|
11 | // EStat install managment |
---|
12 | $.EStatInstall = function (step, param) |
---|
13 | { |
---|
14 | var properties={ |
---|
15 | pArea:null, |
---|
16 | url:'', |
---|
17 | token:'', |
---|
18 | ipNbRecords:'', |
---|
19 | importLog:false |
---|
20 | }, |
---|
21 | |
---|
22 | /** |
---|
23 | * define properties from given parameters |
---|
24 | */ |
---|
25 | setProperties = function (param) |
---|
26 | { |
---|
27 | if(param==null) return(false); |
---|
28 | if(param.url) properties.url=param.url; |
---|
29 | if(param.token) properties.token=param.token; |
---|
30 | if(param.ipNbRecords) properties.ipNbRecords=param.ipNbRecords; |
---|
31 | if(param.importLog) properties.importLog=param.importLog; |
---|
32 | return(true); |
---|
33 | }, |
---|
34 | |
---|
35 | /** |
---|
36 | * initialize the dialog box; set the pArea object as progressArea() |
---|
37 | */ |
---|
38 | initDialogBox = function() |
---|
39 | { |
---|
40 | pArea=$.dialogProgressArea( |
---|
41 | { |
---|
42 | title:translatedString.ciDialogTitle, |
---|
43 | buttons: |
---|
44 | { |
---|
45 | ok:'Ok' |
---|
46 | }, |
---|
47 | text:translatedString.ciDialogText, |
---|
48 | progressBar: |
---|
49 | { |
---|
50 | detail:{ |
---|
51 | visible:false, |
---|
52 | }, |
---|
53 | global:{ |
---|
54 | visible:true, |
---|
55 | showPercent:true, |
---|
56 | percentDecimal:0, |
---|
57 | value:0, |
---|
58 | maxValue:properties.ipNbRecords, |
---|
59 | text:'', |
---|
60 | complete:function (event, value) |
---|
61 | { |
---|
62 | pArea.progressArea('text', translatedString.ciDialogFinished); |
---|
63 | }, |
---|
64 | change: function (event, value) |
---|
65 | { |
---|
66 | processImportIp(value.currentValue); |
---|
67 | } |
---|
68 | } |
---|
69 | }, |
---|
70 | close: function (event) |
---|
71 | { |
---|
72 | manageInstall(1); |
---|
73 | } |
---|
74 | } |
---|
75 | ); |
---|
76 | }, |
---|
77 | |
---|
78 | /** |
---|
79 | * ajax call on server to import ip adress from start value |
---|
80 | * |
---|
81 | * @param Integer start: start import number |
---|
82 | */ |
---|
83 | processImportIp = function (start) |
---|
84 | { |
---|
85 | $.ajax( |
---|
86 | { |
---|
87 | type: "POST", |
---|
88 | url: properties.url, |
---|
89 | async: true, |
---|
90 | data: |
---|
91 | { |
---|
92 | ajaxfct:"admin.install.buildIpList", |
---|
93 | token:properties.token, |
---|
94 | start:start |
---|
95 | }, |
---|
96 | success: |
---|
97 | function(msg) |
---|
98 | { |
---|
99 | msg=$.parseJSON(msg); |
---|
100 | |
---|
101 | pArea.progressArea('globalValue', msg.nbTotal); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | ); |
---|
106 | }, |
---|
107 | |
---|
108 | /** |
---|
109 | * display the import log page |
---|
110 | */ |
---|
111 | displayImportPage = function () |
---|
112 | { |
---|
113 | $('#iImportLogs').css('display', 'block'); |
---|
114 | }, |
---|
115 | |
---|
116 | /** |
---|
117 | * finalize the install process |
---|
118 | */ |
---|
119 | finalize = function () |
---|
120 | { |
---|
121 | $.ajax( |
---|
122 | { |
---|
123 | type: "POST", |
---|
124 | url: properties.url, |
---|
125 | async: true, |
---|
126 | data: { ajaxfct:"admin.migrate.finalize", token:properties.token }, |
---|
127 | success: |
---|
128 | function(msg) |
---|
129 | { |
---|
130 | manageInstall(3); |
---|
131 | } |
---|
132 | } |
---|
133 | ); |
---|
134 | }, |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | /** |
---|
139 | * manage all the import process |
---|
140 | * |
---|
141 | * if importLog, call $.EStatImportLogs |
---|
142 | */ |
---|
143 | manageInstall = function (step) |
---|
144 | { |
---|
145 | switch(step) |
---|
146 | { |
---|
147 | case 0: |
---|
148 | // init process |
---|
149 | initDialogBox(); |
---|
150 | processImportIp(0); |
---|
151 | break; |
---|
152 | case 1: |
---|
153 | // import log process |
---|
154 | if(properties.importLog) |
---|
155 | { |
---|
156 | displayImportPage(); |
---|
157 | // note: when import log, finalization is done by the import log process |
---|
158 | } |
---|
159 | else |
---|
160 | { |
---|
161 | finalize(); |
---|
162 | } |
---|
163 | break; |
---|
164 | case 2: |
---|
165 | finalize(); |
---|
166 | break; |
---|
167 | case 3: |
---|
168 | // end of process, reload the page |
---|
169 | location.reload(); |
---|
170 | break; |
---|
171 | } |
---|
172 | |
---|
173 | }; |
---|
174 | |
---|
175 | |
---|
176 | setProperties(param); |
---|
177 | manageInstall(step); |
---|
178 | } |
---|
179 | |
---|
180 | |
---|
181 | // Estat piwigo's logs import managment |
---|
182 | $.EStatImportLogs = function (url, token) |
---|
183 | { |
---|
184 | var pArea=null, |
---|
185 | properties={ |
---|
186 | _this:this, |
---|
187 | token:'', |
---|
188 | url:'', |
---|
189 | current:{ |
---|
190 | nbLoaded:0, |
---|
191 | periodNum:0, |
---|
192 | id:0 |
---|
193 | }, |
---|
194 | environment:{ |
---|
195 | periods:[], |
---|
196 | } |
---|
197 | }, |
---|
198 | |
---|
199 | /** |
---|
200 | * define properties from given parameters & initialize environment variables |
---|
201 | */ |
---|
202 | setProperties = function (url, token) |
---|
203 | { |
---|
204 | var periodList={}, |
---|
205 | nbEvents=0; |
---|
206 | |
---|
207 | properties.token=token; |
---|
208 | properties.url=url; |
---|
209 | |
---|
210 | properties.environment.periods=[]; |
---|
211 | |
---|
212 | // period to import |
---|
213 | periodList=$('#iImportLogsChoice').inputCheckbox('value'); |
---|
214 | for(var i=0;i<periodList.length;i++) |
---|
215 | { |
---|
216 | if(periodList[i].value) |
---|
217 | { |
---|
218 | nbEvents=$('#'+periodList[i].id).attr('nbEvents'); |
---|
219 | if(nbEvents>0) |
---|
220 | properties.environment.periods.push( |
---|
221 | { |
---|
222 | period:periodList[i].id.substr(1), |
---|
223 | nbEvents:nbEvents |
---|
224 | } |
---|
225 | ); |
---|
226 | } |
---|
227 | } |
---|
228 | |
---|
229 | if(properties.environment.periods.length>0) |
---|
230 | { |
---|
231 | properties.current.periodNum=0; |
---|
232 | properties.current.id=0; |
---|
233 | } |
---|
234 | }, |
---|
235 | |
---|
236 | /** |
---|
237 | * initialize the dialog box; set the pArea object as progressArea() |
---|
238 | */ |
---|
239 | initDialogBox = function() |
---|
240 | { |
---|
241 | pArea=$.dialogProgressArea( |
---|
242 | { |
---|
243 | title:translatedString.ciDialogTitle, |
---|
244 | buttons:{ok:'Ok'}, |
---|
245 | text:translatedString.liDialogText, |
---|
246 | progressBar: |
---|
247 | { |
---|
248 | global:{ |
---|
249 | visible:true, |
---|
250 | showPercent:true, |
---|
251 | percentDecimal:0, |
---|
252 | value:0, |
---|
253 | maxValue:2*properties.environment.periods.length+1, |
---|
254 | text:translatedString.liDialogImportStep1, |
---|
255 | complete:function (event, value) |
---|
256 | { |
---|
257 | pArea.progressArea('text', translatedString.liDialogFinished); |
---|
258 | } |
---|
259 | }, |
---|
260 | detail:{ |
---|
261 | visible:true, |
---|
262 | showPercent:true, |
---|
263 | percentDecimal:0, |
---|
264 | value:0, |
---|
265 | maxValue:properties.environment.periods[properties.current.periodNum].nbEvents, |
---|
266 | text:translatedString.liDialogImportInProgressText, |
---|
267 | complete:function (event, value) |
---|
268 | { |
---|
269 | |
---|
270 | } |
---|
271 | } |
---|
272 | }, |
---|
273 | close: function (event) |
---|
274 | { |
---|
275 | $.EStatInstall(3); |
---|
276 | } |
---|
277 | } |
---|
278 | ); |
---|
279 | }, |
---|
280 | |
---|
281 | |
---|
282 | /** |
---|
283 | * ajax call to the server, import some records from piwigo's history table |
---|
284 | */ |
---|
285 | loadLogs = function () |
---|
286 | { |
---|
287 | // display current period being imported |
---|
288 | $('#iCurrentPeriod').html($('#iText'+properties.environment.periods[properties.current.periodNum].period).html()); |
---|
289 | |
---|
290 | $.ajax( |
---|
291 | { |
---|
292 | type: "POST", |
---|
293 | url: properties.url, |
---|
294 | async: true, |
---|
295 | data: |
---|
296 | { |
---|
297 | ajaxfct:"admin.migrate.loadLogs", |
---|
298 | token:properties.token, |
---|
299 | period:properties.environment.periods[properties.current.periodNum].period, |
---|
300 | lastId:properties.current.lastId |
---|
301 | }, |
---|
302 | success: |
---|
303 | function(msg) |
---|
304 | { |
---|
305 | msg=$.parseJSON(msg); |
---|
306 | |
---|
307 | // set last Id imported |
---|
308 | if(msg.nbLogs>0) properties.current.lastId=msg.lastId; |
---|
309 | |
---|
310 | if(msg.nbLogs>0) |
---|
311 | { |
---|
312 | // nbLogs>0 means to continue to import the period |
---|
313 | |
---|
314 | // update total records imported for the period, update the dialog box progress bar |
---|
315 | properties.current.nbLoaded+=msg.nbLogs; |
---|
316 | pArea.progressArea('detailValue', properties.current.nbLoaded); |
---|
317 | |
---|
318 | // continue the import process for the period |
---|
319 | importProcess(1); |
---|
320 | } |
---|
321 | else |
---|
322 | { |
---|
323 | //nbLogs=0 means that current period is imported |
---|
324 | |
---|
325 | // process next period |
---|
326 | properties.current.periodNum++; |
---|
327 | |
---|
328 | if(properties.current.periodNum>=properties.environment.periods.length) |
---|
329 | { |
---|
330 | // it was the last period => next process is to consolidate informations |
---|
331 | properties.current.periodNum=0; |
---|
332 | |
---|
333 | // update the dialog box messages & progress bar |
---|
334 | pArea |
---|
335 | .progressArea('detailValue', 0) |
---|
336 | .progressArea('detailMaxValue', properties.environment.periods.length) |
---|
337 | .progressArea('globalValue', pArea.progressArea('globalValue')+1) |
---|
338 | .progressArea('globalText', translatedString.liDialogImportStep2); |
---|
339 | |
---|
340 | // continue the process with consolidation |
---|
341 | importProcess(2); |
---|
342 | } |
---|
343 | else |
---|
344 | { |
---|
345 | // import for the period is done, but it's not the last period |
---|
346 | properties.current.nbLoaded=0; |
---|
347 | |
---|
348 | // update the dialog box messages & progress bar |
---|
349 | pArea |
---|
350 | .progressArea('globalValue', properties.current.periodNum) |
---|
351 | .progressArea('detailValue', 0) |
---|
352 | .progressArea('detailMaxValue', properties.environment.periods[properties.current.periodNum].nbEvents); |
---|
353 | |
---|
354 | // continue the import process with the next period |
---|
355 | importProcess(1); |
---|
356 | } |
---|
357 | } |
---|
358 | } |
---|
359 | } |
---|
360 | ); |
---|
361 | }, |
---|
362 | |
---|
363 | /** |
---|
364 | * do the consolidation |
---|
365 | */ |
---|
366 | consolidate = function () |
---|
367 | { |
---|
368 | // display current period being consolidated |
---|
369 | $('#iCurrentPeriod').html($('#iText'+properties.environment.periods[properties.current.periodNum].period).html()); |
---|
370 | |
---|
371 | $.ajax( |
---|
372 | { |
---|
373 | type: "POST", |
---|
374 | url: properties.url, |
---|
375 | async: true, |
---|
376 | data: |
---|
377 | { |
---|
378 | ajaxfct:"admin.migrate.consolidate", |
---|
379 | token:properties.token, |
---|
380 | period:properties.environment.periods[properties.current.periodNum].period, |
---|
381 | process:0 |
---|
382 | }, |
---|
383 | success: |
---|
384 | function(msg) |
---|
385 | { |
---|
386 | if(msg=='Y') |
---|
387 | { |
---|
388 | // period is consolidated, continue with the next period |
---|
389 | properties.current.periodNum++; |
---|
390 | if(properties.current.periodNum>=properties.environment.periods.length) |
---|
391 | { |
---|
392 | // it was the last period, continue with finalization |
---|
393 | |
---|
394 | // update the dialog box messages & progress bar |
---|
395 | pArea |
---|
396 | .progressArea('options', {detail:{visible:false}}) |
---|
397 | .progressArea('globalValue', pArea.progressArea('globalValue')+1) |
---|
398 | .progressArea('globalText', translatedString.liDialogImportStep3) |
---|
399 | |
---|
400 | // continue the process with finalization |
---|
401 | importProcess(3); |
---|
402 | } |
---|
403 | else |
---|
404 | { |
---|
405 | // update the dialog box messages & progress bar |
---|
406 | pArea |
---|
407 | .progressArea('detailValue', properties.current.periodNum) |
---|
408 | .progressArea('globalValue', pArea.progressArea('globalValue')+1); |
---|
409 | |
---|
410 | // continue the consolidation process with the next period |
---|
411 | importProcess(2); |
---|
412 | } |
---|
413 | } |
---|
414 | } |
---|
415 | } |
---|
416 | ); |
---|
417 | |
---|
418 | }, |
---|
419 | |
---|
420 | /** |
---|
421 | * finalize the import process |
---|
422 | */ |
---|
423 | finalize = function () |
---|
424 | { |
---|
425 | $.ajax( |
---|
426 | { |
---|
427 | type: "POST", |
---|
428 | url: properties.url, |
---|
429 | async: true, |
---|
430 | data: { ajaxfct:"admin.migrate.finalize", token:properties.token }, |
---|
431 | success: |
---|
432 | function(msg) |
---|
433 | { |
---|
434 | pArea.progressArea('globalValue', pArea.progressArea('globalValue')+1); |
---|
435 | } |
---|
436 | } |
---|
437 | ); |
---|
438 | }, |
---|
439 | |
---|
440 | /** |
---|
441 | * manage the import process |
---|
442 | */ |
---|
443 | importProcess = function (step) |
---|
444 | { |
---|
445 | switch(step) |
---|
446 | { |
---|
447 | case 1: |
---|
448 | loadLogs(); |
---|
449 | break; |
---|
450 | case 2: |
---|
451 | consolidate(); |
---|
452 | break; |
---|
453 | case 3: |
---|
454 | finalize(); |
---|
455 | break; |
---|
456 | } |
---|
457 | }; |
---|
458 | |
---|
459 | |
---|
460 | setProperties(url, token); |
---|
461 | initDialogBox(); |
---|
462 | importProcess(1); |
---|
463 | } |
---|
464 | |
---|