Submit
Path:
~
/
/
opt
/
psa
/
admin
/
htdocs
/
modules
/
site-import
/
scripts
/
mail-import
/
File Content:
index.js
Jsw.onReady(function() { var progressMessages = { 'prepare-target': migratorLocale.lmsg('mailImportProgressPrepareTarget'), 'create-target-mailbox': migratorLocale.lmsg('mailImportProgressCreateTargetMailbox'), 'prepare-connect-source': migratorLocale.lmsg('mailImportProgressPrepareConnectSource'), 'detect-source-imap-host': migratorLocale.lmsg('mailImportProgressDetectSourceImapHost'), 'login-source': migratorLocale.lmsg('mailImportProgressLoginSource'), 'detect-folder-separator-source': migratorLocale.lmsg('mailImportProgressDetectFolderSeparatorSource'), 'connect-source': migratorLocale.lmsg('mailImportProgressConnectSource'), 'transfer-messages': migratorLocale.lmsg('mailImportProgressTransferMessages'), 'finalize': migratorLocale.lmsg('mailImportProgressFinalize') }; var importMailboxDialogs = { _importMailboxPopup: null, _existingMailboxes: null, _formData: null, showImportMailboxDialog: function() { this._showImportMailboxPopup(); }, setExistingMailboxes: function(mailboxes) { this._existingMailboxes = mailboxes; }, _showImportMailboxPopup: function() { var self = this; self._importMailboxPopup = showImportMailboxPopup( self._existingMailboxes, DOMAIN_DISPLAY_NAME, /*onSubmit=*/function () { self._importMailboxPopup.hideIssues(); if (!self._importMailboxPopup.validate()) { return; } self._importMailboxPopup.setInProgress(); self._importMailboxPopup.setProgress(migratorLocale.lmsg('mailImportProgressPrepare')); self._formData = self._importMailboxPopup.getData(true); backendOperations.startImport( self._importMailboxPopup.getData(), /*ignoreSecurityWarnings=*/false, /*onImportStarted=*/function() { self._onImportStarted(); }, /*onSecurityWarning=*/function(warningText) { self._showSecurityWarningPopup(warningText); }, /*onImapHostAutodetectionFailure*/function() { self._onImapHostAutodetectionFailure(); }, /*onError=*/function (errorText, errorDetails) { self._onStartImportError(errorText, errorDetails) }, /*onProgressUpdate*/function(progressMessage) { self._onProgressUpdate(progressMessage); } ); } ); }, _showSecurityWarningPopup: function(warningText) { var self = this; showSecurityWarningPopup( warningText, /*onAgree=*/function () { // If customer accepts security risks, then: // 1) Show import mailbox popup dialog // - The dialog must show the same set of data as before submit // - The dialog should show that we are in progress. // 2) Send AJAX query to start migration, ignoring security issues. self._showImportMailboxPopup(); self._importMailboxPopup.setData(self._formData); self._importMailboxPopup.setInProgress(); self._importMailboxPopup.setProgress(migratorLocale.lmsg('mailImportProgressPrepare')); backendOperations.startImport( self._formData, /*ignoreSecurityWarnings=*/true, /*onImportStarted=*/function() { self._onImportStarted(); }, /*onSecurityWarning=*/function(warningText) { self._onStartImportSecurityWarning(warningText); }, /*onImapHostAutodetectionFailure*/function() { self._onImapHostAutodetectionFailure(); }, /*onError=*/function (errorText, errorDetails) { self._onStartImportError(errorText, errorDetails) }, /*onProgressUpdate*/function(progressMessage) { self._onProgressUpdate(progressMessage); } ); }, /*onDisagree=*/function () { self._showImportMailboxPopup(); self._importMailboxPopup.setData(self._formData); } ); }, _onStartImportSecurityWarning: function(warningText) { this._showSecurityWarningPopup(warningText); }, _onImapHostAutodetectionFailure: function() { this._importMailboxPopup.setProgressStopped(); this._importMailboxPopup.setImapHostWarning(migratorLocale.lmsg('mailImportAutodetectWarning')); }, _onStartImportError: function(errorText, errorDetails) { this._importMailboxPopup.setProgressStopped(); this._importMailboxPopup.setError(errorText, errorDetails); }, _onImportStarted: function () { var self = this; updateStatusInfoAjax( function() { self._importMailboxPopup.hide(); } ); }, _onProgressUpdate: function(progressMessage) { this._importMailboxPopup.setProgress(progressMessage) } }; var backendOperations = { resync: function(sourceEmail, targetMailname, onSuccess) { new Ajax.Request(URL_ADD_TASKS, { parameters: { 'mailAddressPairs': Object.toJSON([{ 'sourceEmail': sourceEmail, 'targetMailname': targetMailname }]), 'isAsyncStatusReport': 'true' }, onSuccess: function() { // Start task runner, in background. new Ajax.Request(URL_RUN_TASKS); onSuccess(); } }); }, cancel: function(sourceEmail, targetMailname, onSuccess) { new Ajax.Request(URL_CANCEL_TASKS, { parameters: { 'mailAddressPairs': Object.toJSON([{ 'sourceEmail': sourceEmail, 'targetMailname': targetMailname }]) }, onSuccess: function() { onSuccess(); } }); }, startImport: function( mailboxData, ignoreSecurityWarnings, onImportStarted, onSecurityWarning, onImapHostAutodetectionFailure, onError, onProgressUpdate ) { mailboxData.ignoreSecurityWarnings = ignoreSecurityWarnings; function pollStatus(taskId) { new Ajax.Request(URL_GET_STATUS + '/task_id/' + taskId, { onSuccess: function(response) { var json = response.responseText.evalJSON(); var status = json['status']; var step = json['step']; var errorId = json['error_id']; var errorMessage = json['error_message']; var errorDetails = json['error_details']; if (errorId == 'security') { onSecurityWarning(migratorLocale.lmsg('mailImportSslIssue')); } else if (errorId == 'security-invalid-certificate') { onSecurityWarning(migratorLocale.lmsg('mailImportSslCertificateIssue')); } else if (errorId == 'authentication') { onError(migratorLocale.lmsg('mailImportAuthenticationIssue')); } else if (errorId == 'connect') { onError(migratorLocale.lmsg('mailImportConnectIssue')); } else if (errorId == 'create-target-mailbox') { onError(migratorLocale.lmsg('mailImportFailedToCreateMailbox')); } else if (errorId == 'imap-host-autodetect') { onImapHostAutodetectionFailure(); } else if (errorId) { onError(errorMessage, errorDetails); } else if ( inArray(status, [ migrationStatus.SUCCESS, migrationStatus.WARNING, migrationStatus.FAILURE, migrationStatus.CANCELLED ]) || ( status == migrationStatus.IN_PROGRESS && inArray(step, ['transfer-messages', 'finalize']) ) ) { if (step && progressMessages[step]) { onProgressUpdate(progressMessages[step]); } updateStatusInfoAjax( // update status in the table and only then close the dialog function() { onImportStarted(); } ); } else { if (step && progressMessages[step]) { onProgressUpdate(progressMessages[step]); } setTimeout(function() { pollStatus(taskId); }, STATUS_UPDATE_INTERVAL); } }, onFailure: function() { setTimeout(function() { pollStatus(taskId); }, STATUS_UPDATE_INTERVAL); } }); } new Ajax.Request(URL_ADD_TASKS, { parameters: { 'mailAddressPairs': Object.toJSON([mailboxData]) }, onSuccess: function(response) { var addTaskJson = response.responseText.evalJSON(); var taskId = addTaskJson['taskId']; // Start task runner, in background. new Ajax.Request(URL_RUN_TASKS); // Poll status for the new task periodically pollStatus(taskId); } }); } }; var mailboxesTable = { _mailboxes: [], addMailbox: function(sourceEmail, targetMailname) { var table = $('mailboxes-table'); var statusElement = new StatusElement( migratorLocale.lmsg('mailImportIssuesOfMailbox'), migrationStatuses, migrationStatus.READY_TO_IMPORT ); var resyncLinkElement = new Element('a', { 'class': 's-btn mail-import-button-resync', 'href': 'javascript:;', 'style': 'display: none' }).insert( new Element('span').update( migratorLocale.lmsg('mailImportResync').escapeHTML() ) ); var schedulingResyncElement = new Element('span', { 'class': 's-btn mail-import-button-in-progress', 'style': 'display: none' }).insert( new Element('span').update( migratorLocale.lmsg('mailImportSchedulingResync').escapeHTML() ) ); var cancelLinkElement = new Element('a', { 'class': 's-btn mail-import-button-cancel', 'href': 'javascript:;', 'style': 'display: none' }).insert( new Element('span').update( migratorLocale.lmsg('mailImportCancel').escapeHTML() ) ); var cancellingElement = new Element('span', { 'class': 's-btn mail-import-button-in-progress', 'style': 'display: none' }).insert( new Element('span').update( migratorLocale.lmsg('mailImportCancelling').escapeHTML() ) ); var rowElement = new Element('tr', {'style': 'display: none;'}) .insert(new Element('td').update(sourceEmail.escapeHTML())) .insert(new Element('td').update( targetMailname.escapeHTML() + '@' + DOMAIN_DISPLAY_NAME.escapeHTML()) ) .insert(new Element('td').insert(statusElement.getHtmlElement())) .insert( new Element('td') .insert(resyncLinkElement) .insert(cancelLinkElement) .insert(schedulingResyncElement) .insert(cancellingElement) ); table.select('tbody').first().insert(rowElement); var newMailbox = { sourceEmail: sourceEmail, targetMailname: targetMailname, statusElement: statusElement, rowElement: rowElement, cancelLinkElement: cancelLinkElement, resyncLinkElement: resyncLinkElement, schedulingResyncElement: schedulingResyncElement, cancellingElement: cancellingElement, status: migrationStatus.READY_TO_IMPORT, step: null, errorId: null, errorMessage: null }; this._mailboxes.push(newMailbox); this._configureButtonHandlers(newMailbox); return newMailbox; }, setMailboxStatus: function(sourceEmail, targetMailname, status, statusDetails) { var mailbox = this._findOrAddMailbox(sourceEmail, targetMailname); if (status) { mailbox.rowElement.show(); var table = $('mailboxes-table'); table.show(); } else { mailbox.rowElement.hide(); } if (mailbox.status != status) { mailbox.resyncLinkElement.toggle(inArray(status, allowedMigrationStatusesToStartResync)); mailbox.cancelLinkElement.toggle(inArray(status, allowedMigrationStatusesToCancelOperation)); } mailbox.status = status; mailbox.statusElement.updateStatus(status, statusDetails); }, getMailboxStatus: function(sourceEmail, targetMailname) { var mailbox = this._findMailbox(sourceEmail, targetMailname); if (!mailbox) { return null; } return mailbox.status; }, setMailboxStep: function(sourceEmail, targetMailname, step) { var mailbox = this._findOrAddMailbox(sourceEmail, targetMailname); mailbox.step = step; }, setMailboxError: function(sourceEmail, targetMailname, errorId, errorMessage) { var mailbox = this._findOrAddMailbox(sourceEmail, targetMailname); mailbox.errorId = errorId; mailbox.errorMessage = errorMessage; }, getMailboxStep: function(sourceEmail, targetMailname) { var mailbox = this._findMailbox(sourceEmail, targetMailname); if (!mailbox) { return null; } return mailbox.step; }, getMailboxErrorId: function(sourceEmail, targetMailname) { var mailbox = this._findMailbox(sourceEmail, targetMailname); if (!mailbox) { return null; } return mailbox.errorId; }, getMailboxErrorMessage: function(sourceEmail, targetMailname) { var mailbox = this._findMailbox(sourceEmail, targetMailname); if (!mailbox) { return null; } return mailbox.errorMessage; }, setMailboxIssues: function(sourceEmail, targetMailname, issues) { var mailbox = this._findMailbox(sourceEmail, targetMailname); mailbox.statusElement.updateIssues(issues); }, _configureButtonHandlers: function(mailbox) { var self = this; mailbox.cancelLinkElement.observe('click', function() { mailbox.cancellingElement.show(); mailbox.cancelLinkElement.hide(); backendOperations.cancel( mailbox.sourceEmail, mailbox.targetMailname, /*onSuccess=*/function() { updateStatusInfoAjax(function() { mailbox.cancellingElement.hide(); }); } ); }); mailbox.resyncLinkElement.observe('click', function() { mailbox.schedulingResyncElement.show(); mailbox.resyncLinkElement.hide(); backendOperations.resync( mailbox.sourceEmail, mailbox.targetMailname, /*onSuccess=*/function() { updateStatusInfoAjax(function() { mailbox.schedulingResyncElement.hide(); }); } ); }); }, _findOrAddMailbox: function(sourceEmail, targetMailname) { var mailbox = this._findMailbox(sourceEmail, targetMailname); if (mailbox == null) { mailbox = this.addMailbox(sourceEmail, targetMailname); } return mailbox; }, _findMailbox: function(sourceEmail, targetMailname) { var mailbox = null; this._mailboxes.each(function(currentMailbox) { if ( currentMailbox.sourceEmail == sourceEmail && currentMailbox.targetMailname == targetMailname ) { mailbox = currentMailbox; } }); return mailbox; } }; var buttonImportMailbox = $('import-mailbox'); buttonImportMailbox.observe('click', function() { importMailboxDialogs.showImportMailboxDialog(); }); function updateStatusInfo(statusInfo) { if (!statusInfo['mail_address_pairs']) { return; } statusInfo['mail_address_pairs'].forEach(function(mailAddressPair) { var statusDetails = null; if ( mailAddressPair['status'] == migrationStatus.IN_PROGRESS && mailAddressPair['restored_message_num'] ) { statusDetails = 'restoring message #' + mailAddressPair['restored_message_num']; } mailboxesTable.setMailboxStatus( mailAddressPair['source_email'], mailAddressPair['target_mailname'], mailAddressPair['status'], statusDetails ); mailboxesTable.setMailboxStep( mailAddressPair['source_email'], mailAddressPair['target_mailname'], mailAddressPair['step'] ); mailboxesTable.setMailboxIssues( mailAddressPair['source_email'], mailAddressPair['target_mailname'], mailAddressPair['issues'] ); mailboxesTable.setMailboxError( mailAddressPair['source_email'], mailAddressPair['target_mailname'], mailAddressPair['error_id'], mailAddressPair['error_message'] ); }); } function updateStatusInfoAjaxPeriodic() { new Ajax.Request(URL_GET_STATUS, { onSuccess: function(response) { var json = response.responseText.evalJSON(); updateStatusInfo(json); }, onComplete: function() { setTimeout(updateStatusInfoAjaxPeriodic, STATUS_UPDATE_INTERVAL); } }); } function updateStatusInfoAjax(onSuccess) { new Ajax.Request(URL_GET_STATUS, { onSuccess: function(response) { var json = response.responseText.evalJSON(); updateStatusInfo(json); if (onSuccess) { onSuccess(); } } }); } updateStatusInfo(INITIAL_STATUS_INFO); updateStatusInfoAjaxPeriodic(); importMailboxDialogs.setExistingMailboxes(EXISTING_MAILBOXES); });
Submit
FILE
FOLDER
INFO
Name
Size
Permission
Action
popup
---
0755
index.js
21254 bytes
0644
N4ST4R_ID | Naxtarrr