PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / public / js / tinymce / amelia-mce.js
ameliabooking / public / js / tinymce Last commit date
amelia-mce.js 1 day ago amelia-tinymce-styles.css 2 years ago
amelia-mce.js
890 lines
1 /* eslint-disable */
2 (function () {
3 tinymce.create('tinymce.plugins.ameliaBookingPlugin', {
4
5 init: function (editor) {
6 if (!('wpAmeliaLabels' in window)) {
7 return
8 }
9
10 let win = null
11
12 let entities = null
13 let categories = null
14 let services = null
15 let employees = null
16 let locations = null
17 let servicesList = null
18 let packages = null
19 let events = null
20 let tags = null
21 let ivy = null
22 let catalogView = null
23 let useNeutralShortcodes = Boolean(window.wpAmeliaUseNeutralShortcodes)
24 let shortcodeAliases = window.wpAmeliaShortcodeAliases || {}
25 let builderBrandName = useNeutralShortcodes
26 ? (window.wpAmeliaBuilderBrandName || window.wpAmeliaPluginName || 'Booking')
27 : 'Amelia'
28
29 let getNeutralLabel = function (label) {
30 if (!useNeutralShortcodes) {
31 return label
32 }
33
34 return label
35 .replace(/^Amelia\s-\s/i, '')
36 .replace(/\bAmelia\s+/gi, '')
37 .replace(/\s\(Legacy\)$/, '')
38 }
39
40 let getShortcodeTag = function (view, legacyTag) {
41 return useNeutralShortcodes && shortcodeAliases[view] ? shortcodeAliases[view] : legacyTag
42 }
43
44 let createShortcode = function (view, legacyTag, params) {
45 return '[' + getShortcodeTag(view, legacyTag) + (params || '') + ']'
46 }
47
48 let setSharedShortcodeElements = function (viewBody, data) {
49 viewBody.push({
50 type: 'textbox',
51 label: wpAmeliaLabels.manually_loading,
52 name: 'am_trigger',
53 tooltip: wpAmeliaLabels.manually_loading_description,
54 classes: 'am-booking-trigger',
55 onKeyUp: function (e) {
56 syncTriggerFields(!!e.target.value)
57 }
58 })
59
60 viewBody.push({
61 type: 'listbox',
62 label: wpAmeliaLabels.trigger_type,
63 name: 'am_trigger_type',
64 values: [
65 {value: 'id', text: wpAmeliaLabels.trigger_type_id},
66 {value: 'class', text: wpAmeliaLabels.trigger_type_class}
67 ],
68 classes: 'am-booking-trigger-type',
69 })
70
71 viewBody.push({
72 type: 'checkbox',
73 label: wpAmeliaLabels.in_dialog,
74 name: 'am_in_dialog',
75 classes: 'am-booking-dialog',
76 })
77
78 viewBody.push({
79 type: 'listbox',
80 label: wpAmeliaLabels.ivy,
81 name: 'am_ivy',
82 values: data.ivy,
83 classes: 'am-booking-ivy',
84 })
85 }
86
87 let getSharedShortcodeString = function (e) {
88 let shortCodeString = ''
89
90 if (e.data.am_trigger) {
91 shortCodeString += ' trigger=' + e.data.am_trigger
92 }
93
94 if (e.data.am_trigger && e.data.am_trigger_type) {
95 shortCodeString += ' trigger_type=' + e.data.am_trigger_type
96 }
97
98 if (e.data.am_trigger && e.data.am_in_dialog) {
99 shortCodeString += ' in_dialog=1'
100 }
101
102 if (e.data.am_ivy && !e.data.am_trigger) {
103 shortCodeString += ' ivy=' + e.data.am_ivy
104 }
105
106 return shortCodeString
107 }
108
109 let syncTriggerFields = function (hasTrigger) {
110 if (!win) {
111 return
112 }
113
114 let triggerType = win.find('#am_trigger_type')
115 let inDialog = win.find('#am_in_dialog')
116 let ivy = win.find('#am_ivy')
117
118 if (triggerType) {
119 triggerType.parent().visible(!!hasTrigger)
120 }
121 if (inDialog) {
122 inDialog.parent().visible(!!hasTrigger)
123 }
124 if (ivy) {
125 ivy.parent().visible(!hasTrigger)
126 }
127 }
128
129 let setAndOpenEditor = function (view) {
130 editor.windowManager.close()
131
132 let viewBody = [{
133 type: 'listbox',
134 name: 'am_view_type',
135 label: wpAmeliaLabels.select_view,
136 values: [
137 {value: 'stepbooking', text: 'Step Booking', classes: 'am-booking-shortcode'},
138 {value: 'catalogbooking', text: 'Catalog Booking', classes: 'am-booking-shortcode'},
139 {value: 'eventslistbooking', text: 'Events List Booking', classes: 'am-booking-shortcode'},
140 {value: 'eventscalendarbooking', text: 'Events Calendar Booking', classes: 'am-booking-shortcode'},
141 {value: 'customer_panel', text: 'Customer Panel', classes: 'am-booking-shortcode'},
142 {value: 'employee_panel', text: 'Employee Panel', classes: 'am-booking-shortcode'},
143 // {value: 'booking', text: 'Booking', classes: 'am-booking-shortcode am-outdated-booking-shortcode'},
144 // {value: 'search', text: 'Search', classes: 'am-booking-shortcode am-outdated-booking-shortcode'},
145 // {value: 'catalog', text: 'Catalog', classes: 'am-booking-shortcode am-outdated-booking-shortcode'},
146 // {value: 'events', text: 'Events', classes: 'am-booking-shortcode am-outdated-booking-shortcode'},
147 ],
148 value: view,
149 onSelect: function () {
150 setAndOpenEditor(this.value())
151 }
152 },
153 ]
154
155 let filterItems = null
156
157 // set view
158 switch (view) {
159 case ('booking'):
160 case ('stepbooking'):
161
162 // Filter
163 filterItems = []
164
165 if (categories.length > 1) {
166 filterItems.push({
167 type: 'listbox',
168 name: 'am_booking_category',
169 label: wpAmeliaLabels.select_category,
170 classes: 'am-booking-categories',
171 values: [{
172 value: 0,
173 text: wpAmeliaLabels.show_all_categories
174 }].concat(categories),
175 })
176 }
177
178 if (services.length > 1) {
179 filterItems.push({
180 type: 'listbox',
181 name: 'am_booking_service',
182 label: wpAmeliaLabels.select_service,
183 classes: 'am-booking-services',
184 values: [{
185 value: 0,
186 text: wpAmeliaLabels.show_all_services
187 }].concat(services),
188 })
189 }
190
191 if (employees.length > 1) {
192 filterItems.push({
193 type: 'listbox',
194 name: 'am_booking_employee',
195 label: wpAmeliaLabels.select_employee,
196 classes: 'am-booking-employees',
197 values: [{
198 value: 0,
199 text: wpAmeliaLabels.show_all_employees
200 }].concat(employees),
201 })
202 }
203
204 if (locations.length > 1) {
205 filterItems.push({
206 type: 'listbox',
207 name: 'am_booking_location',
208 label: wpAmeliaLabels.select_location,
209 classes: 'am-booking-locations',
210 values: [{
211 value: 0,
212 text: wpAmeliaLabels.show_all_locations
213 }].concat(locations),
214 })
215 }
216
217 if (packages.length) {
218 if (view === 'stepbooking') {
219 filterItems.push({
220 type: 'listbox',
221 name: 'am_booking_package',
222 label: wpAmeliaLabels.select_package,
223 classes: 'am-booking-packages',
224 values: [{
225 value: 0,
226 text: wpAmeliaLabels.show_all_packages
227 }].concat(packages),
228 })
229 }
230
231 viewBody.push({
232 type: 'listbox',
233 name: 'am_show',
234 values: [
235 {value: '', text: wpAmeliaLabels.show_all},
236 {value: 'services', text: wpAmeliaLabels.services},
237 {value: 'packages', text: wpAmeliaLabels.packages}
238 ],
239 classes: 'am-show',
240 })
241 }
242
243 viewBody.push({
244 type: 'checkbox',
245 name: 'am_booking_filter',
246 label: wpAmeliaLabels.filter,
247 classes: 'am-booking-filter',
248 onChange: function () {
249 let filterForm = win.find('#am_booking_panel')
250 filterForm.visible(!filterForm.visible())
251 }
252 })
253
254 viewBody.push({
255 type: 'form',
256 name: 'am_booking_panel',
257 classes: 'am-booking-panel',
258 items: filterItems,
259 visible: false,
260 })
261
262 if (view === 'stepbooking') {
263 // Layout version selector
264 viewBody.push({
265 type: 'listbox',
266 label: wpAmeliaLabels.layout_select_label,
267 name: 'am_layout',
268 values: [
269 {value: '1', text: wpAmeliaLabels.layout_dropdown},
270 {value: '2', text: wpAmeliaLabels.layout_list}
271 ],
272 classes: 'am-booking-layout',
273 })
274
275 setSharedShortcodeElements(viewBody, {ivy: ivy})
276 }
277
278 break
279 case ('search'):
280 // Filter
281 viewBody.push({
282 type: 'checkbox',
283 name: 'am_search_date',
284 label: wpAmeliaLabels.search_date,
285 classes: 'am-search-date',
286 })
287
288 if (packages.length) {
289 viewBody.push({
290 type: 'listbox',
291 name: 'am_show',
292 values: [
293 {value: '', text: wpAmeliaLabels.show_all},
294 {value: 'services', text: wpAmeliaLabels.services},
295 {value: 'packages', text: wpAmeliaLabels.packages}
296 ],
297 classes: 'am-show',
298 })
299 }
300
301 break
302 case ('catalog'):
303 case ('catalogbooking'):
304 var catalogOptions = [
305 {value: 'catalog', text: wpAmeliaLabels.show_catalog},
306 {value: 'category', text: wpAmeliaLabels.show_category},
307 {value: 'service', text: wpAmeliaLabels.show_service}
308 ]
309
310 if (packages.length) {
311 catalogOptions.push({value: 'package', text: wpAmeliaLabels.show_package})
312 }
313
314 viewBody.push({
315 type: 'listbox',
316 name: 'am_catalog_view_type',
317 label: wpAmeliaLabels.select_catalog_view,
318 values: catalogOptions,
319 classes: 'am-catalog-view-type',
320 onSelect: function () {
321 catalogView = this.value()
322
323 let categoryElement = win.find('#am_category')
324 let serviceElement = win.find('#am_service')
325 let packageElement = win.find('#am_package')
326 let showElement = win.find('#am_show')
327
328 if (catalogView === 'category') {
329 categoryElement.visible(true)
330 serviceElement.visible(false)
331 packageElement.visible(false)
332 showElement.visible(true)
333 } else if (catalogView === 'service') {
334 categoryElement.visible(false)
335 serviceElement.visible(true)
336 packageElement.visible(false)
337 showElement.visible(view !== 'catalog')
338 } else if (catalogView === 'package') {
339 categoryElement.visible(false)
340 serviceElement.visible(false)
341 packageElement.visible(true)
342 showElement.visible(false)
343 } else {
344 categoryElement.visible(false)
345 serviceElement.visible(false)
346 packageElement.visible(false)
347 showElement.visible(true)
348 }
349 },
350 })
351
352 // Category
353 viewBody.push({
354 type: 'listbox',
355 name: 'am_category',
356 values: categories,
357 classes: 'am-categories',
358 })
359
360 // Service
361 viewBody.push({
362 type: 'listbox',
363 name: 'am_service',
364 values: services,
365 classes: 'am-services',
366 })
367
368 if (packages.length) {
369 // Package
370 viewBody.push({
371 type: 'listbox',
372 name: 'am_package',
373 values: packages,
374 classes: 'am-packages',
375 })
376
377 // Service
378 viewBody.push({
379 type: 'listbox',
380 name: 'am_show',
381 values: [
382 {value: '', text: wpAmeliaLabels.show_all},
383 {value: 'services', text: wpAmeliaLabels.services},
384 {value: 'packages', text: wpAmeliaLabels.packages}
385 ],
386 classes: 'am-show',
387 })
388 }
389
390 // Filter
391 filterItems = []
392
393 if (employees.length > 1) {
394 filterItems.push({
395 type: 'listbox',
396 name: 'am_booking_employee',
397 label: wpAmeliaLabels.select_employee,
398 classes: 'am-booking-employees',
399 values: [{
400 value: 0,
401 text: wpAmeliaLabels.show_all_employees
402 }].concat(employees),
403 })
404 }
405
406 if (locations.length > 1) {
407 filterItems.push({
408 type: 'listbox',
409 name: 'am_booking_location',
410 label: wpAmeliaLabels.select_location,
411 classes: 'am-booking-locations',
412 values: [{
413 value: 0,
414 text: wpAmeliaLabels.show_all_locations
415 }].concat(locations),
416 })
417 }
418
419 if (view === 'catalogbooking') {
420 filterItems.push({
421 type: 'checkbox',
422 name: 'am_booking_skip_categories',
423 label: wpAmeliaLabels.skip_categories,
424 classes: 'am-booking-skip-categories',
425 })
426 }
427
428 viewBody.push({
429 type: 'checkbox',
430 name: 'am_booking_filter',
431 label: wpAmeliaLabels.filter,
432 classes: 'am-booking-filter',
433 style: '',
434 onChange: function () {
435 let filterForm = win.find('#am_booking_panel')
436 filterForm.visible(!filterForm.visible())
437 }
438 })
439
440 viewBody.push({
441 type: 'form',
442 name: 'am_booking_panel',
443 classes: 'am-booking-panel',
444 items: filterItems,
445 visible: false,
446 })
447
448 setSharedShortcodeElements(viewBody, {ivy: ivy})
449
450 break
451
452 case ('events'):
453 case ('eventslistbooking'):
454 case ('eventscalendarbooking'):
455 // Filter
456 filterItems = [
457 {
458 type: 'listbox',
459 name: 'am_booking_event',
460 label: wpAmeliaLabels.select_event,
461 classes: 'am-booking-events',
462 values: [{
463 value: 0,
464 text: wpAmeliaLabels.show_all_events
465 }].concat(events),
466 },
467 {
468 type: 'checkbox',
469 name: 'am_booking_event_recurring',
470 label: wpAmeliaLabels.recurring_event,
471 classes: 'am-recurring-event',
472 },
473 {
474 type: 'listbox',
475 name: 'am_booking_location',
476 label: wpAmeliaLabels.select_location,
477 classes: 'am-booking-locations',
478 values: [{
479 value: 0,
480 text: wpAmeliaLabels.show_all_locations
481 }].concat(locations),
482 },
483 {
484 type: 'listbox',
485 name: 'am_booking_tag',
486 label: wpAmeliaLabels.select_tag,
487 classes: 'am-booking-tags',
488 values: [{
489 value: 0,
490 text: wpAmeliaLabels.show_all_tags
491 }].concat(tags),
492 }
493 ]
494
495 viewBody.push({
496 type: 'checkbox',
497 name: 'am_booking_filter',
498 label: wpAmeliaLabels.filter,
499 classes: 'am-booking-filter',
500 onChange: function () {
501 let filterForm = win.find('#am_booking_panel')
502 filterForm.visible(!filterForm.visible())
503 }
504 })
505
506 viewBody.push({
507 type: 'form',
508 name: 'am_booking_panel',
509 classes: 'am-booking-panel',
510 items: filterItems,
511 visible: false,
512 })
513
514
515 if (view === 'events' && !parseInt(wpAmeliaLabels.isLite)) {
516 viewBody.push({
517 type: 'listbox',
518 name: 'am_booking_event_view_type',
519 label: wpAmeliaLabels.show_event_view_type,
520 values: [
521 {value: 'list', text: wpAmeliaLabels.show_event_view_list},
522 {value: 'calendar', text: wpAmeliaLabels.show_event_view_calendar}
523 ],
524 classes: 'am-booking-events-view',
525 })
526 }
527
528 setSharedShortcodeElements(viewBody, {ivy: ivy})
529
530 break
531
532 case ('customer_panel'):
533 case ('employee_panel'):
534
535 viewBody.push({
536 type: 'checkbox',
537 name: 'am_cabinet_appointments',
538 label: wpAmeliaLabels.appointments,
539 classes: 'am_cabinet_appointments',
540 })
541
542 viewBody.push({
543 type: 'checkbox',
544 name: 'am_cabinet_events',
545 label: wpAmeliaLabels.events,
546 classes: 'am_cabinet_events',
547 })
548
549 if (view === 'employee_panel') {
550 viewBody.push({
551 type: 'checkbox',
552 name: 'am_cabinet_profile',
553 label: wpAmeliaLabels.profile,
554 classes: 'am_cabinet_profile',
555 })
556 }
557
558 break
559 }
560
561 // open editor
562 win = editor.windowManager.open({
563 title: useNeutralShortcodes ? builderBrandName : 'Amelia Booking',
564 width: 500,
565 height: 435,
566 body: viewBody,
567 onSubmit: function (e) {
568 let shortCodeString = ''
569
570 switch (view) {
571 case ('booking'):
572 case ('stepbooking'):
573 shortCodeString += getSharedShortcodeString(e)
574
575 if (e.data.am_booking_service) {
576 shortCodeString += ' service=' + e.data.am_booking_service
577 } else if (e.data.am_booking_category) {
578 shortCodeString += ' category=' + e.data.am_booking_category
579 } else if (e.data.am_booking_package) {
580 shortCodeString += ' package=' + e.data.am_booking_package
581 }
582
583 if (e.data.am_booking_employee) {
584 shortCodeString += ' employee=' + e.data.am_booking_employee
585 }
586
587 if (e.data.am_booking_location) {
588 shortCodeString += ' location=' + e.data.am_booking_location
589 }
590
591 if (e.data.am_show) {
592 shortCodeString += ' show=' + e.data.am_show
593 }
594
595 if (view === 'stepbooking' && e.data.am_layout) {
596 shortCodeString += ' layout=' + e.data.am_layout
597 }
598
599 editor.insertContent(
600 createShortcode(
601 view,
602 view === 'stepbooking' ? 'ameliastepbooking' : 'ameliabooking',
603 shortCodeString
604 )
605 )
606
607 break
608
609 case ('search'):
610 if (e.data.am_search_date) {
611 shortCodeString += ' today=1'
612 }
613
614 if (e.data.am_trigger) {
615 shortCodeString += ' trigger=' + e.data.am_trigger
616 }
617
618 if (e.data.am_show) {
619 shortCodeString += ' show=' + e.data.am_show
620 }
621
622 editor.insertContent(createShortcode(view, 'ameliasearch', shortCodeString))
623
624 break
625
626 case ('catalog'):
627 shortCodeString += getSharedShortcodeString(e)
628
629 if (e.data.am_booking_employee) {
630 shortCodeString += ' employee=' + e.data.am_booking_employee
631 }
632
633 if (e.data.am_booking_location) {
634 shortCodeString += ' location=' + e.data.am_booking_location
635 }
636
637 if (e.data.am_show && catalogView !== 'service' && catalogView !== 'package') {
638 shortCodeString += ' show=' + e.data.am_show
639 }
640
641 if (catalogView === 'category') {
642 editor.insertContent(createShortcode(view, 'ameliacatalog', ' category=' + e.data.am_category + shortCodeString))
643 } else if (catalogView === 'service') {
644 editor.insertContent(createShortcode(view, 'ameliacatalog', ' service=' + e.data.am_service + shortCodeString))
645 } else if (catalogView === 'package') {
646 editor.insertContent(createShortcode(view, 'ameliacatalog', ' package=' + e.data.am_package + shortCodeString))
647 } else {
648 editor.insertContent(createShortcode(view, 'ameliacatalog', shortCodeString))
649 }
650
651 break
652
653 case ('catalogbooking'):
654 shortCodeString += getSharedShortcodeString(e)
655
656 if (e.data.am_booking_employee) {
657 shortCodeString += ' employee=' + e.data.am_booking_employee
658 }
659
660 if (e.data.am_booking_location) {
661 shortCodeString += ' location=' + e.data.am_booking_location
662 }
663
664 if (e.data.am_booking_skip_categories) {
665 shortCodeString += ' categories_hidden=1'
666 }
667
668 if (catalogView === 'category') {
669 if (e.data.am_show) {
670 shortCodeString += ' show=' + e.data.am_show
671 }
672 editor.insertContent(createShortcode(view, 'ameliacatalogbooking', ' category=' + e.data.am_category + shortCodeString))
673 } else if (catalogView === 'service') {
674 if (e.data.am_show && e.data.am_show !== 'packages') {
675 shortCodeString += ' show=' + e.data.am_show
676 }
677 editor.insertContent(createShortcode(view, 'ameliacatalogbooking', ' service=' + e.data.am_service + shortCodeString))
678 } else if (catalogView === 'package') {
679 editor.insertContent(createShortcode(view, 'ameliacatalogbooking', ' package=' + e.data.am_package + shortCodeString))
680 } else {
681 if (e.data.am_show) {
682 shortCodeString += ' show=' + e.data.am_show
683 }
684 editor.insertContent(createShortcode(view, 'ameliacatalogbooking', shortCodeString))
685 }
686
687 break
688
689 case ('events'):
690 case ('eventslistbooking'):
691 case ('eventscalendarbooking'):
692 shortCodeString += getSharedShortcodeString(e)
693
694 if (e.data.am_booking_event) {
695 shortCodeString += ' event=' + e.data.am_booking_event
696
697 if (e.data.am_booking_event_recurring) {
698 shortCodeString += ' recurring=1'
699 }
700 }
701
702 if (view === 'events' && e.data.am_booking_event_view_type) {
703 shortCodeString += ' type=' + "'" + e.data.am_booking_event_view_type + "'"
704 }
705
706 if (e.data.am_booking_tag) {
707 shortCodeString += ` tag="${e.data.am_booking_tag}"`
708 }
709
710 if (e.data.am_booking_location) {
711 shortCodeString += ' location=' + e.data.am_booking_location
712 }
713
714 if (view === 'eventslistbooking') {
715 editor.insertContent(createShortcode(view, 'ameliaeventslistbooking', shortCodeString))
716 } else if (view === 'eventscalendarbooking') {
717 editor.insertContent(createShortcode(view, 'ameliaeventscalendarbooking', shortCodeString))
718 } else {
719 editor.insertContent(createShortcode(view, 'ameliaevents', shortCodeString))
720 }
721
722 break
723
724 case ('customer_panel'):
725 case ('employee_panel'):
726 if (e.data.am_cabinet_appointments) {
727 shortCodeString += ' appointments=1'
728 }
729
730 if (e.data.am_cabinet_events) {
731 shortCodeString += ' events=1'
732 }
733
734 if (e.data.am_cabinet_profile && view !== 'customer_panel') {
735 shortCodeString += ' profile-hidden=1'
736 }
737
738 if (e.data.am_trigger) {
739 shortCodeString += ' trigger=' + e.data.am_trigger
740 }
741
742 editor.insertContent(
743 view === 'customer_panel'
744 ? createShortcode(view, 'ameliacustomerpanel', shortCodeString)
745 : createShortcode(view, 'ameliaemployeepanel', shortCodeString)
746 )
747
748 break
749 }
750 },
751 onOpen: function () {
752 categoryElement = win.find('#am_category')
753 serviceElement = win.find('#am_service')
754 packageElement = win.find('#am_package')
755
756 categoryElement.visible(false)
757 serviceElement.visible(false)
758 packageElement.visible(false)
759
760 if (view === 'stepbooking' || view === 'catalog' || view === 'catalogbooking' || view === 'events' || view === 'eventslistbooking' || view === 'eventscalendarbooking') {
761 let trigger = win.find('#am_trigger')[0]
762 let hasTrigger = trigger ? !!trigger.value() : false
763
764 syncTriggerFields(hasTrigger)
765 }
766 },
767 })
768 }
769
770 // Add new button
771 let buttonOptions = {
772 title: useNeutralShortcodes ? 'Insert booking shortcode' : wpAmeliaLabels.insert_amelia_shortcode,
773 cmd: 'ameliaButtonCommand'
774 }
775
776 if (useNeutralShortcodes) {
777 buttonOptions.text = builderBrandName
778 } else {
779 buttonOptions.image = window.wpAmeliaPluginURL + 'public/img/amelia-logo-admin-icon.svg'
780 }
781
782 editor.addButton('ameliaButton', buttonOptions)
783
784 // Button functionality
785 editor.addCommand('ameliaButtonCommand', function () {
786 jQuery.ajax({
787 url: ajaxurl + '?action=wpamelia_api&call=/entities&types[]=categories&types[]=employees&types[]=locations&types[]=events&types[]=tags&types[]=packages&types[]=ivy',
788 dataType: 'json',
789 success: function (response) {
790 entities = response.data
791 categories = []
792 services = []
793 employees = []
794 locations = []
795 packages = []
796 servicesList = []
797 events = []
798 tags = []
799 ivy = []
800
801 for (let i = 0; i < response.data.categories.length; i++) {
802 categories.push({
803 value: response.data.categories[i].id,
804 text: response.data.categories[i].name + ' (id: ' + response.data.categories[i].id + ')'
805 })
806 }
807
808 // Add all services to one array
809 response.data.categories.map(category => category.serviceList).forEach(function (serviceList) {
810 servicesList = servicesList.concat(serviceList)
811 })
812
813 // Create array of services objects
814 for (let i = 0; i < servicesList.length; i++) {
815 if (servicesList[i].show) {
816 services.push({
817 value: servicesList[i].id,
818 text: servicesList[i].name + ' (id: ' + servicesList[i].id + ')'
819 })
820 }
821 }
822
823 // Create array of packages objects
824 for (let i = 0; i < response.data.categories.length; i++) {
825 if (response.data.categories[i].show) {
826 packages.push({
827 value: response.data.categories[i].id,
828 text: response.data.categories[i].name + ' (id: ' + response.data.categories[i].id + ')'
829 })
830 }
831 }
832
833 // Create array of employees objects
834 for (let i = 0; i < response.data.employees.length; i++) {
835 if (response.data.employees[i].show) {
836 employees.push({
837 value: response.data.employees[i].id,
838 text: response.data.employees[i].firstName + ' ' + response.data.employees[i].lastName + ' (id: ' + response.data.employees[i].id + ')'
839 })
840 }
841 }
842
843 // Create array of locations objects
844 for (let i = 0; i < response.data.locations.length; i++) {
845 locations.push({
846 value: response.data.locations[i].id,
847 text: response.data.locations[i].name + ' (id: ' + response.data.locations[i].id + ')'
848 })
849 }
850
851 // Create array of packages objects
852 for (let i = 0; i < response.data.packages.length; i++) {
853 packages.push({
854 value: response.data.packages[i].id,
855 text: response.data.packages[i].name + ' (id: ' + response.data.packages[i].id + ')'
856 })
857 }
858
859 for (let i = 0; i < response.data.events.length; i++) {
860 events.push({
861 value: response.data.events[i].id,
862 text: response.data.events[i].name + ' (id: ' + response.data.events[i].id + ') - ' + response.data.events[i].formattedPeriodStart
863 })
864 }
865
866 for (let i = 0; i < response.data.tags.length; i++) {
867 tags.push({
868 value: response.data.tags[i].name,
869 text: response.data.tags[i].name
870 })
871 }
872
873 for (let i = 0; i < (response.data.ivy || []).length; i++) {
874 ivy.push({
875 value: response.data.ivy[i].value,
876 text: response.data.ivy[i].label
877 })
878 }
879
880 // set and open editor
881 setAndOpenEditor('stepbooking')
882 }
883 })
884 })
885 }
886 })
887
888 tinymce.PluginManager.add('ameliaBookingPlugin', tinymce.plugins.ameliaBookingPlugin)
889 })()
890