PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 5.8.5
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v5.8.5
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
automatorwp / integrations / clickup / assets / js / automatorwp-clickup.js

automatorwp-clickup.js in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 5.8.5, at integrations/clickup/assets/js/automatorwp-clickup.js

361 lines 12.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function( $ ) {
2
3 var prefix = 'automatorwp-clickup-';
4 var _prefix = 'automatorwp_clickup_';
5
6 // On click authorize button
7 $('body').on('click', '.automatorwp_settings #' + _prefix + 'authorize', function(e) {
8 e.preventDefault();
9
10 var button = $(this);
11 var wrapper = button.parent();
12
13 var token = $('#' + _prefix + 'token').val();
14
15 // Check if response div exists
16 var response_wrap = wrapper.find('#' + _prefix + 'response');
17
18 if( ! response_wrap.length ) {
19 wrapper.append( '<div id="' + _prefix + 'response" style="display: none; margin-top: 10px;"></div>' );
20 response_wrap = wrapper.find('#' + _prefix + 'response');
21 }
22
23 // Show error message if not correctly configured
24 if( token.length === 0 ) {
25 response_wrap.addClass( 'automatorwp-notice-error' );
26 response_wrap.html( 'API token is required to connect with ClickUp' );
27 response_wrap.slideDown('fast');
28 return;
29 }
30
31 response_wrap.slideUp('fast');
32 response_wrap.attr('class', '');
33
34 // Show spinner
35 wrapper.append('<span class="spinner is-active" style="float: none;"></span>');
36
37 // Disable button
38 button.prop('disabled', true);
39
40 $.post(
41 ajaxurl,
42 {
43 action: 'automatorwp_clickup_authorize',
44 nonce: automatorwp_clickup.nonce,
45 token: token,
46 },
47 function( response ) {
48
49 // Add class automatorwp-notice-success on successful unlock, if not will add the class automatorwp-notice-error
50 response_wrap.addClass( 'automatorwp-notice-' + ( response.success === true ? 'success' : 'error' ) );
51 response_wrap.html( ( response.data.message !== undefined ? response.data.message : response.data ) );
52 response_wrap.slideDown('fast');
53
54 // Hide spinner
55 wrapper.find('.spinner').remove();
56
57 // Redirect on success
58 if( response.success === true && response.data.redirect_url !== undefined ) {
59 window.location = response.data.redirect_url;
60 return;
61 }
62
63
64 // Enable button
65 button.prop('disabled', false);
66
67 }
68 );
69
70
71 });
72
73 // On change team
74 $('body').on('change', '.automatorwp-action-clickup-create-list .cmb2-id-team select, '
75 + '.automatorwp-action-clickup-add-comment-task .cmb2-id-team select, '
76 + '.automatorwp-action-clickup-add-tag-task .cmb2-id-team select, '
77 + '.automatorwp-action-clickup-create-task .cmb2-id-team select, '
78 + '.automatorwp-action-clickup-remove-task .cmb2-id-team select, '
79 + '.automatorwp-action-clickup-remove-tag-task .cmb2-id-team select', function(e, first_change) {
80 var team = $(this).closest('.cmb-row');
81 var space_team = team.next('.cmb2-id-space');
82
83 var team_id = $(this).val();
84
85 if( first_change === undefined ) {
86 first_change = false;
87 }
88
89 if( team_id === 'any' || team_id === '' || team_id === null ) {
90 // Hide the term selector
91 if( first_change ) {
92 space_team.hide();
93 } else {
94 space_team.slideUp('fast');
95 }
96 } else {
97 var space_selector = space_team.find('select.select2-hidden-accessible');
98
99 // Remove Select2 element
100 space_selector.next('.select2').remove();
101
102 // Update the team (since we do not use the table attribute, lets to use it as team)
103 space_selector.data( 'table', team_id );
104
105 if( ! first_change ) {
106 // Update the the term value
107 space_selector.val('');
108 }
109
110 // Reset the selector
111 space_selector.removeAttr('data-select2-id');
112
113 // Init it again
114 automatorwp_ajax_selector( space_selector );
115
116 // Show the term selector
117 if( first_change ) {
118 space_team.show();
119 } else {
120 space_team.slideDown('fast');
121 }
122 }
123
124 });
125
126 // On change space
127 $('body').on('change', '.automatorwp-action-clickup-create-list .cmb2-id-space select, '
128 + '.automatorwp-action-clickup-add-comment-task .cmb2-id-space select, '
129 + '.automatorwp-action-clickup-add-tag-task .cmb2-id-space select, '
130 + '.automatorwp-action-clickup-create-task .cmb2-id-space select, '
131 + '.automatorwp-action-clickup-remove-task .cmb2-id-space select, '
132 + '.automatorwp-action-clickup-remove-tag-task .cmb2-id-space select', function(e, first_change) {
133 var space = $(this).closest('.cmb-row');
134
135 var folder_space = space.next('.cmb2-id-folder');
136
137 var space_id = $(this).val();
138
139 if( first_change === undefined ) {
140 first_change = false;
141 }
142
143 if( space_id === 'any' || space_id === '' || space_id === null ) {
144 // Hide the term selector
145 if( first_change ) {
146 folder_space.hide();
147 } else {
148 folder_space.slideUp('fast');
149 }
150 } else {
151 var folder_selector = folder_space.find('select.select2-hidden-accessible');
152
153 // Remove Select2 element
154 folder_selector.next('.select2').remove();
155
156 // Update the space (since we do not use the table attribute, lets to use it as space)
157 folder_selector.data( 'table', space_id );
158
159 if( ! first_change ) {
160 // Update the the term value
161 folder_selector.val('');
162 }
163
164 // Reset the selector
165 folder_selector.removeAttr('data-select2-id');
166
167 // Init it again
168 automatorwp_ajax_selector( folder_selector );
169
170 // Show the term selector
171 if( first_change ) {
172 folder_space.show();
173 } else {
174 folder_space.slideDown('fast');
175 }
176 }
177
178 });
179
180 // On change folder
181 $('body').on('change', '.automatorwp-action-clickup-create-list .cmb2-id-folder select, '
182 + '.automatorwp-action-clickup-add-comment-task .cmb2-id-folder select, '
183 + '.automatorwp-action-clickup-add-tag-task .cmb2-id-folder select, '
184 + '.automatorwp-action-clickup-create-task .cmb2-id-folder select, '
185 + '.automatorwp-action-clickup-remove-task .cmb2-id-folder select, '
186 + '.automatorwp-action-clickup-remove-tag-task .cmb2-id-folder select', function(e, first_change) {
187 var folder = $(this).closest('.cmb-row');
188 var list_folder = folder.next('.cmb2-id-list');
189
190 var folder_id = $(this).val();
191
192 if( first_change === undefined ) {
193 first_change = false;
194 }
195
196 if( folder_id === 'any' || folder_id === '' || folder_id === null ) {
197 // Hide the term selector
198 if( first_change ) {
199 list_folder.hide();
200 } else {
201 list_folder.slideUp('fast');
202 }
203 } else {
204 var list_selector = list_folder.find('select.select2-hidden-accessible');
205
206 // Remove Select2 element
207 list_selector.next('.select2').remove();
208
209 // Update the folder (since we do not use the table attribute, lets to use it as folder)
210 list_selector.data( 'table', folder_id );
211
212 // Reset the selector
213 list_selector.removeAttr('data-select2-id');
214
215 // Init it again
216 automatorwp_ajax_selector( list_selector );
217
218 // Show the term selector
219 if( first_change ) {
220 list_folder.show();
221 } else {
222 list_folder.slideDown('fast');
223 }
224 }
225
226 });
227
228 // On change list
229 $('body').on('change', '.automatorwp-action-clickup-add-comment-task .cmb2-id-list select, '
230 + '.automatorwp-action-clickup-add-tag-task .cmb2-id-list select, '
231 + '.automatorwp-action-clickup-remove-task .cmb2-id-list select, '
232 + '.automatorwp-action-clickup-remove-tag-task .cmb2-id-list select', function(e, first_change) {
233 var list = $(this).closest('.cmb-row');
234 var task_list = list.next('.cmb2-id-task');
235
236 var list_id = $(this).val();
237
238 if( first_change === undefined ) {
239 first_change = false;
240 }
241
242 if( list_id === 'any' || list_id === '' || list_id === null ) {
243 // Hide the term selector
244 if( first_change ) {
245 task_list.hide();
246 } else {
247 task_list.slideUp('fast');
248 }
249 } else {
250 var task_selector = task_list.find('select.select2-hidden-accessible');
251
252 // Remove Select2 element
253 task_selector.next('.select2').remove();
254
255 // Update the list (since we do not use the table attribute, lets to use it as list)
256 task_selector.data( 'table', list_id );
257
258 // Reset the selector
259 task_selector.removeAttr('data-select2-id');
260
261 // Init it again
262 automatorwp_ajax_selector( task_selector );
263
264 // Show the term selector
265 if( first_change ) {
266 task_list.show();
267 } else {
268 task_list.slideDown('fast');
269 }
270 }
271
272 });
273
274 // On change task
275 $('body').on('change', '.automatorwp-action-clickup-add-comment-task .cmb2-id-task select, '
276 + '.automatorwp-action-clickup-add-tag-task .cmb2-id-task select, '
277 + '.automatorwp-action-clickup-remove-task .cmb2-id-task select, '
278 + '.automatorwp-action-clickup-remove-tag-task .cmb2-id-task select', function(e, first_change) {
279 var task = $(this).closest('.cmb-row');
280 var tag_list = task.next('.cmb2-id-tag');
281
282 var task_id = $(this).val();
283
284 if( first_change === undefined ) {
285 first_change = false;
286 }
287
288 if( task_id === 'any' || task_id === '' || task_id === null ) {
289 // Hide the term selector
290 if( first_change ) {
291 tag_list.hide();
292 } else {
293 tag_list.slideUp('fast');
294 }
295 } else {
296 var tag_selector = tag_list.find('select.select2-hidden-accessible');
297
298 // Remove Select2 element
299 tag_selector.next('.select2').remove();
300
301 // Update the list (since we do not use the table attribute, lets to use it as list)
302 tag_selector.data( 'table', list_id );
303
304 // Reset the selector
305 tag_selector.removeAttr('data-select2-id');
306
307 // Init it again
308 automatorwp_ajax_selector( tag_selector );
309
310 // Show the term selector
311 if( first_change ) {
312 tag_list.show();
313 } else {
314 tag_list.slideDown('fast');
315 }
316 }
317
318 });
319
320 // On click on an option, check if form contains the team selector
321 $('body').on('click', '.automatorwp-automation-item-label > .automatorwp-option', function(e) {
322
323 var item = $(this).closest('.automatorwp-automation-item[class*="clickup"]');
324 var option = $(this).data('option');
325 var option_form = item.find('.automatorwp-option-form-container[data-option="' + option + '"]');
326
327 var team_selector = option_form.find('.cmb2-id-team');
328
329 if( team_selector !== undefined ) {
330 team_selector.find('select.select2-hidden-accessible').trigger('change', [true]);
331 }
332
333 var space_selector = option_form.find('.cmb2-id-space');
334
335 if( space_selector !== undefined ) {
336 space_selector.find('select.select2-hidden-accessible').trigger('change', [true]);
337 }
338
339 var folder_selector = option_form.find('.cmb2-id-folder');
340
341 if( folder_selector !== undefined ) {
342 folder_selector.find('select.select2-hidden-accessible').trigger('change', [true]);
343 }
344
345 var list_selector = option_form.find('.cmb2-id-list');
346
347 if( list_selector !== undefined ) {
348 list_selector.find('select.select2-hidden-accessible').trigger('change', [true]);
349 }
350
351 var task_selector = option_form.find('.cmb2-id-task');
352
353 if( task_selector !== undefined ) {
354 task_selector.find('select.select2-hidden-accessible').trigger('change', [true]);
355 }
356
357 });
358
359
360
361 })( jQuery );