1 | $(document).ready(function() {
|
---|
2 | var business = {};
|
---|
3 |
|
---|
4 | getBusinessInfo(business);
|
---|
5 |
|
---|
6 | getAppointments();
|
---|
7 |
|
---|
8 | $("#add_service").click(function () {
|
---|
9 | var input_service = $("#input_service").val();
|
---|
10 | // clear the input
|
---|
11 | $("#input_service").val('');
|
---|
12 |
|
---|
13 | $("#predefined_services_admin_panel").append(
|
---|
14 | '<div class="form-outline mb-4">' +
|
---|
15 | ' <div class="row">' +
|
---|
16 | ' <div class="col-md-6">\n' +
|
---|
17 | ' <input class="form-check-input" type="checkbox" checked value="' + -1 + '" id="' + -1 + '">\n' +
|
---|
18 | ' <label class="form-check-label" for="' + -1 + '">\n' +
|
---|
19 | input_service +
|
---|
20 | ' </label>\n' +
|
---|
21 | ' </div>' +
|
---|
22 | ' <div class="form-outline col-md-2 d-grid">' +
|
---|
23 | ' <input type="text" id="' + -1 + input_service.replace(/\s/g, "") + "duration" + '" class="form-control" placeholder="time" />' +
|
---|
24 | ' </div>' +
|
---|
25 | ' <div class="form-outline col-md-2 d-grid">' +
|
---|
26 | ' <input type="text" id="' + -1 + input_service.replace(/\s/g, "") + "price"+ '" class="form-control" placeholder="price" />' +
|
---|
27 | ' </div>' +
|
---|
28 | ' </div>' +
|
---|
29 | '</div>');
|
---|
30 | event.preventDefault();
|
---|
31 | });
|
---|
32 |
|
---|
33 | $("#update_services_button").click(function () {
|
---|
34 | businesses = [];
|
---|
35 | console.log("Gjoko");
|
---|
36 | servicesObj = [];
|
---|
37 | $.each($('#predefined_services_admin_panel input:checked').siblings(), function (index, label) {
|
---|
38 |
|
---|
39 | let service = {};
|
---|
40 | var id = $(label).prop('for');
|
---|
41 | var text = $(label).text();
|
---|
42 | var time = $($($(label).parent()).siblings()[0]).children()[0].value;
|
---|
43 | var price = $($($(label).parent()).siblings()[1]).children()[0].value;
|
---|
44 |
|
---|
45 | var serviceType = {}
|
---|
46 | if (parseInt(id) != -1) {
|
---|
47 | service['id'] = parseInt(id);
|
---|
48 | serviceType['id'] = business['services'].find(obj => obj.id === parseInt(id))['serviceType']['id'];
|
---|
49 | } else {
|
---|
50 |
|
---|
51 | }
|
---|
52 | serviceType['name'] = text.trim();
|
---|
53 | service['serviceType'] = serviceType;
|
---|
54 | service['duration'] = parseInt(time);
|
---|
55 | service['price'] = parseInt(price);
|
---|
56 | servicesObj.push(service);
|
---|
57 | });
|
---|
58 | business['services'] = servicesObj;
|
---|
59 |
|
---|
60 | businesses.push(business);
|
---|
61 | console.log(JSON.stringify(businesses));
|
---|
62 |
|
---|
63 | $.ajax({
|
---|
64 | url: "http://localhost:8080/api/business",
|
---|
65 | type:"PATCH",
|
---|
66 | data: JSON.stringify(businesses),
|
---|
67 | contentType:"application/json; charset=utf-8",
|
---|
68 | dataType: 'text',
|
---|
69 | success: function(succ){
|
---|
70 | alert( "Updates applied successfully" );
|
---|
71 | },
|
---|
72 | error: function(err) {
|
---|
73 | alert(err);
|
---|
74 | }
|
---|
75 | });
|
---|
76 | event.preventDefault();
|
---|
77 | });
|
---|
78 |
|
---|
79 | $("#update_owner_button").click(function() {
|
---|
80 | businesses = [];
|
---|
81 | business['owner']['firstName'] = $('#firstName').val();
|
---|
82 | business['owner']['lastName'] = $('#lastName').val();
|
---|
83 | business['owner']['email'] = $('#email').val();
|
---|
84 | business['owner']['phoneNumber'] = $('#phoneNumber').val();
|
---|
85 | business['owner']['username'] = $('#username').val();
|
---|
86 |
|
---|
87 | businesses.push(business);
|
---|
88 | console.log(JSON.stringify(businesses));
|
---|
89 |
|
---|
90 | $.ajax({
|
---|
91 | url: "http://localhost:8080/api/business",
|
---|
92 | type:"PATCH",
|
---|
93 | data: JSON.stringify(businesses),
|
---|
94 | contentType:"application/json; charset=utf-8",
|
---|
95 | dataType: 'text',
|
---|
96 | success: function(succ){
|
---|
97 | alert( "Updates applied successfully" );
|
---|
98 | },
|
---|
99 | error: function(err) {
|
---|
100 | alert(err);
|
---|
101 | }
|
---|
102 | });
|
---|
103 | });
|
---|
104 | event.preventDefault();
|
---|
105 | });
|
---|
106 |
|
---|
107 | function cancelAppointment(appointmentId) {
|
---|
108 | if (confirm("Are you sure you want to cancel the appointment?")) {
|
---|
109 | $.ajax({
|
---|
110 | url: "http://localhost:8080/api/appointment/" + appointmentId,
|
---|
111 | type:"DELETE"
|
---|
112 | }).success(function (data) {
|
---|
113 | alert("Appointment successfully canceled.")
|
---|
114 | getAppointments();
|
---|
115 | }).error(function (error) {
|
---|
116 | alert("Something went wrong.");
|
---|
117 | });
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | function getAppointments() {
|
---|
122 | $.ajax({
|
---|
123 | url: "http://localhost:8080/api/appointment/future/me"
|
---|
124 | }).then(function (data) {
|
---|
125 | console.log(data);
|
---|
126 | var $el = $("#bookings-table-body");
|
---|
127 | $el.empty();
|
---|
128 | $.each(data, function (index, obj) {
|
---|
129 | var element =
|
---|
130 | '<tr>' +
|
---|
131 | ' <th scope="row">' + (parseInt(index) + 1) + '</th>' +
|
---|
132 | ' <td>' + obj['fullName'] + '</td>' +
|
---|
133 | ' <td>' + obj['email'] + '</td>' +
|
---|
134 | ' <td>' + obj['phoneNumber'] + '</td>' +
|
---|
135 | ' <td>' + obj['timePeriod'] + '</td>' +
|
---|
136 | ' <td>' + obj['serviceName'] + '</td>';
|
---|
137 |
|
---|
138 | switch (obj['status']) {
|
---|
139 | case 'NEW':
|
---|
140 | element += ' <td><button type="button" class="btn btn-danger" onclick="cancelAppointment(' + obj['appointmentId'] + ')">Cancel appointment</button></td>';
|
---|
141 | break;
|
---|
142 | case 'CANCELLED_BY_CUSTOMER':
|
---|
143 | element += ' <td><button type="button" class="btn btn-secondary" disabled>Cancelled by customer</button></td>';
|
---|
144 | break;
|
---|
145 | case 'CANCELLED_BY_BUSINESS_OWNER':
|
---|
146 | element += ' <td><button type="button" class="btn btn-secondary" disabled>Cancelled by business owner</button></td>';
|
---|
147 | break;
|
---|
148 | }
|
---|
149 | element+='</tr>';
|
---|
150 |
|
---|
151 | $el.append(element);
|
---|
152 | });
|
---|
153 | });
|
---|
154 | }
|
---|
155 |
|
---|
156 | function getBusinessInfo(business) {
|
---|
157 | $.ajax({
|
---|
158 | url: "http://localhost:8080/api/business/me"
|
---|
159 | }).then(function (data) {
|
---|
160 | business = data;
|
---|
161 | var $header = $("#header");
|
---|
162 |
|
---|
163 | // header
|
---|
164 | $header.text($header.text() + " " + business["owner"]['firstName'] + " " + business['owner']['lastName']);
|
---|
165 |
|
---|
166 | // business info
|
---|
167 | if(business['businessStatus'] == 'NEW') {
|
---|
168 | $('#new_business_warning').removeAttr("hidden");
|
---|
169 | }
|
---|
170 | $('#business_status').val(business['businessStatus']);
|
---|
171 | $('#business_type').val(business['businessType']['text']);
|
---|
172 |
|
---|
173 | // owner info
|
---|
174 | $('#firstName').val(business['owner']['firstName']);
|
---|
175 | $('#lastName').val(business['owner']['lastName']);
|
---|
176 | $('#phoneNumber').val(business['owner']['phoneNumber']);
|
---|
177 | $('#email').val(business['owner']['email']);
|
---|
178 | $('#username').val(business['owner']['username']);
|
---|
179 |
|
---|
180 | // services info
|
---|
181 | var $el = $("#predefined_services_admin_panel");
|
---|
182 | $el.empty();
|
---|
183 | $.each(business['services'], function (index, obj) {
|
---|
184 | $el.append(
|
---|
185 | '<div class=\"form-outline mb-4\">' +
|
---|
186 | ' <div class="row">' +
|
---|
187 | ' <div class="col-md-6">\n' +
|
---|
188 | ' <input class="form-check-input" type="checkbox" checked value=\"' + obj.id + '\" id=\"' + obj.id + '\">\n' +
|
---|
189 | ' <label class="form-check-label" for=\"' + obj.id + '\">\n' + obj['serviceType'].name + '</label>\n' +
|
---|
190 | ' </div>' +
|
---|
191 | ' <div class=\"form-outline col-md-2 d-grid\">' +
|
---|
192 | ' <input type=\"text\" id=\"' + obj.id + obj['serviceType'].name.replace(/\s/g, "") + "duration" + '\" class=\"form-control\" placeholder="time" value=\"' + obj.duration + '" />' +
|
---|
193 | ' </div>' +
|
---|
194 | ' <div class=\"form-outline col-md-2 d-grid\">' +
|
---|
195 | ' <input type=\"text\" id=\"' + obj.id + obj['serviceType'].name.replace(/\s/g, "") + "price" + '\" class=\"form-control\" placeholder="price" value=\"' + obj.price + '" />' +
|
---|
196 | ' </div>' +
|
---|
197 | ' </div>' +
|
---|
198 | '</div>');
|
---|
199 | });
|
---|
200 | });
|
---|
201 | } |
---|