Changeset 77205be for src/main/resources/static/js/business_admin.js
- Timestamp:
- 12/26/23 18:50:43 (6 months ago)
- Branches:
- master
- Children:
- 1413ee2
- Parents:
- 950fa0d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/resources/static/js/business_admin.js
-
Property mode
changed from
100644
to100755
r950fa0d r77205be 1 1 $(document).ready(function() { 2 3 2 var business = {}; 4 3 5 $.ajax({ 6 url: "http://localhost:8080/api/business/me" 7 }).then(function (data) { 8 business = data; 9 var $header = $("#header"); 10 11 // header 12 $header.text($header.text() + " " + business["owner"]['firstName'] + " " + business['owner']['lastName']); 13 14 // business info 15 if(business['businessStatus'] == 'NEW') { 16 $('#new_business_warning').removeAttr("hidden"); 17 } 18 $('#business_status').val(business['businessStatus']); 19 $('#business_type').val(business['businessType']['text']); 20 21 // owner info 22 $('#firstName').val(business['owner']['firstName']); 23 $('#lastName').val(business['owner']['lastName']); 24 $('#email').val(business['owner']['email']); 25 $('#username').val(business['owner']['username']); 26 27 // services info 28 var $el = $("#predefined_services_admin_panel"); 29 $el.empty(); 30 $.each(business['services'], function (index, obj) { 31 $el.append( 32 '<div class=\"form-outline mb-4\">' + 33 ' <div class="row">' + 34 ' <div class="col-md-6">\n' + 35 ' <input class="form-check-input" type="checkbox" checked value=\"' + obj.id + '\" id=\"' + obj.id + '\">\n' + 36 ' <label class="form-check-label" for=\"' + obj.id + '\">\n' + 37 obj['serviceType'].name + 38 ' </label>\n' + 39 ' </div>' + 40 ' <div class=\"form-outline col-md-2 d-grid\">' + 41 ' <input type=\"text\" id=\"' + obj.id + obj['serviceType'].name.replace(/\s/g, "") + "duration" + '\" class=\"form-control\" placeholder="time" value=\"' + obj.duration + '" />' + 42 ' </div>' + 43 ' <div class=\"form-outline col-md-2 d-grid\">' + 44 ' <input type=\"text\" id=\"' + obj.id + obj['serviceType'].name.replace(/\s/g, "") + "price" + '\" class=\"form-control\" placeholder="price" value=\"' + obj.price + '" />' + 45 ' </div>' + 46 ' </div>' + 47 '</div>'); 48 }); 49 }); 4 getBusinessInfo(business); 5 6 getAppointments(); 50 7 51 8 $("#add_service").click(function () { … … 122 79 $("#update_owner_button").click(function() { 123 80 businesses = []; 124 console.log("Gjoko");125 81 business['owner']['firstName'] = $('#firstName').val(); 126 82 business['owner']['lastName'] = $('#lastName').val(); 127 83 business['owner']['email'] = $('#email').val(); 84 business['owner']['phoneNumber'] = $('#phoneNumber').val(); 128 85 business['owner']['username'] = $('#username').val(); 129 86 … … 147 104 event.preventDefault(); 148 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 } -
Property mode
changed from
Note:
See TracChangeset
for help on using the changeset viewer.