Changeset 950fa0d for src/main/resources/static/js/homepage.js
- Timestamp:
- 05/24/23 23:18:47 (16 months ago)
- Branches:
- master
- Children:
- 77205be
- Parents:
- 8bcd64c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/resources/static/js/homepage.js
r8bcd64c r950fa0d 1 1 $(document).ready(function() { 2 var businessTypes = {}; 3 var businesses = {}; 2 4 var date = new Date(); 3 5 var d = date.getDate(); … … 11 13 */ 12 14 13 15 $.ajax({ 16 type: 'GET', 17 url: "http://localhost:8080/api/user/me", 18 success: function(data, textStatus, request) { 19 if (data) { 20 $('#create').parent().removeClass('hidden-button'); 21 $('#profile').parent().removeClass('hidden-button'); 22 $('#logout').parent().removeClass('hidden-button'); 23 $('#login').parent().addClass('hidden-button'); 24 } else { 25 $('#create').parent().addClass('hidden-button'); 26 $('#profile').parent().addClass('hidden-button'); 27 $('#logout').parent().addClass('hidden-button'); 28 $('#login').parent().removeClass('hidden-button'); 29 } 30 }, 31 error: function (request, textStatus, errorThrown) { 32 console.log(errorThrown); 33 } 34 }); 14 35 /* initialize the external events 15 36 -----------------------------------------------------------------*/ … … 35 56 }); 36 57 58 $.ajax({ 59 url: "http://localhost:8080/api/nomenclatures/businessTypes" 60 }).then(function (data) { 61 businessTypes = data; 62 var $el = $("#companyType"); 63 emptyDropdown($el); 64 65 $.each(data, function (index, obj) { 66 $el.append("<option value=" + obj.value + ">" + obj.text + "</option>"); 67 }); 68 }); 69 70 $("#companyType").change(function () { 71 var selectedVal = $(this).find(':selected').val(); 72 var selectedObj = businessTypes[selectedVal - 1]; 73 $.ajax({ 74 url: "http://localhost:8080/api/business/" + selectedObj.value 75 }).then(function (data) { 76 businesses = data; 77 console.log(data); 78 var $el = $("#company"); 79 var $servicesEl = $("#service"); 80 emptyDropdown($el); 81 emptyDropdown($servicesEl); 82 83 $.each(data, function (index, obj) { 84 $el.append("<option value=" + obj.id + ">" + obj.companyName + "</option>"); 85 }); 86 }); 87 }); 88 89 $("#company").change(function () { 90 var selectedVal = $(this).find(':selected').val(); 91 $.ajax({ 92 url: "http://localhost:8080/api/appointment/business/" + selectedVal 93 }).then(function (data) { 94 console.log(data); 95 var $el = $("#service"); 96 emptyDropdown($el); 97 98 var services = businesses.find(item => item.id == selectedVal)['services']; 99 console.log(services); 100 101 $.each(services, function (index, obj) { 102 $el.append("<option value=" + obj.id + ">" + obj.serviceType.name + "</option>"); 103 }); 104 }); 105 }); 106 37 107 38 108 /* initialize the calendar … … 47 117 editable: false, 48 118 edit: function (start, end, allDay) { 49 119 console.log(start); 120 console.log(end); 50 121 }, 51 122 firstDay: 1, // 1(Monday) this can be changed to 0(Sunday) for the USA system … … 131 202 start: new Date(y, m, d, 10, 30), 132 203 allDay: false, 133 className: 'i mportant'204 className: 'info' 134 205 }, 135 206 { … … 138 209 end: new Date(y, m, d, 14, 0), 139 210 allDay: false, 140 className: 'i mportant'211 className: 'info' 141 212 }, 142 213 { … … 155 226 ], 156 227 }); 157 $("#search").click(function () { 158 alert("qweqew"); 228 229 $("#createAppointment").click(function() { 230 var appointment = {}; 231 appointment['business'] = {'id': parseInt($("#company").val())}; 232 appointment['service'] = {'id': parseInt($("#service").val())}; 233 appointment['startTime'] = $("#startdatetime").val(); 159 234 160 235 $.ajax({ 161 url: "http://localhost:8080/events" 162 }).then(function(data) { 163 console.log(data); 164 }); 165 }); 236 url: "http://localhost:8080/api/appointment", 237 type:"POST", 238 data: JSON.stringify(appointment), 239 contentType:"application/json; charset=utf-8", 240 dataType: 'text', 241 success: function(succ){ 242 console.log('success'); 243 }, 244 error: function(err) { 245 console.log(JSON.stringify(err)); 246 } 247 }); 248 }) 166 249 167 250 }); 168 251 169 function search() { 170 252 document.getElementById("login").addEventListener("click", function(event){ 253 window.location = "/login"; 254 }); 255 256 function emptyDropdown(element) { 257 var defaultOption = element.children().get(0); 258 element.children().remove().end().append(defaultOption); 171 259 }
Note:
See TracChangeset
for help on using the changeset viewer.