From 772373083bab345de2aa63d997576fb0ec23ea98 Mon Sep 17 00:00:00 2001 From: rommmka Date: Fri, 31 Mar 2023 10:55:27 +0300 Subject: [PATCH] Moved js to separate file --- Block/Adminhtml/Config/Form/Field/FixAll.php | 38 ++++++++--------- view/adminhtml/web/js/virtualfix.js | 43 ++++++++++++++++++++ 2 files changed, 59 insertions(+), 22 deletions(-) create mode 100644 view/adminhtml/web/js/virtualfix.js diff --git a/Block/Adminhtml/Config/Form/Field/FixAll.php b/Block/Adminhtml/Config/Form/Field/FixAll.php index e015242..506b032 100644 --- a/Block/Adminhtml/Config/Form/Field/FixAll.php +++ b/Block/Adminhtml/Config/Form/Field/FixAll.php @@ -8,34 +8,28 @@ class FixAll extends \Magento\Config\Block\System\Config\Form\Field public function render(AbstractElement $element) { - $url = $this->_urlBuilder->getUrl('swissup/theme/fixAll'); - $cacheUrl = $this->getUrl('adminhtml/cache/index');; + $url = $this->getUrl('swissup/theme/fixAll'); + $cacheUrl = $this->getUrl('adminhtml/cache/index'); $buttonText = __("Fix All"); return <<
- +
+ + + HTML; diff --git a/view/adminhtml/web/js/virtualfix.js b/view/adminhtml/web/js/virtualfix.js new file mode 100644 index 0000000..ac8cfc1 --- /dev/null +++ b/view/adminhtml/web/js/virtualfix.js @@ -0,0 +1,43 @@ +define([ + 'jquery', + 'Magento_Ui/js/modal/alert', +], function ($, alert) { + 'use strict'; + + var self, url, cacheUrl; + + return { + init: function(ajaxCallUrl, cacheUrlPath, assignBtn) { + self = this; + url = ajaxCallUrl; + cacheUrl = cacheUrlPath; + + $(assignBtn).on('click', function() { + self.virtualfix(); + }); + }, + virtualfix: function() { + $.ajax({ + url: url, + method: 'POST', + dataType: 'json', + showLoader: true, + data: { + form_key: window.FORM_KEY + } + }) + .done(function(data) { + $('#row_swissup_core_troubleshooting_virtualcheck .themes-table table').hide(); + $('#fix-all-themes').hide(); + $('Success! Please, clear the cache').insertAfter('#row_swissup_core_troubleshooting_virtualcheck'); + + }) + .fail(function(jqXHR, textStatus, errorThrown) { + alert({ + title: $.mage.__('Error'), + content: $.mage.__('An error occured: ') + errorThrown + }); + }); + } + } +});