|
10 | 10 | require([
|
11 | 11 | 'jquery',
|
12 | 12 | 'Magento_Ui/js/modal/alert',
|
| 13 | + 'Magento_Ui/js/modal/confirm', |
13 | 14 | "jquery/ui",
|
14 | 15 | 'mage/multiselect',
|
15 | 16 | "mage/mage",
|
16 | 17 | 'Magento_Ui/js/modal/modal'
|
17 |
| -], function($, alert){ |
| 18 | +], function($, alert, confirm) { |
18 | 19 |
|
19 | 20 | $.widget("adminhtml.dialogRates", $.mage.modal, {
|
20 | 21 | options: {
|
@@ -160,53 +161,58 @@ require([
|
160 | 161 | taxRateField.find('.mselect-list')
|
161 | 162 | .on('click.mselect-edit', '.mselect-edit', this.edit)
|
162 | 163 | .on("click.mselect-delete", ".mselect-delete", function () {
|
163 |
| - if (!confirm('<?= $block->escapeJs(__('Do you really want to delete this tax rate?')) ?>')) { |
164 |
| - return; |
165 |
| - } |
166 |
| - |
167 | 164 | var that = $(this),
|
168 | 165 | select = that.closest('.mselect-list').prev(),
|
169 | 166 | rateValue = that.parent().find('input[type="checkbox"]').val();
|
170 | 167 |
|
171 |
| - $('body').trigger('processStart'); |
172 |
| - var ajaxOptions = { |
173 |
| - type: 'POST', |
174 |
| - data: { |
175 |
| - tax_calculation_rate_id: rateValue, |
176 |
| - form_key: $('input[name="form_key"]').val() |
177 |
| - }, |
178 |
| - dataType: 'json', |
179 |
| - url: '<?= $block->escapeJs($block->escapeUrl($block->getTaxRateDeleteUrl())) ?>', |
180 |
| - success: function(result, status) { |
181 |
| - $('body').trigger('processStop'); |
182 |
| - if (result.success) { |
183 |
| - that.parent().remove(); |
184 |
| - select.find('option').each(function() { |
185 |
| - if (this.value === rateValue) { |
186 |
| - $(this).remove(); |
| 168 | + confirm({ |
| 169 | + content: '<?= $block->escapeJs(__('Do you really want to delete this tax rate?')) ?>', |
| 170 | + actions: { |
| 171 | + /** |
| 172 | + * Confirm action. |
| 173 | + */ |
| 174 | + confirm: function () { |
| 175 | + $('body').trigger('processStart'); |
| 176 | + var ajaxOptions = { |
| 177 | + type: 'POST', |
| 178 | + data: { |
| 179 | + tax_calculation_rate_id: rateValue, |
| 180 | + form_key: $('input[name="form_key"]').val() |
| 181 | + }, |
| 182 | + dataType: 'json', |
| 183 | + url: '<?= $block->escapeJs($block->escapeUrl($block->getTaxRateDeleteUrl())) ?>', |
| 184 | + success: function(result, status) { |
| 185 | + $('body').trigger('processStop'); |
| 186 | + if (result.success) { |
| 187 | + that.parent().remove(); |
| 188 | + select.find('option').each(function() { |
| 189 | + if (this.value === rateValue) { |
| 190 | + $(this).remove(); |
| 191 | + } |
| 192 | + }); |
| 193 | + select.trigger('change.hiddenSelect'); |
| 194 | + } else { |
| 195 | + if (result.error_message) |
| 196 | + alert({ |
| 197 | + content: result.error_message |
| 198 | + }); |
| 199 | + else |
| 200 | + alert({ |
| 201 | + content: '<?= $block->escapeJs($block->escapeHtml(__('An error occurred'))) ?>' |
| 202 | + }); |
| 203 | + } |
| 204 | + }, |
| 205 | + error: function () { |
| 206 | + $('body').trigger('processStop'); |
| 207 | + alert({ |
| 208 | + content: '<?= $block->escapeJs($block->escapeHtml(__('An error occurred'))) ?>' |
| 209 | + }); |
187 | 210 | }
|
188 |
| - }); |
189 |
| - select.trigger('change.hiddenSelect'); |
190 |
| - } else { |
191 |
| - if (result.error_message) |
192 |
| - alert({ |
193 |
| - content: result.error_message |
194 |
| - }); |
195 |
| - else |
196 |
| - alert({ |
197 |
| - content: '<?= $block->escapeJs($block->escapeHtml(__('An error occurred'))) ?>' |
198 |
| - }); |
| 211 | + }; |
| 212 | + $.ajax(ajaxOptions); |
199 | 213 | }
|
200 |
| - }, |
201 |
| - error: function () { |
202 |
| - $('body').trigger('processStop'); |
203 |
| - alert({ |
204 |
| - content: '<?= $block->escapeJs($block->escapeHtml(__('An error occurred'))) ?>' |
205 |
| - }); |
206 | 214 | }
|
207 |
| - }; |
208 |
| - $.ajax(ajaxOptions); |
209 |
| - |
| 215 | + }); |
210 | 216 | })
|
211 | 217 | .on('click.mselectAdd', '.mselect-button-add', function () {
|
212 | 218 | taxRateForm
|
|
0 commit comments