123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- /**
- * @deprecated since version 2.2.0
- */
- /* global AdminBackup, setLocation */
- /* eslint-disable strict */
- define([
- 'jquery',
- 'Magento_Ui/js/modal/modal',
- 'mage/mage',
- 'prototype'
- ], function (jQuery) {
- window.AdminBackup = new Class.create();
- AdminBackup.prototype = {
- /**
- * Initialize.
- */
- initialize: function () {
- this.reset();
- this.rollbackUrl = this.backupUrl = '';
- },
- /**
- * reset.
- */
- reset: function () {
- this.time = 0;
- this.type = '';
- },
- /**
- * @param {*} type
- * @return {Boolean}
- */
- backup: function (type) {
- this.reset();
- this.type = type;
- this.requestBackupOptions();
- return false;
- },
- /**
- * @param {*} type
- * @param {*} time
- * @return {Boolean}
- */
- rollback: function (type, time) {
- this.reset();
- this.time = time;
- this.type = type;
- this.showRollbackWarning();
- return false;
- },
- /**
- * Show rollback warning.
- */
- showRollbackWarning: function () {
- this.showPopup('rollback-warning');
- },
- /**
- * request backup options.
- */
- requestBackupOptions: function () {
- var action;
- this.hidePopups();
- action = this.type != 'snapshot' ? 'hide' : 'show'; //eslint-disable-line eqeqeq
- this.showPopup('backup-options');
- $$('#exclude-media-checkbox-container').invoke(action);
- },
- /**
- * Request password.
- */
- requestPassword: function () {
- this.hidePopups();
- this.showPopup('rollback-request-password');
- this.type != 'db' ? //eslint-disable-line eqeqeq
- $('use-ftp-checkbox-row').show() :
- $('use-ftp-checkbox-row').hide();
- },
- /**
- * Toggle Ftp Credentials Form.
- */
- toggleFtpCredentialsForm: function () {
- $('use_ftp').checked ? $('ftp-credentials-container').show()
- : $('ftp-credentials-container').hide();
- $$('#ftp-credentials-container input').each(function (item) {
- if (item.name == 'ftp_path') { //eslint-disable-line eqeqeq
- return;
- }
- $('use_ftp').checked ? item.addClassName('required-entry') : item.removeClassName('required-entry');
- });
- },
- /**
- * Submit backup.
- */
- submitBackup: function () {
- var data = {
- 'type': this.type,
- 'maintenance_mode': $('backup_maintenance_mode').checked ? 1 : 0,
- 'backup_name': $('backup_name').value,
- 'exclude_media': $('exclude_media').checked ? 1 : 0
- };
- new Ajax.Request(this.backupUrl, {
- onSuccess: function (transport) {
- this.processResponse(transport, 'backup-options');
- }.bind(this),
- method: 'post',
- parameters: data
- });
- this.modal.modal('closeModal');
- },
- /**
- * Submit rollback.
- */
- submitRollback: function () {
- var data = this.getPostData();
- new Ajax.Request(this.rollbackUrl, {
- onSuccess: function (transport) {
- this.processResponse(transport, 'rollback-request-password');
- }.bind(this),
- method: 'post',
- parameters: data
- });
- this.modal.modal('closeModal');
- },
- /**
- * @param {Object} transport
- * @param {*} popupId
- */
- processResponse: function (transport, popupId) {
- var json;
- if (!transport.responseText.isJSON()) {
- return;
- }
- json = transport.responseText.evalJSON();
- if (json.error) {
- this.showPopup(popupId);
- this.displayError(popupId, json.error);
- return;
- }
- if (json['redirect_url']) {
- setLocation(json['redirect_url']);
- }
- },
- /**
- * @param {*} parentContainer
- * @param {*} message
- */
- displayError: function (parentContainer, message) {
- var messageHtml = this.getErrorMessageHtml(message);
- $$('#' + parentContainer + ' .backup-messages .messages').invoke('update', messageHtml);
- $$('#' + parentContainer + ' .backup-messages').invoke('show');
- },
- /**
- * @param {*} message
- * @return {String}
- */
- getErrorMessageHtml: function (message) {
- return '<div class="message message-error error"><div>' + message + '</div></div>';
- },
- /**
- * @return {*|jQuery}
- */
- getPostData: function () {
- var data = $('rollback-form').serialize(true);
- data.time = this.time;
- data.type = this.type;
- return data;
- },
- backupConfig: {
- 'backup-options': {
- title: jQuery.mage.__('Backup options'),
- /**
- * @return {String}
- */
- content: function () {
- return document.getElementById('backup-options-template').textContent;
- },
- /**
- * Action Ok.
- */
- actionOk: function () {
- this.modal.find('#backup-form').validation({
- submitHandler: jQuery.proxy(this.submitBackup, this)
- });
- this.modal.find('#backup-form').submit();
- }
- },
- 'rollback-warning': {
- title: jQuery.mage.__('Warning'),
- /**
- * @return {String}
- */
- content: function () {
- return document.getElementById('rollback-warning-template').textContent;
- },
- /**
- * Action Ok.
- */
- actionOk: function () {
- this.modal.modal('closeModal');
- this.requestPassword();
- }
- },
- 'rollback-request-password': {
- title: jQuery.mage.__('Backup options'),
- /**
- * @return {String}
- */
- content: function () {
- return document.getElementById('rollback-request-password-template').textContent;
- },
- /**
- * Action Ok.
- */
- actionOk: function () {
- this.modal.find('#rollback-form').validation({
- submitHandler: jQuery.proxy(this.submitRollback, this)
- });
- this.modal.find('#rollback-form').submit();
- },
- /**
- * Opened.
- */
- opened: function () {
- this.toggleFtpCredentialsForm();
- }
- }
- },
- /**
- * @param {*} divId
- */
- showPopup: function (divId) {
- var self = this;
- this.modal = jQuery('<div/>').attr({
- id: divId
- }).html(this.backupConfig[divId].content()).modal({
- modalClass: 'magento',
- title: this.backupConfig[divId].title,
- type: 'slide',
- /**
- * @param {juery.Event} e
- * @param {Object} modal
- */
- closed: function (e, modal) {
- modal.modal.remove();
- },
- /**
- * Opened.
- */
- opened: function () {
- if (self.backupConfig[divId].opened) {
- self.backupConfig[divId].opened.call(self);
- }
- },
- buttons: [{
- text: jQuery.mage.__('Cancel'),
- 'class': 'action cancel',
- /**
- * Click action.
- */
- click: function () {
- this.closeModal();
- }
- }, {
- text: jQuery.mage.__('Ok'),
- 'class': 'action primary',
- /**
- * Click action.
- */
- click: function () {
- self.backupConfig[divId].actionOk.call(self);
- }
- }]
- });
- this.modal.modal('openModal');
- },
- /**
- * Hide Popups.
- */
- hidePopups: function () {
- var mask;
- $$('.backup-dialog').each(Element.hide);
- mask = $('popup-window-mask');
- if (mask) {
- mask.hide();
- }
- }
- };
- });
|