/** * ----------------------------------------------------------------------------- * file: estatIM.js * file version: 1.0.0 * date: 2011-12-02 * * Import Manager */ // EStat install managment $.EStatInstall = function (step, param) { var properties={ pArea:null, url:'', token:'', ipNbRecords:'', importLog:false }, /** * define properties from given parameters */ setProperties = function (param) { if(param==null) return(false); if(param.url) properties.url=param.url; if(param.token) properties.token=param.token; if(param.ipNbRecords) properties.ipNbRecords=param.ipNbRecords; if(param.importLog) properties.importLog=param.importLog; return(true); }, /** * initialize the dialog box; set the pArea object as progressArea() */ initDialogBox = function() { pArea=$.dialogProgressArea( { title:translatedString.ciDialogTitle, buttons: { ok:'Ok' }, text:translatedString.ciDialogText, progressBar: { detail:{ visible:false, }, global:{ visible:true, showPercent:true, percentDecimal:0, value:0, maxValue:properties.ipNbRecords, text:'', complete:function (event, value) { pArea.progressArea('text', translatedString.ciDialogFinished); }, change: function (event, value) { processImportIp(value.currentValue); } } }, close: function (event) { manageInstall(1); } } ); }, /** * ajax call on server to import ip adress from start value * * @param Integer start: start import number */ processImportIp = function (start) { $.ajax( { type: "POST", url: properties.url, async: true, data: { ajaxfct:"admin.install.buildIpList", token:properties.token, start:start }, success: function(msg) { msg=$.parseJSON(msg); pArea.progressArea('globalValue', msg.nbTotal); } } ); }, /** * display the import log page */ displayImportPage = function () { $('#iImportLogs').css('display', 'block'); }, /** * finalize the install process */ finalize = function () { $.ajax( { type: "POST", url: properties.url, async: true, data: { ajaxfct:"admin.migrate.finalize", token:properties.token }, success: function(msg) { manageInstall(3); } } ); }, /** * manage all the import process * * if importLog, call $.EStatImportLogs */ manageInstall = function (step) { switch(step) { case 0: // init process initDialogBox(); processImportIp(0); break; case 1: // import log process if(properties.importLog) { displayImportPage(); // note: when import log, finalization is done by the import log process } else { finalize(); } break; case 2: finalize(); break; case 3: // end of process, reload the page location.reload(); break; } }; setProperties(param); manageInstall(step); } // Estat piwigo's logs import managment $.EStatImportLogs = function (url, token) { var pArea=null, properties={ _this:this, token:'', url:'', current:{ nbLoaded:0, periodNum:0, id:0 }, environment:{ periods:[], } }, /** * define properties from given parameters & initialize environment variables */ setProperties = function (url, token) { var periodList={}, nbEvents=0; properties.token=token; properties.url=url; properties.environment.periods=[]; // period to import periodList=$('#iImportLogsChoice').inputCheckbox('value'); for(var i=0;i0) properties.environment.periods.push( { period:periodList[i].id.substr(1), nbEvents:nbEvents } ); } } if(properties.environment.periods.length>0) { properties.current.periodNum=0; properties.current.id=0; } }, /** * initialize the dialog box; set the pArea object as progressArea() */ initDialogBox = function() { pArea=$.dialogProgressArea( { title:translatedString.ciDialogTitle, buttons:{ok:'Ok'}, text:translatedString.liDialogText, progressBar: { global:{ visible:true, showPercent:true, percentDecimal:0, value:0, maxValue:2*properties.environment.periods.length+1, text:translatedString.liDialogImportStep1, complete:function (event, value) { pArea.progressArea('text', translatedString.liDialogFinished); } }, detail:{ visible:true, showPercent:true, percentDecimal:0, value:0, maxValue:properties.environment.periods[properties.current.periodNum].nbEvents, text:translatedString.liDialogImportInProgressText, complete:function (event, value) { } } }, close: function (event) { $.EStatInstall(3); } } ); }, /** * ajax call to the server, import some records from piwigo's history table */ loadLogs = function () { // display current period being imported $('#iCurrentPeriod').html($('#iText'+properties.environment.periods[properties.current.periodNum].period).html()); $.ajax( { type: "POST", url: properties.url, async: true, data: { ajaxfct:"admin.migrate.loadLogs", token:properties.token, period:properties.environment.periods[properties.current.periodNum].period, lastId:properties.current.lastId }, success: function(msg) { msg=$.parseJSON(msg); // set last Id imported if(msg.nbLogs>0) properties.current.lastId=msg.lastId; if(msg.nbLogs>0) { // nbLogs>0 means to continue to import the period // update total records imported for the period, update the dialog box progress bar properties.current.nbLoaded+=msg.nbLogs; pArea.progressArea('detailValue', properties.current.nbLoaded); // continue the import process for the period importProcess(1); } else { //nbLogs=0 means that current period is imported // process next period properties.current.periodNum++; if(properties.current.periodNum>=properties.environment.periods.length) { // it was the last period => next process is to consolidate informations properties.current.periodNum=0; // update the dialog box messages & progress bar pArea .progressArea('detailValue', 0) .progressArea('detailMaxValue', properties.environment.periods.length) .progressArea('globalValue', pArea.progressArea('globalValue')+1) .progressArea('globalText', translatedString.liDialogImportStep2); // continue the process with consolidation importProcess(2); } else { // import for the period is done, but it's not the last period properties.current.nbLoaded=0; // update the dialog box messages & progress bar pArea .progressArea('globalValue', properties.current.periodNum) .progressArea('detailValue', 0) .progressArea('detailMaxValue', properties.environment.periods[properties.current.periodNum].nbEvents); // continue the import process with the next period importProcess(1); } } } } ); }, /** * do the consolidation */ consolidate = function () { // display current period being consolidated $('#iCurrentPeriod').html($('#iText'+properties.environment.periods[properties.current.periodNum].period).html()); $.ajax( { type: "POST", url: properties.url, async: true, data: { ajaxfct:"admin.migrate.consolidate", token:properties.token, period:properties.environment.periods[properties.current.periodNum].period, process:0 }, success: function(msg) { if(msg=='Y') { // period is consolidated, continue with the next period properties.current.periodNum++; if(properties.current.periodNum>=properties.environment.periods.length) { // it was the last period, continue with finalization // update the dialog box messages & progress bar pArea .progressArea('options', {detail:{visible:false}}) .progressArea('globalValue', pArea.progressArea('globalValue')+1) .progressArea('globalText', translatedString.liDialogImportStep3) // continue the process with finalization importProcess(3); } else { // update the dialog box messages & progress bar pArea .progressArea('detailValue', properties.current.periodNum) .progressArea('globalValue', pArea.progressArea('globalValue')+1); // continue the consolidation process with the next period importProcess(2); } } } } ); }, /** * finalize the import process */ finalize = function () { $.ajax( { type: "POST", url: properties.url, async: true, data: { ajaxfct:"admin.migrate.finalize", token:properties.token }, success: function(msg) { pArea.progressArea('globalValue', pArea.progressArea('globalValue')+1); } } ); }, /** * manage the import process */ importProcess = function (step) { switch(step) { case 1: loadLogs(); break; case 2: consolidate(); break; case 3: finalize(); break; } }; setProperties(url, token); initDialogBox(); importProcess(1); }