Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/aimogen-pro/scripts/assistants.js

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + "use strict";
2 + function aiomaticLoading2(btn){
3 + btn.attr('disabled','disabled');
4 + if(!btn.find('spinner').length){
5 + btn.append('<span class="spinner"></span>');
6 + }
7 + btn.find('.spinner').css('visibility','unset');
8 + }
9 + function aiomaticRmLoading(btn)
10 + {
11 + btn.removeAttr('disabled');
12 + btn.find('.spinner').remove();
13 + }
14 + jQuery(document).ready(function()
15 + {
16 + jQuery('input#aiomatic_media_clear_new').on('click', function(e)
17 + {
18 + e.preventDefault();
19 + jQuery('input#aiomatic_image_id_new').val('0');
20 + jQuery('#aiomatic-preview-image-new').removeAttr('src');
21 + jQuery('#aiomatic-preview-image-new').removeAttr('srcset');
22 + jQuery('#aiomatic-preview-image-new').removeAttr('width');
23 + jQuery('#aiomatic-preview-image-new').removeAttr('height');
24 + jQuery('#aiomatic-preview-image-new').removeAttr('sizes');
25 + jQuery('#aiomatic-preview-image-new').removeAttr('loading');
26 + jQuery('#aiomatic-preview-image-new').removeAttr('decoding');
27 + jQuery('#aiomatic-preview-image-new').removeAttr('alt');
28 + jQuery('#aiomatic-preview-image-new').removeAttr('class');
29 + });
30 + jQuery('body').on('click', '#aiomatic_media_clear_new-edit', function(e)
31 + {
32 + e.preventDefault();
33 + jQuery('input#aiomatic_image_id_new-edit').val('0');
34 + jQuery('#aiomatic-preview-image-new-edit').removeAttr('src');
35 + jQuery('#aiomatic-preview-image-new-edit').removeAttr('srcset');
36 + jQuery('#aiomatic-preview-image-new-edit').removeAttr('width');
37 + jQuery('#aiomatic-preview-image-new-edit').removeAttr('height');
38 + jQuery('#aiomatic-preview-image-new-edit').removeAttr('sizes');
39 + jQuery('#aiomatic-preview-image-new-edit').removeAttr('loading');
40 + jQuery('#aiomatic-preview-image-new-edit').removeAttr('decoding');
41 + jQuery('#aiomatic-preview-image-new-edit').removeAttr('alt');
42 + jQuery('#aiomatic-preview-image-new-edit').removeAttr('class');
43 + });
44 + jQuery('input#aiomatic_media_manager_new').on('click', function(e) {
45 + e.preventDefault();
46 + var image_frame;
47 + if(image_frame){
48 + image_frame.open();
49 + }
50 + image_frame = wp.media({
51 + title: 'Select Media',
52 + multiple : false,
53 + library : {
54 + type : 'image',
55 + }
56 + });
57 + image_frame.on('close',function() {
58 + var selection = image_frame.state().get('selection');
59 + var gallery_ids = new Array();
60 + var my_index = 0;
61 + selection.each(function(attachment) {
62 + gallery_ids[my_index] = attachment['id'];
63 + my_index++;
64 + });
65 + var ids = gallery_ids.join(",");
66 + if(ids.length === 0) return true;
67 + jQuery('input#aiomatic_image_id_new').val(ids);
68 + Refresh_Image_New(ids);
69 + });
70 + image_frame.on('open',function() {
71 + var selection = image_frame.state().get('selection');
72 + var ids = jQuery('input#aiomatic_image_id_new').val().split(',');
73 + ids.forEach(function(id) {
74 + var attachment = wp.media.attachment(id);
75 + attachment.fetch();
76 + selection.add( attachment ? [ attachment ] : [] );
77 + });
78 + });
79 + image_frame.open();
80 + });
81 + jQuery('input.god_mode-edit-checkbox').on('change', function(e) {
82 + e.preventDefault();
83 + var god_mode = '0';
84 + var dalle = '0';
85 + var stable = '0';
86 + var midjourney = '0';
87 + var replicate = '0';
88 + var ideogram = '0';
89 + var amazon = '0';
90 + var amazon_details = '0';
91 + var booking = '0';
92 + var scraper = '0';
93 + var rss = '0';
94 + var google = '0';
95 + var captions = '0';
96 + var royalty = '0';
97 + var youtube = '0';
98 + var email = '0';
99 + var facebook = '0';
100 + var facebook_image = '0';
101 + var end = '0';
102 + var twitter = '0';
103 + var instagram = '0';
104 + var pinterest = '0';
105 + var business = '0';
106 + var youtube_community = '0';
107 + var reddit = '0';
108 + var linkedin = '0';
109 + var webhook = '0';
110 + var stable_video = '0';
111 + var database = '0';
112 + var lead_capture = '0';
113 + var ai = '0';
114 + var chart = '0';
115 + var threads = '0';
116 + var toubiz = '0';
117 + var google_image = '0';
118 + var omniblock = '0';
119 + if(jQuery('#function_god_mode-edit').is(":checked"))
120 + {
121 + god_mode = '1';
122 + }
123 + if(jQuery('#function_chart-edit').is(":checked"))
124 + {
125 + chart = '1';
126 + }
127 + if(jQuery('#function_dalle-edit').is(":checked"))
128 + {
129 + dalle = '1';
130 + }
131 + if(jQuery('#function_stable-edit').is(":checked"))
132 + {
133 + stable = '1';
134 + }
135 + if(jQuery('#function_midjourney-edit').is(":checked"))
136 + {
137 + midjourney = '1';
138 + }
139 + if(jQuery('#function_replicate-edit').is(":checked"))
140 + {
141 + replicate = '1';
142 + }
143 + if(jQuery('#function_ideogram-edit').is(":checked"))
144 + {
145 + ideogram = '1';
146 + }
147 + if(jQuery('#function_amazon-edit').is(":checked"))
148 + {
149 + amazon = '1';
150 + }
151 + if(jQuery('#function_amazon_details-edit').is(":checked"))
152 + {
153 + amazon_details = '1';
154 + }
155 + if(jQuery('#function_booking-edit').is(":checked"))
156 + {
157 + booking = '1';
158 + }
159 + if(jQuery('#function_toubiz-edit').is(":checked"))
160 + {
161 + toubiz = '1';
162 + }
163 + if(jQuery('#function_scraper-edit').is(":checked"))
164 + {
165 + scraper = '1';
166 + }
167 + if(jQuery('#function_rss-edit').is(":checked"))
168 + {
169 + rss = '1';
170 + }
171 + if(jQuery('#function_google-edit').is(":checked"))
172 + {
173 + google = '1';
174 + }
175 + if(jQuery('#function_captions-edit').is(":checked"))
176 + {
177 + captions = '1';
178 + }
179 + if(jQuery('#function_royalty-edit').is(":checked"))
180 + {
181 + royalty = '1';
182 + }
183 + if(jQuery('#function_youtube-edit').is(":checked"))
184 + {
185 + youtube = '1';
186 + }
187 + if(jQuery('#function_email-edit').is(":checked"))
188 + {
189 + email = '1';
190 + }
191 + if(jQuery('#function_facebook-edit').is(":checked"))
192 + {
193 + facebook = '1';
194 + }
195 + if(jQuery('#function_facebook_image-edit').is(":checked"))
196 + {
197 + facebook_image = '1';
198 + }
199 + if(jQuery('#function_end-edit').is(":checked"))
200 + {
201 + end = '1';
202 + }
203 + if(jQuery('#function_twitter-edit').is(":checked"))
204 + {
205 + twitter = '1';
206 + }
207 + if(jQuery('#function_threads-edit').is(":checked"))
208 + {
209 + threads = '1';
210 + }
211 + if(jQuery('#function_instagram-edit').is(":checked"))
212 + {
213 + instagram = '1';
214 + }
215 + if(jQuery('#function_pinterest-edit').is(":checked"))
216 + {
217 + pinterest = '1';
218 + }
219 + if(jQuery('#function_business-edit').is(":checked"))
220 + {
221 + business = '1';
222 + }
223 + if(jQuery('#function_youtube_community-edit').is(":checked"))
224 + {
225 + youtube_community = '1';
226 + }
227 + if(jQuery('#function_reddit-edit').is(":checked"))
228 + {
229 + reddit = '1';
230 + }
231 + if(jQuery('#function_linkedin-edit').is(":checked"))
232 + {
233 + linkedin = '1';
234 + }
235 + if(jQuery('#function_webhook-edit').is(":checked"))
236 + {
237 + webhook = '1';
238 + }
239 + if(jQuery('#function_ai-edit').is(":checked"))
240 + {
241 + ai = '1';
242 + }
243 + if(jQuery('#function_stable_video-edit').is(":checked"))
244 + {
245 + stable_video = '1';
246 + }
247 + if(jQuery('#function_google_image-edit').is(":checked"))
248 + {
249 + google_image = '1';
250 + }
251 + if(jQuery('#function_database-edit').is(":checked"))
252 + {
253 + database = '1';
254 + }
255 + if(jQuery('#function_omniblock-edit').is(":checked"))
256 + {
257 + omniblock = '1';
258 + }
259 + if(jQuery('#function_lead_capture-edit').is(":checked"))
260 + {
261 + lead_capture = '1';
262 + }
263 + jQuery.ajax({
264 + url: aiomatic_object.ajax_url,
265 + data: {action: 'aiomatic_get_god_mode_function', god_mode: god_mode, omniblock: omniblock, chart: chart, end: end, lead_capture: lead_capture, ai: ai, stable_video: stable_video, google_image: google_image, database: database, webhook: webhook, linkedin: linkedin, reddit: reddit, youtube_community: youtube_community, business: business, pinterest: pinterest, instagram: instagram, twitter: twitter, threads: threads, facebook_image: facebook_image, facebook: facebook, dalle: dalle, stable: stable, midjourney: midjourney, replicate: replicate, ideogram: ideogram, amazon: amazon, amazon_details: amazon_details, booking:booking, scraper: scraper, rss: rss, google: google, captions: captions, royalty: royalty, youtube: youtube, email: email, toubiz: toubiz, nonce: aiomatic_object.nonce},
266 + type: 'POST',
267 + success: function (res)
268 + {
269 + if (res.status !== 'success')
270 + {
271 + alert('Error in processing: ' + JSON.stringify(res));
272 + }
273 + else
274 + {
275 + var god_json = res.json;
276 + jQuery('#aiomatic-assistant-functions-edit').val(god_json);
277 + }
278 + },
279 + error: function (r, s, error) {
280 + alert('Error in processing file sync: ' + error);
281 + }
282 + });
283 + });
284 + jQuery('input#aiomatic_god_mode_new_disable-edit').on('click', function(e) {
285 + e.preventDefault();
286 + var god_json = `[]`;
287 + jQuery('#aiomatic-assistant-functions-edit').val(god_json);
288 + jQuery(".god_mode-edit-checkbox").prop("checked", false);
289 + });
290 + jQuery('input.god_mode-checkbox').on('change', function(e) {
291 + e.preventDefault();
292 + var god_mode = '0';
293 + var dalle = '0';
294 + var stable = '0';
295 + var midjourney = '0';
296 + var replicate = '0';
297 + var ideogram = '0';
298 + var amazon = '0';
299 + var amazon_details = '0';
300 + var booking = '0';
301 + var scraper = '0';
302 + var rss = '0';
303 + var google = '0';
304 + var captions = '0';
305 + var royalty = '0';
306 + var youtube = '0';
307 + var email = '0';
308 + var facebook = '0';
309 + var facebook_image = '0';
310 + var end = '0';
311 + var twitter = '0';
312 + var instagram = '0';
313 + var pinterest = '0';
314 + var business = '0';
315 + var youtube_community = '0';
316 + var reddit = '0';
317 + var linkedin = '0';
318 + var webhook = '0';
319 + var stable_video = '0';
320 + var google_image = '0';
321 + var database = '0';
322 + var lead_capture = '0';
323 + var ai = '0';
324 + var chart = '0';
325 + var threads = '0';
326 + var toubiz = '0';
327 + var omniblock = '0';
328 + if(jQuery('#function_god_mode').is(":checked"))
329 + {
330 + god_mode = '1';
331 + }
332 + if(jQuery('#function_dalle').is(":checked"))
333 + {
334 + dalle = '1';
335 + }
336 + if(jQuery('#function_chart').is(":checked"))
337 + {
338 + chart = '1';
339 + }
340 + if(jQuery('#function_stable').is(":checked"))
341 + {
342 + stable = '1';
343 + }
344 + if(jQuery('#function_midjourney').is(":checked"))
345 + {
346 + midjourney = '1';
347 + }
348 + if(jQuery('#function_replicate').is(":checked"))
349 + {
350 + replicate = '1';
351 + }
352 + if(jQuery('#function_ideogram').is(":checked"))
353 + {
354 + ideogram = '1';
355 + }
356 + if(jQuery('#function_amazon').is(":checked"))
357 + {
358 + amazon = '1';
359 + }
360 + if(jQuery('#function_amazon_details').is(":checked"))
361 + {
362 + amazon_details = '1';
363 + }
364 + if(jQuery('#function_booking').is(":checked"))
365 + {
366 + booking = '1';
367 + }
368 + if(jQuery('#function_toubiz').is(":checked"))
369 + {
370 + toubiz = '1';
371 + }
372 + if(jQuery('#function_scraper').is(":checked"))
373 + {
374 + scraper = '1';
375 + }
376 + if(jQuery('#function_rss').is(":checked"))
377 + {
378 + rss = '1';
379 + }
380 + if(jQuery('#function_google').is(":checked"))
381 + {
382 + google = '1';
383 + }
384 + if(jQuery('#function_captions').is(":checked"))
385 + {
386 + captions = '1';
387 + }
388 + if(jQuery('#function_royalty').is(":checked"))
389 + {
390 + royalty = '1';
391 + }
392 + if(jQuery('#function_youtube').is(":checked"))
393 + {
394 + youtube = '1';
395 + }
396 + if(jQuery('#function_omniblock').is(":checked"))
397 + {
398 + omniblock = '1';
399 + }
400 + if(jQuery('#function_email').is(":checked"))
401 + {
402 + email = '1';
403 + }
404 + if(jQuery('#function_facebook').is(":checked"))
405 + {
406 + facebook = '1';
407 + }
408 + if(jQuery('#function_facebook_image').is(":checked"))
409 + {
410 + facebook_image = '1';
411 + }
412 + if(jQuery('#function_end').is(":checked"))
413 + {
414 + end = '1';
415 + }
416 + if(jQuery('#function_twitter').is(":checked"))
417 + {
418 + twitter = '1';
419 + }
420 + if(jQuery('#function_threads').is(":checked"))
421 + {
422 + threads = '1';
423 + }
424 + if(jQuery('#function_instagram').is(":checked"))
425 + {
426 + instagram = '1';
427 + }
428 + if(jQuery('#function_pinterest').is(":checked"))
429 + {
430 + pinterest = '1';
431 + }
432 + if(jQuery('#function_business').is(":checked"))
433 + {
434 + business = '1';
435 + }
436 + if(jQuery('#function_youtube_community').is(":checked"))
437 + {
438 + youtube_community = '1';
439 + }
440 + if(jQuery('#function_reddit').is(":checked"))
441 + {
442 + reddit = '1';
443 + }
444 + if(jQuery('#function_linkedin').is(":checked"))
445 + {
446 + linkedin = '1';
447 + }
448 + if(jQuery('#function_ai').is(":checked"))
449 + {
450 + ai = '1';
451 + }
452 + if(jQuery('#function_webhook').is(":checked"))
453 + {
454 + webhook = '1';
455 + }
456 + if(jQuery('#function_stable_video').is(":checked"))
457 + {
458 + stable_video = '1';
459 + }
460 + if(jQuery('#function_google_image').is(":checked"))
461 + {
462 + google_image = '1';
463 + }
464 + if(jQuery('#function_database').is(":checked"))
465 + {
466 + database = '1';
467 + }
468 + if(jQuery('#function_lead_capture').is(":checked"))
469 + {
470 + lead_capture = '1';
471 + }
472 + jQuery.ajax({
473 + url: aiomatic_object.ajax_url,
474 + data: {action: 'aiomatic_get_god_mode_function', god_mode: god_mode, chart: chart, end: end, omniblock: omniblock, lead_capture: lead_capture, ai: ai, database: database, stable_video: stable_video, google_image:google_image, midjourney: midjourney, replicate: replicate, ideogram: ideogram, webhook: webhook, linkedin: linkedin, reddit: reddit, youtube_community: youtube_community, business: business, pinterest: pinterest, instagram: instagram, threads: threads, twitter: twitter, facebook_image: facebook_image, facebook: facebook, dalle: dalle, stable: stable, amazon: amazon, amazon_details: amazon_details, booking:booking, scraper: scraper, rss: rss, google: google, captions: captions, royalty: royalty, youtube: youtube, email: email, toubiz: toubiz, nonce: aiomatic_object.nonce},
475 + type: 'POST',
476 + success: function (res)
477 + {
478 + if (res.status !== 'success')
479 + {
480 + alert('Error in processing: ' + JSON.stringify(res));
481 + }
482 + else
483 + {
484 + var god_json = res.json;
485 + jQuery('#aiomatic-assistant-functions').val(god_json);
486 + }
487 + },
488 + error: function (r, s, error) {
489 + alert('Error in processing file sync: ' + error);
490 + }
491 + });
492 + });
493 + jQuery('input#aiomatic_god_mode_new_disable').on('click', function(e) {
494 + e.preventDefault();
495 + var god_json = `[]`;
496 + jQuery('#aiomatic-assistant-functions').val(god_json);
497 + jQuery(".god_mode-checkbox").prop("checked", false);
498 + });
499 + jQuery('input#aiomatic_media_manager_new-edit').on('click', function(e) {
500 + e.preventDefault();
501 + var image_frame;
502 + if(image_frame){
503 + image_frame.open();
504 + }
505 + image_frame = wp.media({
506 + title: 'Select Media',
507 + multiple : false,
508 + library : {
509 + type : 'image',
510 + }
511 + });
512 + image_frame.on('close',function() {
513 + var selection = image_frame.state().get('selection');
514 + var gallery_ids = new Array();
515 + var my_index = 0;
516 + selection.each(function(attachment) {
517 + gallery_ids[my_index] = attachment['id'];
518 + my_index++;
519 + });
520 + var ids = gallery_ids.join(",");
521 + if(ids.length === 0) return true;
522 + jQuery('input#aiomatic_image_id_new-edit').val(ids);
523 + Refresh_Image_Edit(ids);
524 + });
525 + image_frame.on('open',function() {
526 + var selection = image_frame.state().get('selection');
527 + var ids = jQuery('input#aiomatic_image_id_new-edit').val().split(',');
528 + ids.forEach(function(id) {
529 + var attachment = wp.media.attachment(id);
530 + attachment.fetch();
531 + selection.add( attachment ? [ attachment ] : [] );
532 + });
533 + });
534 + image_frame.open();
535 + });
536 + function Refresh_Image_New(the_id){
537 + var data = {
538 + action: 'aiomatic_get_image',
539 + id: the_id,
540 + nonce: aiomatic_object.singlenonce
541 + };
542 + jQuery.get(ajaxurl, data, function(response) {
543 + if(response.success === true) {
544 + response.data.image = response.data.image.replace('aiomatic-preview-image', 'aiomatic-preview-image-new');
545 + jQuery('#aiomatic-preview-image-new').replaceWith( response.data.image );
546 + }
547 + });
548 + }
549 + function Refresh_Image_Edit(the_id){
550 + var data = {
551 + action: 'aiomatic_get_image',
552 + id: the_id,
553 + nonce: aiomatic_object.singlenonce
554 + };
555 + jQuery.get(ajaxurl, data, function(response) {
556 + if(response.success === true) {
557 + response.data.image = response.data.image.replace('aiomatic-preview-image', 'aiomatic-preview-image-new-edit');
558 + jQuery('#aiomatic-preview-image-new-edit').replaceWith( response.data.image );
559 + }
560 + });
561 + }
562 + function timeConverter(UNIX_timestamp){
563 + var a = new Date(UNIX_timestamp * 1000);
564 + var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
565 + var year = a.getFullYear();
566 + var month = months[a.getMonth()];
567 + var date = a.getDate();
568 + var hour = a.getHours() < 10 ? '0' + a.getHours() : a.getHours();
569 + var min = a.getMinutes() < 10 ? '0' + a.getMinutes() : a.getMinutes();
570 + var sec = a.getSeconds() < 10 ? '0' + a.getSeconds() : a.getSeconds();
571 + var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
572 + return time;
573 + }
574 + jQuery('body').on('click', '.aiomatic_download_file', function() {
575 + var dataID = jQuery(this).attr('data-id');
576 + if(dataID != '')
577 + {
578 + var btn = jQuery(this);
579 + jQuery.ajax({
580 + url: aiomatic_object.ajax_url,
581 + data: {action: 'aiomatic_download_file', id: dataID, nonce: aiomatic_object.nonce},
582 + type: 'POST',
583 + beforeSend: function () {
584 + aiomaticAjaxRunning = true;
585 + aiomaticLoading2(btn);
586 + },
587 + success: function (res) {
588 + aiomaticAjaxRunning = false;
589 + aiomaticRmLoading(btn);
590 + if (res.status !== 'success')
591 + {
592 + alert('Error in processing: ' + JSON.stringify(res));
593 + }
594 + else
595 + {
596 + var hiddenElement = document.createElement('a');
597 + hiddenElement.href = 'data:attachment/text,' + encodeURI(res.data);
598 + hiddenElement.target = '_blank';
599 + hiddenElement.download = res.filename;
600 + hiddenElement.click();
601 + }
602 + },
603 + error: function (r, s, error) {
604 + aiomaticAjaxRunning = false;
605 + aiomaticRmLoading(btn);
606 + alert('Error in processing file sync: ' + error);
607 + }
608 + });
609 + }
610 + else
611 + {
612 + alert('Empty data-id provided');
613 + }
614 + });
615 + jQuery('body').on('click', '.aiomatic_delete_file', function() {
616 + var dataID = jQuery(this).attr('data-id');
617 + if(dataID != '')
618 + {
619 + var btn = jQuery(this);
620 + jQuery.ajax({
621 + url: aiomatic_object.ajax_url,
622 + data: {action: 'aiomatic_delete_assistant_file', id: dataID, nonce: aiomatic_object.nonce},
623 + type: 'POST',
624 + beforeSend: function () {
625 + aiomaticAjaxRunning = true;
626 + aiomaticLoading2(btn);
627 + },
628 + success: function (res) {
629 + aiomaticAjaxRunning = false;
630 + aiomaticRmLoading(btn);
631 + if (res.status !== 'success')
632 + {
633 + alert('Error in processing: ' + JSON.stringify(res));
634 + }
635 + else
636 + {
637 + location.reload();
638 + }
639 + },
640 + error: function (r, s, error) {
641 + aiomaticAjaxRunning = false;
642 + aiomaticRmLoading(btn);
643 + alert('Error in processing file sync: ' + error);
644 + }
645 + });
646 + }
647 + else
648 + {
649 + alert('Empty data-id provided');
650 + }
651 + });
652 + jQuery('body').on('click', '#aiomatic_file_button', function() {
653 + var aiomatic_file_upload = jQuery('#aiomatic_assistant_file_upload');
654 + if(aiomatic_file_upload[0].files.length === 0){
655 + alert('Please select a file!');
656 + }
657 + else{
658 + var aiomatic_max_file_size = aiomatic_object.maxfilesize;
659 + var aiomatic_max_size_in_mb = aiomatic_object.maxfilesize / (1024 ** 2);
660 + var aiomatic_progress = jQuery('.aiomatic_progress');
661 + var aiomatic_file_button = jQuery('#aiomatic_file_button');
662 + var aiomatic_file = aiomatic_file_upload[0].files[0];
663 + var aiomatic_upload_success = jQuery('.aiomatic_upload_success');
664 + var aiomatic_error_message = jQuery('.aiomatic-error-msg');
665 + if(aiomatic_file.size > aiomatic_max_file_size){
666 + aiomatic_file_upload.val('');
667 + alert('Dataset allowed maximum size (MB): '+ aiomatic_max_size_in_mb)
668 + }
669 + else{
670 + var formData = new FormData();
671 + formData.append('action', 'aiomatic_assistant_file_upload');
672 + formData.append('file', aiomatic_file);
673 + formData.append('nonce', aiomatic_object.nonce);
674 + jQuery.ajax({
675 + url: aiomatic_object.ajax_url,
676 + type: 'POST',
677 + dataType: 'JSON',
678 + data: formData,
679 + beforeSend: function (){
680 + aiomatic_progress.find('span').css('width','0');
681 + aiomatic_progress.show();
682 + aiomaticLoading2(aiomatic_file_button);
683 + aiomatic_error_message.hide();
684 + aiomatic_upload_success.hide();
685 + },
686 + xhr: function() {
687 + var xhr = jQuery.ajaxSettings.xhr();
688 + xhr.upload.addEventListener("progress", function(evt) {
689 + if (evt.lengthComputable) {
690 + var percentComplete = evt.loaded / evt.total;
691 + aiomatic_progress.find('span').css('width',(Math.round(percentComplete * 100))+'%');
692 + }
693 + }, false);
694 + return xhr;
695 + },
696 + success: function(res) {
697 + if(res.status === 'success'){
698 + aiomaticRmLoading(aiomatic_file_button);
699 + aiomatic_progress.hide();
700 + aiomatic_file_upload.val('');
701 + aiomatic_upload_success.show();
702 + location.reload();
703 + }
704 + else{
705 + aiomaticRmLoading(aiomatic_file_button);
706 + aiomatic_progress.find('small').html('Error');
707 + aiomatic_progress.addClass('aiomatic_error');
708 + aiomatic_error_message.html(res.msg);
709 + aiomatic_error_message.show();
710 + }
711 + },
712 + cache: false,
713 + contentType: false,
714 + processData: false,
715 + error: function (r, s, error){
716 + aiomatic_file_upload.val('');
717 + aiomaticRmLoading(aiomatic_file_button);
718 + aiomatic_progress.addClass('aiomatic_error');
719 + aiomatic_progress.find('small').html('Error');
720 + alert('Error in processing finetune uploading: ' + error);
721 + aiomatic_error_message.show();
722 + }
723 + });
724 + }
725 + }
726 + });
727 + var assistent_files = [];
728 + var aiomaticAjaxRunning = false;
729 + jQuery('#aiomatic_sync_assistant_files').on('click', function (e){
730 + e.preventDefault();
731 + jQuery("#aiomatic-assistants-files > tbody").empty();
732 + var btn = jQuery(this);
733 + if(!aiomaticAjaxRunning) {
734 + jQuery.ajax({
735 + url: aiomatic_object.ajax_url,
736 + data: {action: 'aiomatic_list_assistant_files', nonce: aiomatic_object.nonce},
737 + dataType: 'JSON',
738 + type: 'POST',
739 + beforeSend: function () {
740 + aiomaticAjaxRunning = true;
741 + aiomaticLoading2(btn);
742 + },
743 + success: function (res) {
744 + aiomaticAjaxRunning = false;
745 + aiomaticRmLoading(btn);
746 + if (res.status === 'success')
747 + {
748 + assistent_files = res.data;
749 + res.data.forEach(async (tfile) => {
750 + var appendme = '<tr><td>' + tfile.id + '</td><td>' + tfile.bytes + '</td><td>' + tfile.purpose + '</td><td>' + timeConverter(tfile.created_at) + '</td><td>' + tfile.filename + '</td><td>' + tfile.status + '</td><td><button data-id="' + tfile.id + '" class="button button-small aiomatic_download_file"';
751 + if(tfile.purpose == 'assistants')
752 + {
753 + appendme += ' disabled';
754 + }
755 + appendme += '>Download</button><button data-id="' + tfile.id + '" class="button button-small button-link-delete aiomatic_delete_file">Delete</button></td></tr>';
756 + jQuery('#aiomatic-assistants-files > tbody:last-child').append(appendme);
757 + });
758 + aiomatic_refresh_options();
759 + } else {
760 + alert(res.msg);
761 + }
762 + },
763 + error: function (r, s, error) {
764 + aiomaticAjaxRunning = false;
765 + aiomaticRmLoading(btn);
766 + alert('Error in processing file sync: ' + error);
767 + }
768 + });
769 + }
770 + });
771 + jQuery( "#aiomatic_sync_assistant_files" ).trigger( "click" );
772 + function aiomatic_refresh_options()
773 + {
774 + assistent_files.forEach(async (tfile) => {
775 + jQuery("#aiomatic-assistant-files").append(jQuery('<option>', {
776 + value: tfile.id,
777 + text: tfile.filename + ' (' + tfile.id + ')'
778 + }));
779 + });
780 + assistent_files.forEach(async (tfile) => {
781 + jQuery("#aiomatic-assistant-files-edit").append(jQuery('<option>', {
782 + value: tfile.id,
783 + text: tfile.filename + ' (' + tfile.id + ')'
784 + }));
785 + });
786 + }
787 + jQuery(document).on('change', '#aiomatic-assistant-model', function (e) {
788 + var model = jQuery('#aiomatic-assistant-model').val();
789 + if(aiomatic_object.retrival_models.includes(model))
790 + {
791 + jQuery('#aiomatic-assistant-file_search').prop('disabled', false);
792 + }
793 + else
794 + {
795 + jQuery('#aiomatic-assistant-file_search').prop('disabled', true);
796 + jQuery("#aiomatic-assistant-file_search").prop("checked", false);
797 + }
798 + });
799 + jQuery(document).on('change', '#aiomatic-assistant-model-edit', function (e) {
800 + var model = jQuery('#aiomatic-assistant-model-edit').val();
801 + if(aiomatic_object.retrival_models.includes(model))
802 + {
803 + jQuery('#aiomatic-assistant-file_search-edit').prop('disabled', false);
804 + }
805 + else
806 + {
807 + jQuery('#aiomatic-assistant-file_search-edit').prop('disabled', true);
808 + jQuery("#aiomatic-assistant-file_search-edit").prop("checked", false);
809 + }
810 + });
811 + jQuery(document).on('change', '#aiomatic-assistant-code-interpreter', function (e) {
812 + if(jQuery("#aiomatic-assistant-code-interpreter").is(':checked') || jQuery("#aiomatic-assistant-file_search").is(':checked'))
813 + {
814 + jQuery('#aiomatic-assistant-files').prop('disabled', false);
815 + }
816 + else
817 + {
818 + jQuery('#aiomatic-assistant-files').prop('disabled', true);
819 + }
820 + });
821 + jQuery(document).on('change', '#aiomatic-assistant-file_search', function (e) {
822 + if(jQuery("#aiomatic-assistant-code-interpreter").is(':checked') || jQuery("#aiomatic-assistant-file_search").is(':checked'))
823 + {
824 + jQuery('#aiomatic-assistant-files').prop('disabled', false);
825 + }
826 + else
827 + {
828 + jQuery('#aiomatic-assistant-files').prop('disabled', true);
829 + }
830 + });
831 + jQuery(document).on('change', '#aiomatic-assistant-code-interpreter-edit', function (e) {
832 + if(jQuery("#aiomatic-assistant-code-interpreter-edit").is(':checked') || jQuery("#aiomatic-assistant-file_search-edit").is(':checked'))
833 + {
834 + jQuery('#aiomatic-assistant-files-edit').prop('disabled', false);
835 + }
836 + else
837 + {
838 + jQuery('#aiomatic-assistant-files-edit').prop('disabled', true);
839 + }
840 + });
841 + jQuery(document).on('change', '#aiomatic-assistant-file_search-edit', function (e) {
842 + if(jQuery("#aiomatic-assistant-code-interpreter-edit").is(':checked') || jQuery("#aiomatic-assistant-file_search-edit").is(':checked'))
843 + {
844 + jQuery('#aiomatic-assistant-files-edit').prop('disabled', false);
845 + }
846 + else
847 + {
848 + jQuery('#aiomatic-assistant-files-edit').prop('disabled', true);
849 + }
850 + });
851 + jQuery('#aiomatic-assistant-model').trigger("change");
852 + jQuery('#aiomatic-assistant-model-edit').trigger("change");
853 + jQuery('#aiomatic_sync_assistants').on('click', function (e)
854 + {
855 + e.preventDefault();
856 + if(confirm('Are you sure you want to sync assistants with OpenAI?'))
857 + {
858 + var btn = jQuery(this);
859 + aiomaticLoading2(btn);
860 + var data = {
861 + action: 'aiomatic_sync_assistants',
862 + nonce: aiomatic_object.nonce,
863 + };
864 + jQuery.ajax({
865 + url: aiomatic_object.ajax_url,
866 + data: data,
867 + dataType: 'JSON',
868 + type: 'POST',
869 + success: function (res){
870 + aiomaticRmLoading(btn);
871 + if(res.status === 'success'){
872 + jQuery('.aiomatic-assistants-success').show();
873 + jQuery('.aiomatic-assistants-content').val('');
874 + setTimeout(function (){
875 + jQuery('.aiomatic-assistants-success').hide();
876 + },2000);
877 + location.reload();
878 + }
879 + else{
880 + alert(res.msg);
881 + }
882 + },
883 + error: function (r, s, error){
884 + aiomaticRmLoading(btn);
885 + alert('Error in processing assistant sync: ' + error);
886 + }
887 + });
888 + }
889 + });
890 + jQuery('#aiomatic_delete_selected_assistants').on('click', function (e){
891 + e.preventDefault();
892 + if(confirm('Are you sure you want to delete selected assistants?'))
893 + {
894 + var btn = jQuery(this);
895 + aiomaticLoading2(btn);
896 + var ids = [];
897 + jQuery('.aiomatic-select-assistant:checked').each(function (idx, item) {
898 + ids.push(jQuery(item).val())
899 + });
900 + if (ids.length) {
901 + var data = {
902 + action: 'aiomatic_delete_selected_assistants',
903 + nonce: aiomatic_object.nonce,
904 + ids: ids
905 + };
906 + jQuery.ajax({
907 + url: aiomatic_object.ajax_url,
908 + data: data,
909 + dataType: 'JSON',
910 + type: 'POST',
911 + success: function (res){
912 + aiomaticRmLoading(btn);
913 + if(res.status === 'success'){
914 + jQuery('.aiomatic-assistants-success').show();
915 + jQuery('.aiomatic-assistants-content').val('');
916 + setTimeout(function (){
917 + jQuery('.aiomatic-assistants-success').hide();
918 + },2000);
919 + location.reload();
920 + }
921 + else{
922 + alert(res.msg);
923 + }
924 + },
925 + error: function (r, s, error){
926 + aiomaticRmLoading(btn);
927 + alert('Error in processing assistant removal selected: ' + error);
928 + }
929 + });
930 + } else {
931 + alert('No assistants selected');
932 + aiomaticRmLoading(btn);
933 + }
934 + }
935 + });
936 + jQuery(".aiomatic_edit_assistant").on('click', function(e) {
937 + e.preventDefault();
938 + var assistantid = jQuery(this).attr("edit-id");
939 + if(assistantid == '')
940 + {
941 + alert('Incorrect edit id submitted');
942 + }
943 + else
944 + {
945 + document.getElementById('mymodalfzr-edit').style.display = "block";
946 + jQuery('#assistant_id').val(assistantid);
947 + var data = {
948 + action: 'aiomatic_get_assistant',
949 + assistantid: assistantid,
950 + nonce: aiomatic_object.nonce,
951 + };
952 + jQuery.ajax({
953 + url: aiomatic_object.ajax_url,
954 + data: data,
955 + dataType: 'JSON',
956 + type: 'POST',
957 + success: function (res){
958 + if(res.status === 'success'){
959 + if(res.data !== undefined)
960 + {
961 + if(res.data['vector_store_id'] != '')
962 + {
963 + jQuery('#aiomatic-assistant-vector-store-edit').text('Vectore Store ID: ' + res.data['vector_store_id']);
964 + }
965 + jQuery('#aiomatic-assistant-title-edit').val(res.data['post_title']);
966 + jQuery('#aiomatic-assistant-prompt-edit').val(res.data['post_content']);
967 + jQuery('#aiomatic-assistant-description-edit').val(res.data['post_excerpt']);
968 + jQuery('#aiomatic-assistant-temperature-edit').val(res.data['temperature']);
969 + jQuery('#aiomatic-assistant-topp-edit').val(res.data['topp']);
970 + jQuery("#aiomatic-assistant-model-edit").val(res.data['assistant_model']).change();
971 + jQuery('#aiomatic-assistant-first-message-edit').val(res.data['assistant_first_message']);
972 + jQuery('#aiomatic-assistant-files-edit').val(res.data['assistant_files']);
973 + if(res.data['featured_image'] > 0)
974 + {
975 + jQuery('input#aiomatic_image_id_new-edit').val(res.data['featured_image']);
976 + Refresh_Image_Edit(res.data['featured_image']);
977 + }
978 + else
979 + {
980 + jQuery('input#aiomatic_image_id_new-edit').val('');
981 + Refresh_Image_Edit('');
982 + }
983 + var functions_str = JSON.stringify(res.data['functions'],null,2);
984 + if(functions_str.includes('aiomatic_wp_god_mode'))
985 + {
986 + jQuery("#function_god_mode-edit").prop( "checked", true );
987 + }
988 + if(functions_str.includes('aiomatic_chart'))
989 + {
990 + jQuery("#function_chart-edit").prop( "checked", true );
991 + }
992 + if(functions_str.includes('aiomatic_end'))
993 + {
994 + jQuery("#function_end-edit").prop( "checked", true );
995 + }
996 + if(functions_str.includes('aiomatic_image'))
997 + {
998 + jQuery("#function_dalle-edit").prop( "checked", true );
999 + }
1000 + if(functions_str.includes('aiomatic_stable_image'))
1001 + {
1002 + jQuery("#function_stable-edit").prop( "checked", true );
1003 + }
1004 + if(functions_str.includes('aiomatic_midjourney_image'))
1005 + {
1006 + jQuery("#function_midjourney-edit").prop( "checked", true );
1007 + }
1008 + if(functions_str.includes('aiomatic_replicate_image'))
1009 + {
1010 + jQuery("#function_replicate-edit").prop( "checked", true );
1011 + }
1012 + if(functions_str.includes('aiomatic_ideogram_image'))
1013 + {
1014 + jQuery("#function_ideogram-edit").prop( "checked", true );
1015 + }
1016 + if(functions_str.includes('aiomatic_stable_video'))
1017 + {
1018 + jQuery("#function_stable_video-edit").prop( "checked", true );
1019 + }
1020 + if(functions_str.includes('aiomatic_google_image'))
1021 + {
1022 + jQuery("#function_google_image-edit").prop( "checked", true );
1023 + }
1024 + if(functions_str.includes('aiomatic_database'))
1025 + {
1026 + jQuery("#function_database-edit").prop( "checked", true );
1027 + }
1028 + if(functions_str.includes('aiomatic_omniblock'))
1029 + {
1030 + jQuery("#function_omniblock-edit").prop( "checked", true );
1031 + }
1032 + if(functions_str.includes('aiomatic_lead_capture'))
1033 + {
1034 + jQuery("#function_lead_capture-edit").prop( "checked", true );
1035 + }
1036 + if(functions_str.includes('aiomatic_amazon_listing'))
1037 + {
1038 + jQuery("#function_amazon-edit").prop( "checked", true );
1039 + }
1040 + if(functions_str.includes('aiomatic_amazon_product_details'))
1041 + {
1042 + jQuery("#function_amazon_details-edit").prop( "checked", true );
1043 + }
1044 + if(functions_str.includes('aiomatic_booking'))
1045 + {
1046 + jQuery("#function_booking-edit").prop( "checked", true );
1047 + }
1048 + if(functions_str.includes('aiomatic_website_scraper'))
1049 + {
1050 + jQuery("#function_scraper-edit").prop( "checked", true );
1051 + }
1052 + if(functions_str.includes('aiomatic_rss_parser'))
1053 + {
1054 + jQuery("#function_rss-edit").prop( "checked", true );
1055 + }
1056 + if(functions_str.includes('aiomatic_google_parser'))
1057 + {
1058 + jQuery("#function_google-edit").prop( "checked", true );
1059 + }
1060 + if(functions_str.includes('aiomatic_royalty_free_image'))
1061 + {
1062 + jQuery("#function_royalty-edit").prop( "checked", true );
1063 + }
1064 + if(functions_str.includes('aiomatic_youtube_captions'))
1065 + {
1066 + jQuery("#function_captions-edit").prop( "checked", true );
1067 + }
1068 + if(functions_str.includes('aiomatic_youtube_search'))
1069 + {
1070 + jQuery("#function_youtube-edit").prop( "checked", true );
1071 + }
1072 + if(functions_str.includes('aiomatic_send_email'))
1073 + {
1074 + jQuery("#function_email-edit").prop( "checked", true );
1075 + }
1076 + if(functions_str.includes('aiomatic_webhook'))
1077 + {
1078 + jQuery("#function_webhook-edit").prop( "checked", true );
1079 + }
1080 + if(functions_str.includes('aiomatic_toubiz'))
1081 + {
1082 + jQuery("#function_toubiz-edit").prop( "checked", true );
1083 + }
1084 + if(functions_str.includes('aiomatic_generate_reasoning'))
1085 + {
1086 + jQuery("#function_ai-edit").prop( "checked", true );
1087 + }
1088 + if(functions_str.includes('aiomatic_publish_facebook'))
1089 + {
1090 + jQuery("#function_facebook-edit").prop( "checked", true );
1091 + }
1092 + if(functions_str.includes('aiomatic_publish_image_facebook'))
1093 + {
1094 + jQuery("#function_facebook_image-edit").prop( "checked", true );
1095 + }
1096 + if(functions_str.includes('aiomatic_publish_twitter'))
1097 + {
1098 + jQuery("#function_twitter-edit").prop( "checked", true );
1099 + }
1100 + if(functions_str.includes('aiomatic_publish_threads'))
1101 + {
1102 + jQuery("#function_threads-edit").prop( "checked", true );
1103 + }
1104 + if(functions_str.includes('aiomatic_publish_instagram'))
1105 + {
1106 + jQuery("#function_instagram-edit").prop( "checked", true );
1107 + }
1108 + if(functions_str.includes('aiomatic_publish_pinterest'))
1109 + {
1110 + jQuery("#function_pinterest-edit").prop( "checked", true );
1111 + }
1112 + if(functions_str.includes('aiomatic_publish_google_my_business'))
1113 + {
1114 + jQuery("#function_business-edit").prop( "checked", true );
1115 + }
1116 + if(functions_str.includes('aiomatic_publish_youtube_community'))
1117 + {
1118 + jQuery("#function_youtube_community-edit").prop( "checked", true );
1119 + }
1120 + if(functions_str.includes('aiomatic_publish_reddit'))
1121 + {
1122 + jQuery("#function_reddit-edit").prop( "checked", true );
1123 + }
1124 + if(functions_str.includes('aiomatic_publish_linkedin'))
1125 + {
1126 + jQuery("#function_linkedin-edit").prop( "checked", true );
1127 + }
1128 + jQuery('#aiomatic-assistant-functions-edit').val(functions_str);
1129 + if(res.data['code_interpreter'] == true)
1130 + {
1131 + jQuery("#aiomatic-assistant-code-interpreter-edit").prop( "checked", true );
1132 + }
1133 + else
1134 + {
1135 + jQuery("#aiomatic-assistant-code-interpreter-edit").prop( "checked", false );
1136 + }
1137 + if(res.data['file_search'] == true)
1138 + {
1139 + jQuery("#aiomatic-assistant-file_search-edit").prop( "checked", true );
1140 + }
1141 + else
1142 + {
1143 + jQuery("#aiomatic-assistant-file_search-edit").prop( "checked", false );
1144 + }
1145 + jQuery('#aiomatic-assistant-code-interpreter-edit').trigger("change");
1146 + }
1147 + else
1148 + {
1149 + alert('Incorrect response from the back end!');
1150 + }
1151 + }
1152 + else{
1153 + alert(res.msg);
1154 + }
1155 + },
1156 + error: function (r, s, error){
1157 + alert('Error in processing assistant editing: ' + error);
1158 + }
1159 + });
1160 + }
1161 + });
1162 + jQuery(".aiomatic_sync_assistant").on('click', function(e) {
1163 + e.preventDefault();
1164 + var assistantid = jQuery(this).attr("sync-id");
1165 + if(assistantid == '')
1166 + {
1167 + alert('Incorrect sync id submitted');
1168 + }
1169 + else
1170 + {
1171 + var data = {
1172 + action: 'aiomatic_sync_assistant',
1173 + assistantid: assistantid,
1174 + nonce: aiomatic_object.nonce,
1175 + };
1176 + jQuery.ajax({
1177 + url: aiomatic_object.ajax_url,
1178 + data: data,
1179 + dataType: 'JSON',
1180 + type: 'POST',
1181 + beforeSend: function (){
1182 + aiomaticLoading2(jQuery('#aiomatic_sync_assistant_' + assistantid));
1183 + },
1184 + success: function (res){
1185 + if(res.status === 'success'){
1186 + location.reload();
1187 + }
1188 + else{
1189 + alert(res.msg);
1190 + }
1191 + },
1192 + error: function (r, s, error){
1193 + alert('Error in processing assistant sync by id: ' + error);
1194 + }
1195 + });
1196 + }
1197 + });
1198 + jQuery(".aiomatic_delete_assistant").on('click', function(e) {
1199 + e.preventDefault();
1200 + if(confirm('Are you sure you want to delete this assistant?'))
1201 + {
1202 + var assistantid = jQuery(this).attr("delete-id");
1203 + if(assistantid == '')
1204 + {
1205 + alert('Incorrect delete id submitted');
1206 + }
1207 + else
1208 + {
1209 + e.preventDefault();
1210 + var data = {
1211 + action: 'aiomatic_delete_assistant',
1212 + assistantid: assistantid,
1213 + nonce: aiomatic_object.nonce,
1214 + };
1215 + jQuery.ajax({
1216 + url: aiomatic_object.ajax_url,
1217 + data: data,
1218 + dataType: 'JSON',
1219 + type: 'POST',
1220 + beforeSend: function (){
1221 + aiomaticLoading2(jQuery('#aiomatic_delete_assistant_' + assistantid));
1222 + },
1223 + success: function (res){
1224 + if(res.status === 'success'){
1225 + location.reload();
1226 + }
1227 + else{
1228 + alert(res.msg);
1229 + location.reload();
1230 + }
1231 + },
1232 + error: function (r, s, error){
1233 + alert('Error in processing assistant deletion: ' + error);
1234 + location.reload();
1235 + }
1236 + });
1237 + }
1238 + }
1239 + });
1240 + jQuery(".aiomatic_convert_assistant").on('click', function(e) {
1241 + e.preventDefault();
1242 + if(confirm('Are you sure you want to convert this to persona?'))
1243 + {
1244 + var assistantid = jQuery(this).attr("conv-id");
1245 + if(assistantid == '')
1246 + {
1247 + alert('Incorrect convert id submitted');
1248 + }
1249 + else
1250 + {
1251 + e.preventDefault();
1252 + var data = {
1253 + action: 'aiomatic_convert_assistant',
1254 + assistantid: assistantid,
1255 + nonce: aiomatic_object.nonce,
1256 + };
1257 + jQuery.ajax({
1258 + url: aiomatic_object.ajax_url,
1259 + data: data,
1260 + dataType: 'JSON',
1261 + type: 'POST',
1262 + beforeSend: function (){
1263 + aiomaticLoading2(jQuery('#aiomatic_convert_assistant_' + assistantid));
1264 + },
1265 + success: function (res){
1266 + if(res.status === 'success'){
1267 + aiomaticRmLoading(jQuery('#aiomatic_convert_assistant_' + assistantid));
1268 + alert('AI Assistant successfully converted to persona. Check the "Bot Persona Manager" tab in the "AI Chatbot" menu for details.')
1269 + }
1270 + else{
1271 + alert(res.msg);
1272 + location.reload();
1273 + }
1274 + },
1275 + error: function (r, s, error){
1276 + alert('Error in processing assistant conversion: ' + error);
1277 + location.reload();
1278 + }
1279 + });
1280 + }
1281 + }
1282 + });
1283 + jQuery(".aiomatic_duplicate_assistant").on('click', function(e) {
1284 + e.preventDefault();
1285 + if(confirm('Are you sure you want to duplicate this assistant?'))
1286 + {
1287 + var assistantid = jQuery(this).attr("dup-id");
1288 + if(assistantid == '')
1289 + {
1290 + alert('Incorrect duplicate id submitted');
1291 + }
1292 + else
1293 + {
1294 + e.preventDefault();
1295 + var data = {
1296 + action: 'aiomatic_duplicate_assistant',
1297 + assistantid: assistantid,
1298 + nonce: aiomatic_object.nonce,
1299 + };
1300 + jQuery.ajax({
1301 + url: aiomatic_object.ajax_url,
1302 + data: data,
1303 + dataType: 'JSON',
1304 + type: 'POST',
1305 + beforeSend: function (){
1306 + aiomaticLoading2(jQuery('#aiomatic_duplicate_assistant_' + assistantid));
1307 + },
1308 + success: function (res){
1309 + if(res.status === 'success'){
1310 + location.reload();
1311 + }
1312 + else{
1313 + alert(res.msg);
1314 + location.reload();
1315 + }
1316 + },
1317 + error: function (r, s, error){
1318 + alert('Error in processing assistant duplication: ' + error);
1319 + location.reload();
1320 + }
1321 + });
1322 + }
1323 + }
1324 + });
1325 + jQuery('#aiomatic_deleteall_assistants').on('click', function (e){
1326 + e.preventDefault();
1327 + if(confirm('Are you sure you want to delete ALL assistants?'))
1328 + {
1329 + var btn = jQuery(this);
1330 + aiomaticLoading2(btn);
1331 + var data = {
1332 + action: 'aiomatic_deleteall_assistants',
1333 + nonce: aiomatic_object.nonce,
1334 + };
1335 + jQuery.ajax({
1336 + url: aiomatic_object.ajax_url,
1337 + data: data,
1338 + dataType: 'JSON',
1339 + type: 'POST',
1340 + success: function (res){
1341 + aiomaticRmLoading(btn);
1342 + if(res.status === 'success'){
1343 + jQuery('.aiomatic-assistants-success').show();
1344 + jQuery('.aiomatic-assistants-content').val('');
1345 + setTimeout(function (){
1346 + jQuery('.aiomatic-assistants-success').hide();
1347 + },2000);
1348 + location.reload();
1349 + }
1350 + else{
1351 + alert(res.msg);
1352 + }
1353 + },
1354 + error: function (r, s, error){
1355 + aiomaticRmLoading(btn);
1356 + alert('Error in processing assistant removal (all): ' + error);
1357 + }
1358 + });
1359 + }
1360 + });
1361 + jQuery('#aiomatic_assistants_form').on('submit', function (e)
1362 + {
1363 + e.preventDefault();
1364 + var form = jQuery('#aiomatic_assistants_form');
1365 + var btn = form.find('#aiomatic-assistants-save-button');
1366 + var title = jQuery('#aiomatic-assistant-title').val();
1367 + if(title === ''){
1368 + alert('Please insert all required values!');
1369 + }
1370 + else{
1371 + var data = form.serialize();
1372 + jQuery.ajax({
1373 + url: aiomatic_object.ajax_url,
1374 + data: data,
1375 + dataType: 'JSON',
1376 + type: 'POST',
1377 + beforeSend: function (){
1378 + aiomaticLoading2(btn);
1379 + },
1380 + success: function (res){
1381 + aiomaticRmLoading(btn);
1382 + if(res.status === 'success'){
1383 + jQuery('.aiomatic-assistants-success').html("Assistant saved successfully!");
1384 + jQuery('.aiomatic-assistants-success').show();
1385 + location.reload();
1386 + }
1387 + else{
1388 + alert(res.msg);
1389 + }
1390 + },
1391 + error: function (r, s, error){
1392 + aiomaticRmLoading(btn);
1393 + alert('Error in processing assistant saving: ' + error);
1394 + }
1395 + });
1396 + }
1397 + return false;
1398 + });
1399 +
1400 + jQuery('#aiomatic_assistants_form-edit').on('submit', function (e)
1401 + {
1402 + e.preventDefault();
1403 + var form = jQuery('#aiomatic_assistants_form-edit');
1404 + var btn = form.find('#aiomatic-assistants-save-button-edit');
1405 + var title = jQuery('#aiomatic-assistant-title-edit').val();
1406 + if(title === ''){
1407 + alert('Please insert all required values!');
1408 + }
1409 + else{
1410 + var data = form.serialize();
1411 + jQuery.ajax({
1412 + url: aiomatic_object.ajax_url,
1413 + data: data,
1414 + dataType: 'JSON',
1415 + type: 'POST',
1416 + beforeSend: function (){
1417 + aiomaticLoading2(btn);
1418 + },
1419 + success: function (res){
1420 + aiomaticRmLoading(btn);
1421 + if(res.status === 'success'){
1422 + jQuery('.aiomatic-assistants-success').html("Assistant updated successfully!");
1423 + jQuery('.aiomatic-assistants-success').show();
1424 + location.reload();
1425 + }
1426 + else{
1427 + alert(res.msg);
1428 + }
1429 + },
1430 + error: function (r, s, error){
1431 + aiomaticRmLoading(btn);
1432 + alert('Error in processing assistant saving: ' + error);
1433 + }
1434 + });
1435 + }
1436 + return false;
1437 + });
1438 + var aiomatic_assistant_button = jQuery('#aiomatic_assistant_button');
1439 + aiomatic_assistant_button.on('click', function (e){
1440 + e.preventDefault();
1441 + if(confirm('Are you sure you want to load assistants from file?'))
1442 + {
1443 + var aiomatic_assistant_upload = jQuery('#aiomatic_assistant_upload');
1444 + if(jQuery("#aiomatic_overwrite").is(':checked'))
1445 + {
1446 + var overwrite = '1';
1447 + }
1448 + else
1449 + {
1450 + var overwrite = '0';
1451 + }
1452 + if(aiomatic_assistant_upload[0].files.length === 0){
1453 + alert('Please select a file!');
1454 + }
1455 + else{
1456 + var aiomatic_progress = jQuery('.aiomatic_progress');
1457 + var aiomatic_error_message = jQuery('.aiomatic-error-msg');
1458 + var aiomatic_upload_success = jQuery('.aiomatic_upload_success');
1459 + var aiomatic_max_file_size = aiomatic_object.maxfilesize;
1460 + var aiomatic_max_size_in_mb = aiomatic_object.maxfilesize / (1024 ** 2);
1461 + var aiomatic_assistant_file = aiomatic_assistant_upload[0].files[0];
1462 + var aiomatic_assistant_file_extension = aiomatic_assistant_file.name.substr( (aiomatic_assistant_file.name.lastIndexOf('.') +1) );
1463 + if(aiomatic_assistant_file_extension !== 'json'){
1464 + aiomatic_assistant_upload.val('');
1465 + alert('This feature only accepts JSON file type!');
1466 + }
1467 + else if(aiomatic_assistant_file.size > aiomatic_max_file_size){
1468 + aiomatic_assistant_upload.val('');
1469 + alert('Dataset allowed maximum size (MB): '+ aiomatic_max_size_in_mb)
1470 + }
1471 + else{
1472 + var formData = new FormData();
1473 + formData.append('action', 'aiomatic_assistant_upload');
1474 + formData.append('nonce', aiomatic_object.nonce);
1475 + formData.append('overwrite', overwrite);
1476 + formData.append('file', aiomatic_assistant_file);
1477 + jQuery.ajax({
1478 + url: aiomatic_object.ajax_url,
1479 + type: 'POST',
1480 + dataType: 'JSON',
1481 + data: formData,
1482 + beforeSend: function (){
1483 + aiomatic_progress.find('span').css('width','0');
1484 + aiomatic_progress.show();
1485 + aiomaticLoading2(aiomatic_assistant_button);
1486 + aiomatic_error_message.hide();
1487 + aiomatic_upload_success.hide();
1488 + },
1489 + xhr: function() {
1490 + var xhr = jQuery.ajaxSettings.xhr();
1491 + xhr.upload.addEventListener("progress", function(evt) {
1492 + if (evt.lengthComputable) {
1493 + var percentComplete = evt.loaded / evt.total;
1494 + aiomatic_progress.find('span').css('width',(Math.round(percentComplete * 100))+'%');
1495 + }
1496 + }, false);
1497 + return xhr;
1498 + },
1499 + success: function(res) {
1500 + if(res.status === 'success'){
1501 + aiomaticRmLoading(aiomatic_assistant_button);
1502 + aiomatic_progress.hide();
1503 + aiomatic_assistant_upload.val('');
1504 + aiomatic_upload_success.show();
1505 + location.reload();
1506 + }
1507 + else{
1508 + aiomaticRmLoading(aiomatic_assistant_button);
1509 + aiomatic_progress.find('small').html('Error');
1510 + aiomatic_progress.addClass('aiomatic_error');
1511 + aiomatic_error_message.html(res.msg);
1512 + aiomatic_error_message.show();
1513 + }
1514 + },
1515 + cache: false,
1516 + contentType: false,
1517 + processData: false,
1518 + error: function (r, s, error){
1519 + aiomatic_assistant_upload.val('');
1520 + aiomaticRmLoading(aiomatic_assistant_button);
1521 + aiomatic_progress.addClass('aiomatic_error');
1522 + aiomatic_progress.find('small').html('Error');
1523 + alert('Error in processing assistants uploading: ' + error);
1524 + aiomatic_error_message.show();
1525 + }
1526 + });
1527 + }
1528 + }
1529 + }
1530 + });
1531 + jQuery("#checkedAll").on('change', function() {
1532 + if (this.checked) {
1533 + jQuery(".aiomatic-select-assistant").each(function() {
1534 + this.checked=true;
1535 + });
1536 + } else {
1537 + jQuery(".aiomatic-select-assistant").each(function() {
1538 + this.checked=false;
1539 + });
1540 + }
1541 + });
1542 + var aiomatic_assistant_buttonx = jQuery('#aiomatic_assistant_default_button');
1543 + aiomatic_assistant_buttonx.on('click', function (e){
1544 + e.preventDefault();
1545 + if(confirm('Are you sure you want to load the default assistants which come bundled with the plugin?'))
1546 + {
1547 + var data = {
1548 + action: 'aiomatic_default_assistant',
1549 + nonce: aiomatic_object.nonce,
1550 + };
1551 + jQuery.ajax({
1552 + url: aiomatic_object.ajax_url,
1553 + data: data,
1554 + dataType: 'JSON',
1555 + type: 'POST',
1556 + beforeSend: function (){
1557 + aiomaticLoading2(jQuery('#aiomatic_assistant_default_button'));
1558 + },
1559 + success: function (res){
1560 + if(res.status === 'success'){
1561 + alert('Default assistants loaded successfully!');
1562 + location.reload();
1563 + }
1564 + else{
1565 + alert(res.msg);
1566 + location.reload();
1567 + }
1568 + },
1569 + error: function (r, s, error){
1570 + console.error("AJAX Error: ", r);
1571 + console.error("Status: ", s);
1572 + console.error("Error: ", error);
1573 + console.error('Detailed error: ' + r.responseText);
1574 + alert('Error in processing assistant loading: ' + error);
1575 + location.reload();
1576 + }
1577 + });
1578 + }
1579 + });
1580 + var codemodalfzr = document.getElementById('mymodalfzr');
1581 + var btn = document.getElementById("aiomatic_manage_assistants");
1582 + var span = document.getElementById("aiomatic_close");
1583 + if(btn != null)
1584 + {
1585 + btn.onclick = function(e) {
1586 + e.preventDefault();
1587 + codemodalfzr.style.display = "block";
1588 + }
1589 + }
1590 + if(span != null)
1591 + {
1592 + span.onclick = function() {
1593 + codemodalfzr.style.display = "none";
1594 + }
1595 + }
1596 +
1597 + var codemodalfzr_backup = document.getElementById('mymodalfzr_backup');
1598 + var btn_backup = document.getElementById("aiomatic_backup_assistants");
1599 + var span_backup = document.getElementById("aiomatic_close_backup");
1600 + if(btn_backup != null)
1601 + {
1602 + btn_backup.onclick = function(e) {
1603 + e.preventDefault();
1604 + codemodalfzr_backup.style.display = "block";
1605 + }
1606 + }
1607 + if(span_backup != null)
1608 + {
1609 + span_backup.onclick = function() {
1610 + codemodalfzr_backup.style.display = "none";
1611 + }
1612 + }
1613 +
1614 + var codemodalfzr_edit = document.getElementById('mymodalfzr-edit');
1615 + var span_edit = document.getElementById("aiomatic_close-edit");
1616 + if(span_edit != null)
1617 + {
1618 + span_edit.onclick = function() {
1619 + codemodalfzr_edit.style.display = "none";
1620 + }
1621 + }
1622 + window.onclick = function(event) {
1623 + if (event.target == codemodalfzr_edit) {
1624 + codemodalfzr_edit.style.display = "none";
1625 + }
1626 + if (event.target == codemodalfzr) {
1627 + codemodalfzr.style.display = "none";
1628 + }
1629 + if (event.target == codemodalfzr_backup) {
1630 + codemodalfzr_backup.style.display = "none";
1631 + }
1632 + }
1633 + });