JAVASCRIPT   80

backup.js

Guest on 28th July 2021 01:11:09 AM

  1. /**
  2.  * Magento
  3.  *
  4.  * NOTICE OF LICENSE
  5.  *
  6.  * This source file is subject to the Academic Free License (AFL 3.0)
  7.  * that is bundled with this package in the file LICENSE_AFL.txt.
  8.  * It is also available through the world-wide-web at this URL:
  9.  * http://opensource.org/licenses/afl-3.0.php
  10.  * If you did not receive a copy of the license and are unable to
  11.  * obtain it through the world-wide-web, please send an email
  12.  * to license@magento.com so we can send you a copy immediately.
  13.  *
  14.  * DISCLAIMER
  15.  *
  16.  * Do not edit or add to this file if you wish to upgrade Magento to newer
  17.  * versions in the future. If you wish to customize Magento for your
  18.  * needs please refer to http://www.magento.com for more information.
  19.  *
  20.  * @category    Mage
  21.  * @package     Mage_Adminhtml
  22.  * @copyright   Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  23.  * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
  24.  */
  25. var AdminBackup = new Class.create();
  26. AdminBackup.prototype = {
  27.     initialize : function(a, b){
  28.         this.reset();
  29.         this.rollbackUrl = this.backupUrl = '';
  30.         this.rollbackValidator = new Validation($('rollback-form'));
  31.         this.backupValidator = new Validation($('backup-form'));
  32.     },
  33.  
  34.     reset: function() {
  35.         this.time = 0;
  36.         this.type = '';
  37.         $('use-ftp-checkbox-row').hide();
  38.         $('use_ftp').checked = false;
  39.         $('ftp-credentials-container').hide();
  40.         $$('#ftp-credentials-container input').each(function(item) {
  41.             item.removeClassName('required-entry');
  42.         });
  43.         $('backup_maintenance_mode').checked = false;
  44.         $('rollback_maintenance_mode').checked = false;
  45.         $('exclude_media').checked = false;
  46.         $('password').value = '';
  47.         $('backup_name').value = '';
  48.         $$('.validation-advice').invoke('remove');
  49.         $$('input').invoke('removeClassName', 'validation-failed');
  50.         $$('input').invoke('removeClassName', 'validation-passed');
  51.         $$('.backup-messages').invoke('hide');
  52.         $$('#ftp-credentials-container input').each(function(item) {
  53.             item.value = '';
  54.         });
  55.     },
  56.  
  57.     backup: function(type) {
  58.         this.reset();
  59.         this.type = type;
  60.         this.showBackupWarning();
  61.         return false;
  62.     },
  63.  
  64.     rollback: function(type, time) {
  65.         this.reset();
  66.         this.time = time;
  67.         this.type = type;
  68.         this.showRollbackWarning();
  69.         return false;
  70.     },
  71.  
  72.     showBackupWarning: function() {
  73.         this.showPopup('backup-warning');
  74.     },
  75.  
  76.     showRollbackWarning: function() {
  77.         this.showPopup('rollback-warning');
  78.     },
  79.  
  80.     requestBackupOptions: function() {
  81.         this.hidePopups();
  82.         var action = this.type != 'snapshot' ? 'hide' : 'show';
  83.         $$('#exclude-media-checkbox-container').invoke(action);
  84.         this.showPopup('backup-options');
  85.     },
  86.  
  87.     requestPassword: function() {
  88.         this.hidePopups();
  89.         this.type != 'db' ? $('use-ftp-checkbox-row').show() : $('use-ftp-checkbox-row').hide();
  90.         this.showPopup('rollback-request-password');
  91.     },
  92.  
  93.     toggleFtpCredentialsForm: function() {
  94.         $('use_ftp').checked ? $('ftp-credentials-container').show()
  95.             : $('ftp-credentials-container').hide();
  96.         var divId = 'rollback-request-password';
  97.  
  98.         $$('#ftp-credentials-container input').each(function(item) {
  99.             if (item.name == 'ftp_path') return;
  100.             $('use_ftp').checked ? item.addClassName('required-entry') : item.removeClassName('required-entry');
  101.         });
  102.  
  103.         $(divId).show().setStyle({
  104.             'marginTop': -$(divId).getDimensions().height / 2 + 'px'
  105.         });
  106.     },
  107.  
  108.     submitBackup: function () {
  109.         if (!!this.backupValidator && this.backupValidator.validate()) {
  110.             this.hidePopups();
  111.             var data = {
  112.                 'type': this.type,
  113.                 'maintenance_mode': $('backup_maintenance_mode').checked ? 1 : 0,
  114.                 'backup_name': $('backup_name').value,
  115.                 'exclude_media': $('exclude_media').checked ? 1 : 0
  116.             };
  117.  
  118.             new Ajax.Request(this.backupUrl, {
  119.                 onSuccess: function(transport) {
  120.                     this.processResponse(transport, 'backup-options');
  121.                 }.bind(this),
  122.                 method: 'post',
  123.                 parameters: data
  124.             });
  125.         }
  126.         return false;
  127.     },
  128.  
  129.     submitRollback: function() {
  130.         if (!!this.rollbackValidator && this.rollbackValidator.validate()) {
  131.             var data = this.getPostData();
  132.             this.hidePopups();
  133.             new Ajax.Request(this.rollbackUrl, {
  134.                 onSuccess: function(transport) {
  135.                     this.processResponse(transport, 'rollback-request-password');
  136.                 }.bind(this),
  137.                 method: 'post',
  138.                 parameters: data
  139.             });
  140.         }
  141.         return false;
  142.     },
  143.  
  144.     processResponse: function(transport, popupId) {
  145.         if (!transport.responseText.isJSON()) {
  146.             return;
  147.         }
  148.  
  149.         var json = transport.responseText.evalJSON();
  150.  
  151.         if (!!json.error) {
  152.             this.displayError(popupId, json.error);
  153.             this.showPopup(popupId);
  154.             return;
  155.         }
  156.  
  157.         if (!!json.redirect_url) {
  158.             setLocation(json.redirect_url);
  159.         }
  160.     },
  161.  
  162.     displayError: function(parentContainer, message) {
  163.         var messageHtml = this.getErrorMessageHtml(message);
  164.         $$('#' + parentContainer + ' .backup-messages .messages').invoke('update', messageHtml);
  165.         $$('#' + parentContainer + ' .backup-messages').invoke('show');
  166.     },
  167.  
  168.     getErrorMessageHtml: function(message) {
  169.         return '<li class="error-msg"><ul><li><span>' + message + '</span></li></ul></li>';
  170.     },
  171.  
  172.     getPostData: function() {
  173.         var data = $('rollback-form').serialize(true);
  174.         data['time'] = this.time;
  175.         data['type'] = this.type;
  176.         return data;
  177.     },
  178.  
  179.     showPopup: function(divId) {
  180.         $(divId).show().setStyle({
  181.             'marginTop': -$(divId).getDimensions().height / 2 + 'px'
  182.         });
  183.         $('popup-window-mask').setStyle({
  184.             height: $('html-body').getHeight() + 'px'
  185.         }).show();
  186.     },
  187.  
  188.     hidePopups: function() {
  189.         $$('.backup-dialog').each(Element.hide);
  190.         $('popup-window-mask').hide();
  191.     }
  192. }

Raw Paste


Login or Register to edit or fork this paste. It's free.