|
3 | 3 | * Copyright © MagePal LLC. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | * http://www.magepal.com | support@magepal.com
|
6 |
| -*/ |
| 6 | + */ |
7 | 7 |
|
8 | 8 | /**
|
9 | 9 | * @var $block MagePal\CheckoutSuccessMiscScript\Block\Adminhtml\System\Config\Form\Field\MiscScript
|
10 | 10 | */
|
11 |
| - |
12 | 11 | ?>
|
13 | 12 |
|
14 | 13 | <?php
|
15 | 14 | $_htmlId = $block->getHtmlId() ? $block->getHtmlId() : '_' . uniqid();
|
16 | 15 | $_colspan = $block->isAddAfter() ? 2 : 1;
|
17 | 16 | ?>
|
18 | 17 |
|
19 |
| -<div class="design_theme_ua_regexp" id="grid<?= /* @escapeNotVerified */ $_htmlId ?>"> |
| 18 | +<div class="design_theme_ua_regexp" id="grid<?= $block->escapeHtmlAttr($_htmlId) ?>"> |
20 | 19 | <div class="admin__control-table-wrapper">
|
21 |
| - <table class="admin__control-table" id="<?= /* @escapeNotVerified */ $block->getElement()->getId() ?>"> |
| 20 | + <table class="admin__control-table" id="<?= $block->escapeHtmlAttr($block->getElement()->getId()) ?>"> |
22 | 21 | <thead>
|
23 |
| - <tr> |
24 |
| - <?php foreach ($block->getColumns() as $columnName => $column): ?> |
25 |
| - <?php if ($column['type'] != 'textarea'):?> |
26 |
| - <th><?= /* @escapeNotVerified */ $column['label'] ?></th> |
27 |
| - <?php endif; ?> |
28 |
| - <?php endforeach;?> |
29 |
| - <th class="col-actions" colspan="<?= /* @escapeNotVerified */ $_colspan ?>">Action</th> |
30 |
| - </tr> |
| 22 | + <tr> |
| 23 | + <?php foreach ($block->getColumns() as $columnName => $column) : ?> |
| 24 | + <?php if ($column['type'] != 'textarea') :?> |
| 25 | + <th><?= $block->escapeHtml($column['label']) ?></th> |
| 26 | + <?php endif; ?> |
| 27 | + <?php endforeach;?> |
| 28 | + <th class="col-actions" colspan="<?= $block->escapeHtmlAttr($_colspan) ?>"> |
| 29 | + <?= $block->escapeHtml(__('Action')); ?> |
| 30 | + </th> |
| 31 | + </tr> |
31 | 32 | </thead>
|
32 | 33 | <tfoot>
|
33 |
| - <tr> |
34 |
| - <td colspan="<?= count($block->getColumns())+$_colspan ?>" class="col-actions-add"> |
35 |
| - <button id="addToEndBtn<?= /* @escapeNotVerified */ $_htmlId ?>" class="action-add" title="<?= /* @escapeNotVerified */ __('Add') ?>" type="button"> |
36 |
| - <span><?= /* @escapeNotVerified */ $block->getAddButtonLabel() ?></span> |
37 |
| - </button> |
38 |
| - </td> |
39 |
| - </tr> |
| 34 | + <tr> |
| 35 | + <td colspan="<?= count($block->getColumns())+$_colspan ?>" class="col-actions-add"> |
| 36 | + <button id="addToEndBtn<?= $block->escapeHtmlAttr($_htmlId) ?>" |
| 37 | + class="action-add" |
| 38 | + title="<?= $block->escapeHtmlAttr(__('Add')) ?>" |
| 39 | + type="button"> |
| 40 | + <span><?= $block->escapeHtml($block->getAddButtonLabel()) ?></span> |
| 41 | + </button> |
| 42 | + </td> |
| 43 | + </tr> |
40 | 44 | </tfoot>
|
41 |
| - <tbody id="addRow<?= /* @escapeNotVerified */ $_htmlId ?>"></tbody> |
| 45 | + <tbody id="addRow<?= $block->escapeHtmlAttr($_htmlId) ?>"></tbody> |
42 | 46 | </table>
|
43 | 47 | </div>
|
44 |
| - <input type="hidden" name="<?= /* @escapeNotVerified */ $block->getElement()->getName() ?>[__empty]" value="" /> |
| 48 | + <input type="hidden" |
| 49 | + name="<?= $block->escapeHtmlAttr($block->getElement()->getName()) ?>[__empty]" |
| 50 | + value="" /> |
45 | 51 |
|
46 | 52 | <script>
|
47 | 53 | require([
|
48 | 54 | 'mage/template',
|
49 | 55 | 'jquery',
|
50 | 56 | 'prototype'
|
51 | 57 | ], function (mageTemplate, $j) {
|
52 |
| - // create row creator |
53 |
| - window.arrayRow<?= /* @escapeNotVerified */ $_htmlId ?> = { |
54 |
| - |
55 |
| - // define row prototypeJS template |
56 |
| - template: mageTemplate( |
57 |
| - '<tr id="<%- _id %>">' |
58 |
| - <?php foreach ($block->getColumns() as $columnName => $column): ?> |
59 |
| - <?php if ($column['type'] != 'textarea'):?> |
60 |
| - + '<td>' |
61 |
| - + '<?= /* @escapeNotVerified */ $block->renderCellTemplate($columnName) ?>' |
62 |
| - + '<\/td>' |
63 |
| - <?php endif; ?> |
64 |
| - <?php endforeach; ?> |
| 58 | + // create row creator |
| 59 | + window.arrayRow<?= /* @noEscape */ $_htmlId ?> = { |
| 60 | + |
| 61 | + // define row prototypeJS template |
| 62 | + template: mageTemplate( |
| 63 | + '<tr id="<%- _id %>">' |
| 64 | + <?php foreach ($block->getColumns() as $columnName => $column) : ?> |
| 65 | + <?php if ($column['type'] != 'textarea') :?> |
| 66 | + + '<td>' |
| 67 | + + '<?= /* @noEscape */ $block->renderCellTemplate($columnName) ?>' |
| 68 | + + '<\/td>' |
| 69 | + <?php endif; ?> |
| 70 | + <?php endforeach; ?> |
65 | 71 |
|
66 |
| - <?php if ($block->isAddAfter()): ?> |
67 |
| - + '<td><button class="action-add" type="button" id="addAfterBtn<%- _id %>"><span><?= /* @escapeNotVerified */ __('Add after') ?><\/span><\/button><\/td>' |
68 |
| - <?php endif; ?> |
| 72 | + <?php if ($block->isAddAfter()) : ?> |
| 73 | + + '<td><button class="action-add" type="button" id="addAfterBtn<%- _id %>"><span><?= $block->escapeHtml(__('Add after')) ?><\/span><\/button><\/td>' |
| 74 | + <?php endif; ?> |
69 | 75 |
|
70 |
| - + '<td class="col-actions"><button onclick="arrayRow<?= /* @escapeNotVerified */ $_htmlId ?>.del(\'<%- _id %>\')" class="action-delete" type="button"><span><?= /* @escapeNotVerified */ __('Delete') ?><\/span><\/button><\/td>' |
71 |
| - +'<\/tr>' |
| 76 | + + '<td class="col-actions"><button onclick="arrayRow<?= /* @noEscape */ $_htmlId ?>.del(\'<%- _id %>\')" class="action-delete" type="button"><span><?= $block->escapeHtml(__('Delete')) ?><\/span><\/button><\/td>' |
| 77 | + +'<\/tr>' |
72 | 78 |
|
73 |
| - <?php foreach ($block->getColumns() as $columnName => $column): ?> |
74 |
| - <?php if ($column['type'] == 'textarea'):?> |
75 |
| - + '<tr id="<%- _id %>"><td colspan="<?= count($block->getColumns())+$_colspan ?>">' |
76 |
| - + '<?= /* @escapeNotVerified */ $block->renderCellTemplate($columnName) ?>' |
77 |
| - + '<div><?= $block->getTemplateButtonList() ?></div>' |
78 |
| - + '<\/td></tr>' |
79 |
| - <?php endif; ?> |
80 |
| - <?php endforeach; ?> |
81 |
| - ), |
82 |
| - |
83 |
| - add: function(rowData, insertAfterId) { |
84 |
| - // generate default template data |
85 |
| - var templateValues; |
86 |
| - |
87 |
| - // Prepare template values |
88 |
| - if (rowData) { |
89 |
| - templateValues = rowData; |
90 |
| - } else { |
91 |
| - var d = new Date(); |
92 |
| - templateValues = { |
93 |
| - <?php foreach ($block->getColumns() as $columnName => $column): ?> |
94 |
| - <?= /* @escapeNotVerified */ $columnName ?> : '', |
95 |
| - 'option_extra_attrs': {}, |
| 79 | + <?php foreach ($block->getColumns() as $columnName => $column) : ?> |
| 80 | + <?php if ($column['type'] == 'textarea') :?> |
| 81 | + + '<tr id="<%- _id %>"><td colspan="<?= count($block->getColumns())+$_colspan ?>">' |
| 82 | + + '<?= /* @noEscape */ $block->renderCellTemplate($columnName) ?>' |
| 83 | + + '<div><?= /* @noEscape */ $block->getTemplateButtonList() ?></div>' |
| 84 | + + '<\/td></tr>' |
| 85 | + <?php endif; ?> |
96 | 86 | <?php endforeach; ?>
|
97 |
| - _id: '_' + d.getTime() + '_' + d.getMilliseconds() |
98 |
| - }; |
99 |
| - } |
| 87 | + ), |
| 88 | + |
| 89 | + add: function(rowData, insertAfterId) { |
| 90 | + // generate default template data |
| 91 | + var templateValues; |
| 92 | + |
| 93 | + // Prepare template values |
| 94 | + if (rowData) { |
| 95 | + templateValues = rowData; |
| 96 | + } else { |
| 97 | + var d = new Date(); |
| 98 | + templateValues = { |
| 99 | + <?php foreach ($block->getColumns() as $columnName => $column) : ?> |
| 100 | + <?= /* @noEscape */ $columnName ?> : '', |
| 101 | + 'option_extra_attrs': {}, |
| 102 | + <?php endforeach; ?> |
| 103 | + _id: '_' + d.getTime() + '_' + d.getMilliseconds() |
| 104 | + }; |
| 105 | + } |
100 | 106 |
|
101 |
| - // Insert new row after specified row or at the bottom |
102 |
| - if (insertAfterId) { |
103 |
| - Element.insert($(insertAfterId), {after: this.template(templateValues)}); |
104 |
| - } else { |
105 |
| - Element.insert($('addRow<?= /* @escapeNotVerified */ $_htmlId ?>'), {bottom: this.template(templateValues)}); |
106 |
| - } |
| 107 | + // Insert new row after specified row or at the bottom |
| 108 | + if (insertAfterId) { |
| 109 | + Element.insert($(insertAfterId), {after: this.template(templateValues)}); |
| 110 | + } else { |
| 111 | + Element.insert($('addRow<?= /* @noEscape */ $_htmlId ?>'), {bottom: this.template(templateValues)}); |
| 112 | + } |
107 | 113 |
|
108 |
| - // Fill controls with data |
109 |
| - if (rowData) { |
110 |
| - var rowInputElementNames = Object.keys(rowData.column_values); |
111 |
| - for (var i = 0; i < rowInputElementNames.length; i++) { |
112 |
| - if ($(rowInputElementNames[i])) { |
113 |
| - $(rowInputElementNames[i]).setValue(rowData.column_values[rowInputElementNames[i]]); |
| 114 | + // Fill controls with data |
| 115 | + if (rowData) { |
| 116 | + var rowInputElementNames = Object.keys(rowData.column_values); |
| 117 | + for (var i = 0; i < rowInputElementNames.length; i++) { |
| 118 | + if ($(rowInputElementNames[i])) { |
| 119 | + $(rowInputElementNames[i]).setValue(rowData.column_values[rowInputElementNames[i]]); |
| 120 | + } |
114 | 121 | }
|
115 | 122 | }
|
| 123 | + |
| 124 | + // Add event for {addAfterBtn} button |
| 125 | + <?php if ($block->isAddAfter()) : ?> |
| 126 | + Event.observe('addAfterBtn' + templateValues._id, 'click', this.add.bind(this, false, templateValues._id)); |
| 127 | + <?php endif; ?> |
| 128 | + |
| 129 | + $j('#magepal_checkout_misc_script_scripts').trigger('contentUpdated'); |
| 130 | + }, |
| 131 | + |
| 132 | + del: function(rowId) { |
| 133 | + $(rowId).remove(); |
| 134 | + $(rowId).remove(); |
116 | 135 | }
|
| 136 | + }; |
| 137 | + |
| 138 | + // bind add action to "Add" button in last row |
| 139 | + // phpcs:disable |
| 140 | + Event.observe('addToEndBtn<?= /* @noEscape */ $_htmlId ?>', 'click', arrayRow<?= /* @noEscape */ $_htmlId ?>.add.bind(arrayRow<?= /* @noEscape */ $_htmlId ?>, false, false)); |
| 141 | + // phpcs:enable |
| 142 | + |
| 143 | + // add existing rows |
| 144 | + <?php foreach ($block->getArrayRows() as $_rowId => $_row) : ?> |
| 145 | + <?= /* @noEscape */ "arrayRow{$_htmlId}.add(" . $_row->toJson() . ");\n"; ?> |
| 146 | + <?php endforeach; ?> |
117 | 147 |
|
118 |
| - // Add event for {addAfterBtn} button |
119 |
| - <?php if ($block->isAddAfter()): ?> |
120 |
| - Event.observe('addAfterBtn' + templateValues._id, 'click', this.add.bind(this, false, templateValues._id)); |
121 |
| - <?php endif; ?> |
122 |
| - |
123 |
| - $j('#magepal_checkout_misc_script_scripts').trigger('contentUpdated'); |
124 |
| - }, |
125 |
| - |
126 |
| - del: function(rowId) { |
127 |
| - $(rowId).remove(); |
128 |
| - $(rowId).remove(); |
129 |
| - } |
130 |
| - }; |
131 |
| - |
132 |
| - // bind add action to "Add" button in last row |
133 |
| - Event.observe('addToEndBtn<?= /* @escapeNotVerified */ $_htmlId ?>', 'click', arrayRow<?= /* @escapeNotVerified */ $_htmlId ?>.add.bind(arrayRow<?= /* @escapeNotVerified */ $_htmlId ?>, false, false)); |
134 |
| - |
135 |
| - // add existing rows |
136 |
| - <?php |
137 |
| - foreach ($block->getArrayRows() as $_rowId => $_row) { |
138 |
| - /* @escapeNotVerified */ echo "arrayRow{$_htmlId}.add(" . $_row->toJson() . ");\n"; |
139 |
| - } |
140 |
| - ?> |
141 |
| - |
142 |
| - // Toggle the grid availability, if element is disabled (depending on scope) |
143 |
| - <?php if ($block->getElement()->getDisabled()):?> |
144 |
| - toggleValueElements({checked: true}, $('grid<?= /* @escapeNotVerified */ $_htmlId ?>').parentNode); |
| 148 | + // Toggle the grid availability, if element is disabled (depending on scope) |
| 149 | + <?php if ($block->getElement()->getDisabled()) :?> |
| 150 | + toggleValueElements({checked: true}, $('grid<?= /* @noEscape */ $_htmlId ?>').parentNode); |
145 | 151 | <?php endif;?>
|
146 | 152 | });
|
147 | 153 | </script>
|
|
0 commit comments