PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / assets / js / statuscodes.js
vikappointments / site / assets / js Last commit date
charts-framework 2 days ago colorpicker 2 days ago select2 2 days ago tel 2 days ago contextmenu.js 2 days ago currency.js 2 days ago index.html 2 days ago jquery-ui.draggable.min.js 2 days ago jquery-ui.min.js 2 days ago jquery-ui.sortable.min.js 2 days ago jquery.fancybox.js 2 days ago jquery.min.js 2 days ago sortablelist.js 2 days ago statuscodes.js 2 days ago toast.js 2 days ago utils.js 2 days ago vap-emparea.js 2 days ago vikappointments.js 2 days ago
statuscodes.js
163 lines
1 /**
2 * Define object to easily access the supported status codes.
3 * The codes will be grouped by category:
4 * - appointments
5 * - packages
6 * - subscriptions
7 *
8 * @var object
9 */
10 if (typeof VIKAPPOINTMENTS_STATUS_CODES_MAP === 'undefined') {
11 var VIKAPPOINTMENTS_STATUS_CODES_MAP = {};
12 }
13
14 /**
15 * Reservation status codes context menu.
16 */
17 (function($) {
18 /**
19 * Click event implementor for context menu buttons.
20 *
21 * @param object handle The popup handler.
22 * @param Event event The triggered event.
23 *
24 * @return void
25 */
26 var statusCodesPopupButtonClicked = function(handle, event) {
27 // get selected order
28 var id_order = parseInt($(handle).attr('data-id'));
29 // get selected status
30 var status = $(handle).attr('data-status');
31
32 // do not go ahead if the status didn't change
33 if (status == this.id) {
34 return false;
35 }
36
37 // replace HTML with loading icon
38 $(handle).css('opacity', 0.5);
39
40 // make request
41 UIAjax.do(
42 this.url,
43 {
44 id: id_order,
45 status: this.id,
46 layout: this.layout
47 },
48 (resp) => {
49 // inject ID order in response
50 resp.id_order = id_order;
51
52 // update status HTML
53 $(handle).html(resp.html);
54
55 // reset opacity
56 $(handle).css('opacity', 'inherit');
57
58 // update root with new status
59 $(handle).attr('data-status', resp.code);
60
61 // trigger change method, if supported
62 if (this.onChange) {
63 this.onChange(resp, handle);
64 }
65
66 // trigger status code changed event
67 $(window).trigger('statuscode.changed', [resp, handle]);
68 },
69 (error) => {
70 // trigger status code error event
71 $(window).trigger('statuscode.error', [error, handle]);
72
73 // reset opacity
74 $(handle).css('opacity', 'inherit');
75 }
76 );
77 };
78
79 /**
80 * Register jQuery plugin.
81 *
82 * @param mixed method A configuration object or a method to invoke.
83 *
84 * @return self The given root to support chaining.
85 */
86 $.fn.statusCodesPopup = function(method) {
87 var root = this;
88
89 if (!method) {
90 method = {};
91 }
92
93 // initialize popup events
94 if (typeof method === 'object') {
95 // create default object
96 var data = $.extend({
97 url: null,
98 group: null,
99 layout: null,
100 onShow: null,
101 onHide: null,
102 onChange: null,
103 }, method);
104
105 // iterate all elements
106 $(root).each(function() {
107 var buttons = [];
108
109 // check if we have some codes for this group
110 if (VIKAPPOINTMENTS_STATUS_CODES_MAP.hasOwnProperty(data.group)) {
111 // iterate all status codes
112 VIKAPPOINTMENTS_STATUS_CODES_MAP[data.group].forEach((status) => {
113 // create new button
114 let btn = {
115 id: status.code,
116 text: status.name,
117 action: statusCodesPopupButtonClicked,
118 url: data.url,
119 layout: data.layout,
120 onChange: data.onChange,
121 icon: function(handle, config) {
122 // display a colored icon next to the status code
123 return $('<i class="far fa-circle"></i>').css('color', '#' + status.color);
124 },
125 visible: function(handle, config) {
126 // get selected status
127 var code = $(handle).attr('data-status');
128
129 // hide in case the status code is already assigned
130 return this.id != code;
131 },
132 };
133
134 // add button to list
135 buttons.push(btn);
136 });
137 }
138
139 // init context menu
140 $(this).vikContextMenu({
141 buttons: buttons,
142 class: 'statuscodes-context-menu',
143 onShow: data.onShow,
144 onHide: data.onHide,
145 });
146 });
147 }
148 // check if we should destroy the popup
149 else if (typeof method === 'string' && method.match(/^(destroy)$/i)) {
150 $(this).vikContextMenu('destroy');
151 }
152 // check if we should dismiss the popup
153 else if (typeof method === 'string' && method.match(/^(close|dismiss|hide)$/i)) {
154 $(this).vikContextMenu('hide');
155 }
156 // otherwise open the popup
157 else {
158 $(this).vikContextMenu('show');
159 }
160
161 return this;
162 };
163 })(jQuery);