Skip to content

Commit

Permalink
Moved js to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
rommmka committed Mar 31, 2023
1 parent 3420534 commit 7723730
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 22 deletions.
38 changes: 16 additions & 22 deletions Block/Adminhtml/Config/Form/Field/FixAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
<tr>
<td colspan="100">
<div class="button-container">
<button id="fix-all-themes" class="button action-configure" type="button"
onclick="jQuery.ajax({
url: '{$url}',
method: 'POST',
dataType: 'json',
showLoader: true,
data: {
form_key: window.FORM_KEY
},
success: function(data) {
alert(data.message);
jQuery('#row_swissup_core_troubleshooting_virtualcheck .themes-table table').hide();
jQuery('#fix-all-themes').hide();
jQuery('<tr><td>Please, <a href=&quot;{$cacheUrl}&quot; target=_blank>clear the cache</a></td></tr>').insertAfter('#row_swissup_core_troubleshooting_virtualcheck');
},
error: function() {
alert('An error occurred while updating theme types.');
}
})"><span>$buttonText</span></button>
<button id="fix-all-themes"
class="button action-configure"
type="button"
><span>$buttonText</span>
</button>
</div>
<script type="text/javascript">
require([
'Swissup_Core/js/virtualfix'
], function (virtualfix) {
virtualfix.init("$url", "$cacheUrl", '#fix-all-themes');
});
</script>
</td>
</tr>
HTML;
Expand Down
43 changes: 43 additions & 0 deletions view/adminhtml/web/js/virtualfix.js
Original file line number Diff line number Diff line change
@@ -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();
$('<tr><td>Success! Please, <a href="' + cacheUrl + '" target=_blank>clear the cache</a></td></tr>').insertAfter('#row_swissup_core_troubleshooting_virtualcheck');

})
.fail(function(jqXHR, textStatus, errorThrown) {
alert({
title: $.mage.__('Error'),
content: $.mage.__('An error occured: ') + errorThrown
});
});
}
}
});

0 comments on commit 7723730

Please sign in to comment.