source: src/main/resources/static/js/homepage.js@ 950fa0d

Last change on this file since 950fa0d was 950fa0d, checked in by Gjoko Kostadinov <gjoko.kostadinov@…>, 17 months ago

Periodic update

  • Property mode set to 100644
File size: 8.7 KB
Line 
1$(document).ready(function() {
2 var businessTypes = {};
3 var businesses = {};
4 var date = new Date();
5 var d = date.getDate();
6 var m = date.getMonth();
7 var y = date.getFullYear();
8
9 /* className colors
10
11 className: default(transparent), important(red), chill(pink), success(green), info(blue)
12
13 */
14
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 });
35 /* initialize the external events
36 -----------------------------------------------------------------*/
37
38 $('#external-events div.external-event').each(function() {
39
40 // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
41 // it doesn't need to have a start or end
42 var eventObject = {
43 title: $.trim($(this).text()) // use the element's text as the event title
44 };
45
46 // store the Event Object in the DOM element so we can get to it later
47 $(this).data('eventObject', eventObject);
48
49 // make the event draggable using jQuery UI
50 $(this).draggable({
51 zIndex: 999,
52 revert: true, // will cause the event to go back to its
53 revertDuration: 0 // original position after the drag
54 });
55
56 });
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
107
108 /* initialize the calendar
109 -----------------------------------------------------------------*/
110
111 var calendar = $('#calendar').fullCalendar({
112 header: {
113 left: 'title',
114 center: 'agendaWeek',
115 right: 'prev,next today'
116 },
117 editable: false,
118 edit: function (start, end, allDay) {
119 console.log(start);
120 console.log(end);
121 },
122 firstDay: 1, // 1(Monday) this can be changed to 0(Sunday) for the USA system
123 selectable: false,
124 defaultView: 'agendaWeek',
125
126 axisFormat: 'h:mm',
127 columnFormat: {
128 month: 'ddd', // Mon
129 week: 'ddd d', // Mon 7
130 day: 'dddd M/d', // Monday 9/7
131 agendaDay: 'dddd d'
132 },
133 titleFormat: {
134 month: 'MMMM yyyy', // September 2009
135 week: "MMMM yyyy", // September 2009
136 day: 'MMMM yyyy' // Tuesday, Sep 8, 2009
137 },
138 allDaySlot: false,
139 selectHelper: true,
140 select: function(start, end, allDay) {
141 var title = prompt('Event Title:');
142 if (title) {
143 calendar.fullCalendar('renderEvent',
144 {
145 title: title,
146 start: start,
147 end: end,
148 allDay: allDay
149 },
150 true // make the event "stick"
151 );
152 }
153 calendar.fullCalendar('unselect');
154 },
155 droppable: false, // this allows things to be dropped onto the calendar !!!
156 drop: function(date, allDay) { // this function is called when something is dropped
157
158 // retrieve the dropped element's stored Event Object
159 var originalEventObject = $(this).data('eventObject');
160
161 // we need to copy it, so that multiple events don't have a reference to the same object
162 var copiedEventObject = $.extend({}, originalEventObject);
163
164 // assign it the date that was reported
165 copiedEventObject.start = date;
166 copiedEventObject.allDay = allDay;
167
168 // render the event on the calendar
169 // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
170 $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);
171
172 // is the "remove after drop" checkbox checked?
173 if ($('#drop-remove').is(':checked')) {
174 // if so, remove the element from the "Draggable Events" list
175 $(this).remove();
176 }
177 console.log('dropped');
178
179 },
180
181 events: [
182 {
183 title: 'All Day Event',
184 start: new Date(y, m, 1)
185 },
186 {
187 id: 999,
188 title: 'Repeating Event',
189 start: new Date(y, m, d-3, 16, 0),
190 allDay: false,
191 className: 'info'
192 },
193 {
194 id: 999,
195 title: 'Repeating Event',
196 start: new Date(y, m, d+4, 16, 0),
197 allDay: false,
198 className: 'info'
199 },
200 {
201 title: 'Meeting',
202 start: new Date(y, m, d, 10, 30),
203 allDay: false,
204 className: 'info'
205 },
206 {
207 title: 'Lunch',
208 start: new Date(y, m, d, 12, 0),
209 end: new Date(y, m, d, 14, 0),
210 allDay: false,
211 className: 'info'
212 },
213 {
214 title: 'Birthday Party',
215 start: new Date(y, m, d+1, 19, 0),
216 end: new Date(y, m, d+1, 22, 30),
217 allDay: false,
218 },
219 {
220 title: 'Click for Google',
221 start: new Date(y, m, 28),
222 end: new Date(y, m, 29),
223 url: 'http://google.com/',
224 className: 'success'
225 }
226 ],
227 });
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();
234
235 $.ajax({
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 })
249
250});
251
252document.getElementById("login").addEventListener("click", function(event){
253 window.location = "/login";
254});
255
256function emptyDropdown(element) {
257 var defaultOption = element.children().get(0);
258 element.children().remove().end().append(defaultOption);
259}
Note: See TracBrowser for help on using the repository browser.