|
1 | 1 | /* global wu_setup, wu_setup_settings, ajaxurl, wu_block_ui_polyfill, _wu_block_ui_polyfill */ |
2 | 2 | (function($) { |
3 | 3 |
|
4 | | - window._wu_block_ui_polyfill = wu_block_ui_polyfill; |
| 4 | + window._wu_block_ui_polyfill = wu_block_ui_polyfill; |
5 | 5 |
|
6 | | - wu_block_ui_polyfill = function() { }; |
| 6 | + wu_block_ui_polyfill = function() { }; |
7 | 7 |
|
8 | | - $(document).ready(function() { |
| 8 | + $(document).ready(function() { |
9 | 9 |
|
10 | | - // Click button |
11 | | - // Generates queue |
12 | | - // Start to process queue items one by one |
13 | | - // Changes the status |
14 | | - // Move to the next item |
15 | | - // When all is done, redirect to the next page via a form submission |
16 | | - $('#poststuff').on('submit', 'form', function(e) { |
| 10 | + // Click button |
| 11 | + // Generates queue |
| 12 | + // Start to process queue items one by one |
| 13 | + // Changes the status |
| 14 | + // Move to the next item |
| 15 | + // When all is done, redirect to the next page via a form submission |
| 16 | + $('#poststuff').on('submit', 'form', function(e) { |
17 | 17 |
|
18 | | - e.preventDefault(); |
| 18 | + e.preventDefault(); |
19 | 19 |
|
20 | | - const $form = $(this); |
| 20 | + const $form = $(this); |
21 | 21 |
|
22 | | - const install_id = $form.find('table[data-id]').data('id'); |
| 22 | + const install_id = $form.find('table[data-id]').data('id'); |
23 | 23 |
|
24 | | - $form.find('[name=next]').attr('disabled', 'disabled'); |
| 24 | + $form.find('[name=next]').attr('disabled', 'disabled'); |
25 | 25 |
|
26 | | - let queue = $form.find('tr[data-content]'); |
| 26 | + let queue = $form.find('tr[data-content]'); |
27 | 27 |
|
28 | | - /* |
| 28 | + /* |
29 | 29 | * Only keep items selected on the queue. |
30 | 30 | */ |
31 | | - queue = queue.filter(function() { |
| 31 | + queue = queue.filter(function() { |
32 | 32 |
|
33 | | - const checkbox = $(this).find('input[type=checkbox]'); |
| 33 | + const checkbox = $(this).find('input[type=checkbox]'); |
34 | 34 |
|
35 | | - if (checkbox.length) { |
| 35 | + if (checkbox.length) { |
36 | 36 |
|
37 | | - return checkbox.is(':checked'); |
| 37 | + return checkbox.is(':checked'); |
38 | 38 |
|
39 | | - } // end if; |
| 39 | + } // end if; |
40 | 40 |
|
41 | | - return true; |
| 41 | + return true; |
42 | 42 |
|
43 | | - }); |
| 43 | + }); |
44 | 44 |
|
45 | | - let successes = 0; |
| 45 | + let successes = 0; |
46 | 46 |
|
47 | | - let index = 0; |
| 47 | + let index = 0; |
48 | 48 |
|
49 | | - process_queue_item(queue.eq(index)); |
| 49 | + process_queue_item(queue.eq(index)); |
50 | 50 |
|
51 | | - /** |
52 | | - * Process the queue items one by one recursively. |
53 | | - * |
54 | | - * @param {string} item The item to process. |
55 | | - */ |
56 | | - function process_queue_item(item) { |
| 51 | + /** |
| 52 | + * Process the queue items one by one recursively. |
| 53 | + * |
| 54 | + * @param {string} item The item to process. |
| 55 | + */ |
| 56 | + function process_queue_item(item) { |
| 57 | + |
| 58 | + window.onbeforeunload = function() { |
| 59 | + |
| 60 | + return ''; |
57 | 61 |
|
58 | | - window.onbeforeunload = function() { |
| 62 | + }; |
59 | 63 |
|
60 | | - return ''; |
| 64 | + if (item.length === 0) { |
61 | 65 |
|
62 | | - }; |
| 66 | + if (queue.length === successes || install_id === 'migration') { |
63 | 67 |
|
64 | | - if (item.length === 0) { |
| 68 | + window.onbeforeunload = null; |
65 | 69 |
|
66 | | - if (queue.length === successes || install_id === 'migration') { |
| 70 | + _wu_block_ui_polyfill($('#poststuff .inside')); |
67 | 71 |
|
68 | | - window.onbeforeunload = null; |
| 72 | + setTimeout(() => { |
69 | 73 |
|
70 | | - _wu_block_ui_polyfill($('#poststuff .inside')); |
| 74 | + $form.get(0).submit(); |
71 | 75 |
|
72 | | - setTimeout(() => { |
| 76 | + }, 100); |
73 | 77 |
|
74 | | - $form.get(0).submit(); |
| 78 | + } // end if; |
75 | 79 |
|
76 | | - }, 100); |
| 80 | + $form.find('[name=next]').removeAttr('disabled'); |
77 | 81 |
|
78 | | - } // end if; |
| 82 | + return false; |
79 | 83 |
|
80 | | - $form.find('[name=next]').removeAttr('disabled'); |
| 84 | + } // end if; |
81 | 85 |
|
82 | | - return false; |
| 86 | + const $item = $(item); |
83 | 87 |
|
84 | | - } // end if; |
| 88 | + const content = $item.data('content'); |
85 | 89 |
|
86 | | - const $item = $(item); |
| 90 | + $item.get(0).scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' }); |
87 | 91 |
|
88 | | - const content = $item.data('content'); |
| 92 | + $item.find('td.status') |
| 93 | + .attr('class', '') |
| 94 | + .addClass('status') |
| 95 | + .find('> span').html(wu_setup[ content ].installing).end() |
| 96 | + .find('.spinner').addClass('is-active').end() |
| 97 | + .find('a.help').slideUp(); |
89 | 98 |
|
90 | | - $item.get(0).scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' }); |
| 99 | + // Ajax request |
| 100 | + $.ajax({ |
| 101 | + url: ajaxurl, |
| 102 | + method: 'post', |
| 103 | + data: { |
| 104 | + action: wu_setup_settings.ajax_action || 'wu_setup_install', |
| 105 | + installer: content, |
| 106 | + 'dry-run': wu_setup_settings.dry_run, |
| 107 | + }, |
| 108 | + success(data) { |
91 | 109 |
|
92 | | - $item.find('td.status') |
93 | | - .attr('class', '') |
94 | | - .addClass('status') |
95 | | - .find('> span').html(wu_setup[content].installing).end() |
96 | | - .find('.spinner').addClass('is-active').end() |
97 | | - .find('a.help').slideUp(); |
| 110 | + if (data.success === true) { |
98 | 111 |
|
99 | | - // Ajax request |
100 | | - $.ajax({ |
101 | | - url: ajaxurl, |
102 | | - method: 'post', |
103 | | - data: { |
104 | | - action: 'wu_setup_install', |
105 | | - installer: content, |
106 | | - 'dry-run': wu_setup_settings.dry_run, |
107 | | - }, |
108 | | - success(data) { |
| 112 | + $item.find('td.status') |
| 113 | + .attr('class', '') |
| 114 | + .addClass('status wu-text-green-600') |
| 115 | + .find('> span').html(wu_setup[ content ].success).end() |
| 116 | + .find('.spinner').removeClass('is-active'); |
109 | 117 |
|
110 | | - if (data.success === true) { |
| 118 | + $item.removeAttr('data-content'); |
111 | 119 |
|
112 | | - $item.find('td.status') |
113 | | - .attr('class', '') |
114 | | - .addClass('status wu-text-green-600') |
115 | | - .find('> span').html(wu_setup[content].success).end() |
116 | | - .find('.spinner').removeClass('is-active'); |
| 120 | + successes++; |
117 | 121 |
|
118 | | - $item.removeAttr('data-content'); |
| 122 | + } else { |
119 | 123 |
|
120 | | - successes++; |
| 124 | + $item.find('td.status') |
| 125 | + .attr('class', '') |
| 126 | + .addClass('status wu-text-red-400') |
| 127 | + .find('> span').html(data.data[ 0 ].message).end() |
| 128 | + .find('.spinner').removeClass('is-active').end() |
| 129 | + .find('a.help').slideDown(); |
121 | 130 |
|
122 | | - } else { |
| 131 | + } // end if; |
123 | 132 |
|
124 | | - $item.find('td.status') |
125 | | - .attr('class', '') |
126 | | - .addClass('status wu-text-red-400') |
127 | | - .find('> span').html(data.data[0].message).end() |
128 | | - .find('.spinner').removeClass('is-active').end() |
129 | | - .find('a.help').slideDown(); |
| 133 | + index++; |
130 | 134 |
|
131 | | - } // end if; |
| 135 | + process_queue_item(queue.eq(index)); |
132 | 136 |
|
133 | | - index++; |
| 137 | + }, |
| 138 | + error(jqXHR) { |
134 | 139 |
|
135 | | - process_queue_item(queue.eq(index)); |
| 140 | + let errorMessage = wu_setup_settings.generic_error_message || 'An error occurred.'; |
136 | 141 |
|
137 | | - }, |
138 | | - error() { |
| 142 | + if (jqXHR.responseJSON && jqXHR.responseJSON.data && jqXHR.responseJSON.data[ 0 ]) { |
| 143 | + errorMessage = jqXHR.responseJSON.data[ 0 ].message || errorMessage; |
| 144 | + } |
139 | 145 |
|
140 | | - $item.find('td.status') |
141 | | - .attr('class', '') |
142 | | - .addClass('status wu-text-red-400') |
143 | | - .find('span').html('').end() |
144 | | - .find('.spinner').removeClass('is-active').end() |
145 | | - .find('a.help').slideDown(); |
| 146 | + $item.find('td.status') |
| 147 | + .attr('class', '') |
| 148 | + .addClass('status wu-text-red-400') |
| 149 | + .find('> span').html(errorMessage).end() |
| 150 | + .find('.spinner').removeClass('is-active').end() |
| 151 | + .find('a.help').slideDown(); |
146 | 152 |
|
147 | | - index++; |
| 153 | + index++; |
148 | 154 |
|
149 | | - process_queue_item(queue.eq(index)); |
| 155 | + process_queue_item(queue.eq(index)); |
150 | 156 |
|
151 | | - }, |
152 | | - }); |
| 157 | + }, |
| 158 | + }); |
153 | 159 |
|
154 | | - } // end process_queue_item; |
| 160 | + } // end process_queue_item; |
155 | 161 |
|
156 | | - }); |
| 162 | + }); |
157 | 163 |
|
158 | | - $('#poststuff [name=next]').removeAttr('disabled'); |
| 164 | + $('#poststuff [name=next]').removeAttr('disabled'); |
159 | 165 |
|
160 | | - }); |
| 166 | + }); |
161 | 167 |
|
162 | 168 | }(jQuery)); |
163 | 169 |
|
164 | 170 | if (typeof wu_initialize_tooltip !== 'function') { |
165 | 171 |
|
166 | | - const wu_initialize_tooltip = function() { |
| 172 | + const wu_initialize_tooltip = function() { |
167 | 173 |
|
168 | | - jQuery('[role="tooltip"]').tipTip({ |
169 | | - attribute: 'aria-label', |
170 | | - }); |
| 174 | + jQuery('[role="tooltip"]').tipTip({ |
| 175 | + attribute: 'aria-label', |
| 176 | + }); |
171 | 177 |
|
172 | | - }; // end wu_initialize_tooltip; |
| 178 | + }; // end wu_initialize_tooltip; |
173 | 179 |
|
174 | | - // eslint-disable-next-line no-unused-vars |
175 | | - const wu_block_ui = function(el) { |
| 180 | + // eslint-disable-next-line no-unused-vars |
| 181 | + const wu_block_ui = function(el) { |
176 | 182 |
|
177 | | - jQuery(el).wu_block({ |
178 | | - message: '<span>Please wait...</span>', |
179 | | - overlayCSS: { |
180 | | - backgroundColor: '#FFF', |
181 | | - opacity: 0.6, |
182 | | - }, |
183 | | - css: { |
184 | | - padding: 0, |
185 | | - margin: 0, |
186 | | - width: '50%', |
187 | | - fontSize: '14px !important', |
188 | | - top: '40%', |
189 | | - left: '35%', |
190 | | - textAlign: 'center', |
191 | | - color: '#000', |
192 | | - border: 'none', |
193 | | - backgroundColor: 'none', |
194 | | - cursor: 'wait', |
195 | | - }, |
196 | | - }); |
| 183 | + jQuery(el).wu_block({ |
| 184 | + message: '<span>Please wait...</span>', |
| 185 | + overlayCSS: { |
| 186 | + backgroundColor: '#FFF', |
| 187 | + opacity: 0.6, |
| 188 | + }, |
| 189 | + css: { |
| 190 | + padding: 0, |
| 191 | + margin: 0, |
| 192 | + width: '50%', |
| 193 | + fontSize: '14px !important', |
| 194 | + top: '40%', |
| 195 | + left: '35%', |
| 196 | + textAlign: 'center', |
| 197 | + color: '#000', |
| 198 | + border: 'none', |
| 199 | + backgroundColor: 'none', |
| 200 | + cursor: 'wait', |
| 201 | + }, |
| 202 | + }); |
197 | 203 |
|
198 | | - return jQuery(el); |
| 204 | + return jQuery(el); |
199 | 205 |
|
200 | | - }; |
| 206 | + }; |
201 | 207 |
|
202 | | - (function($) { |
| 208 | + (function($) { |
203 | 209 |
|
204 | | - $(document).ready(function() { |
| 210 | + $(document).ready(function() { |
205 | 211 |
|
206 | | - wu_initialize_tooltip(); |
| 212 | + wu_initialize_tooltip(); |
207 | 213 |
|
208 | | - }); |
| 214 | + }); |
209 | 215 |
|
210 | | - }(jQuery)); |
| 216 | + }(jQuery)); |
211 | 217 |
|
212 | 218 | } // end if; |
0 commit comments