3 window._w.appointmentedit = {
12 highestOfferId : false,
14 publicCentreList : {},
16 idSource : 'appointmentedit',
18 onValuationAppointmentEditTemplateReady : function( template, event, eventData )
20 _w.appointmentedit.itemData = null;
21 _w.appointmentedit.ti = _t[template];
22 _w.appointmentedit.limited = false;
24 //console.log('_w.appointmentId',_w.appointmentId);
26 App.DataStore.loadSelectListData('appointmentTimeSlot', true, 'Valuation', 'ValuationTimeSlots.SelectList');
28 _w.appointmentedit.setCalendarValuationViewFormMeta();
29 _w.appointmentedit.ti.hydrate(_w.appointmentedit.formMeta);
30 // Retrieve initial view data.
31 _w.appointmentedit.itemId = '' != _w.appointmentId && undefined != _w.appointmentId ? _w.appointmentId : 0;
33 _w.appointmentedit.newItem = true;
34 _w.appointmentedit.itemData = {ValuationAppointments:{}};
36 // 'createappointmentedit', 'Valuation', 'ValuationAppointments.Create',
37 // null, {}, function(){}, _w.taskContractError
41 'calendarValuationUpdate:' + _w.appointmentedit.itemId, 'Valuation', 'ValuationAppointments.Update', null,
42 {'id':_w.appointmentedit.itemId}, $.proxy( _w.appointmentedit._onCalendarValuationViewDataReceived, this ), _w.taskContractError
46 // 'calendarValuationCreate:' + _w.appointmentedit.itemId, 'Valuation', 'ValuationAppointments.Create', _w.appointmentedit.itemId,
47 // {'id':_w.appointmentedit.itemId}, $.proxy( _w.appointmentedit._onCalendarValuationViewDataReceived, this ), _w.taskContractError
51 // 'calendarValuationUpdate:' + _w.appointmentedit.itemId, 'Valuation', 'ValuationAppointments.Update', null,
52 // {'id':_w.appointmentedit.itemId},
53 // $.proxy( function(responce){
55 // console.log('responce',responce);
58 // 'calendarValuationUpdate:' + _w.appointmentedit.itemId, {'id':_w.appointmentedit.itemId}, {},
59 // $.proxy( _w.appointmentedit._onCalendarValuationViewDataReceived, this ),
60 // _w.customercompletevaluation._onValuationFail
63 // _w.taskContractError
67 // 'createCustomerValuation', data, {},
68 // _w.customercompletevaluation._onValuationUpdated,
69 // _w.customercompletevaluation._onValuationFail
73 onValuationAppointmentEditPublished : function( template, event, eventData )
75 $('#frmModal').modal({
80 _w.appointmentedit.limited = false;
81 _w.appointmentedit._setupValidation();
83 $('#btnSaveAppointment').prop('disabled', true);
84 $('#btnSaveAppointment').show();
88 _onCalendarValuationViewDataReceived : function( response )
90 console.log('response.Data',response.Data);
92 _w.appointmentedit.itemId = response.Data.id;
93 _w.appointmentedit.itemData = response.Data;
94 _w.appointmentedit.setCalendarValuationViewFormMeta(response.Data);
95 _w.appointmentedit.ti.hydratePartial(_w.appointmentedit.formMeta);
96 if (_w.appointmentedit.ti.published)
98 _w.appointmentedit._setupValidation();
102 setCalendarValuationViewFormMeta : function(data)
106 data = {"ValuationAppointments":{},"valuation":{},"timeSlot":{}};
109 console.log('data'.data);
111 if(undefined != data.appointmentDate)
113 _w.appointmentDateData = data.appointmentDate.replace(/ 00:00:00/g,'');
115 if(undefined != data.timeSlot && undefined != data.timeSlot.timeSlot)
117 var appointmentTimeSlotData = data.timeSlot.timeSlot.split(' - ');
119 _w.appointmentTimeSlotData = appointmentTimeSlotData[1];
122 _w.appointmentedit.formMeta = {
128 value : data.valuation.firstName ? data.valuation.firstName : ''
134 value : data.valuation.familyName ? data.valuation.familyName : ''
139 title : 'Email address',
140 value : data.valuation.email ? data.valuation.email : ''
146 value : data.valuation.mobile ? data.valuation.mobile : ''
149 'appointmentDate' : {
151 id : 'appointmentDate',
152 title : 'Appointment Date',
153 style : 'datepicker',
154 value : data.appointmentDate ? data.appointmentDate.replace(/ 00:00:00/g,'') : ''
160 title : 'Appointment Time',
161 dataStoreId : 'appointmentTimeSlot',
162 value : data.timeSlot.id ? data.timeSlot.id : ''
165 'appointmentCancelledComments' : {
166 type : 'textarea-styled',
168 id : 'appointmentCancelledComments',
169 title : 'Cancellation Reason',
170 style : 'damages-comments',
171 value : data.appointmentCancelledComments ? data.appointmentCancelledComments : ''
174 'appointmentCompleted': {
176 id: 'appointmentCompleted',
177 title: 'Appointment Completed',
178 value: data.appointmentCompleted ? data.appointmentCompleted : false
181 'appointmentCancelled': {
183 id: 'appointmentCancelled',
184 title: 'Cancel Appointment',
185 value: data.appointmentCancelled ? data.appointmentCancelled : false
189 'customerAddressStreet' : {
191 id : 'customerAddressStreet',
192 title : 'Street/Unit/Building No',
193 value : data.valuation.customerAddressStreet ? data.valuation.customerAddressStreet : ''
195 'customerAddressStreetName' : {
197 id : 'customerAddressStreetName',
198 title : 'Street Name',
199 value : data.valuation.customerAddressStreetName ? data.valuation.customerAddressStreetName : ''
201 'customerAddressSuburb' : {
203 id : 'customerAddressSuburb',
204 title : 'Suburb / District',
205 value : data.valuation.customerAddressSuburb ? data.valuation.customerAddressSuburb : ''
207 'customerAddressCity' : {
209 id : 'customerAddressCity',
210 title : 'City / Town',
211 value : data.valuation.customerAddressCity ? data.valuation.customerAddressCity : ''
213 'customerAddressPostalCode' : {
215 id : 'customerAddressPostalCode',
216 title : 'Postal Code',
217 value : data.valuation.customerAddressPostalCode ? data.valuation.customerAddressPostalCode : ''
222 _listMakesModelsTypes : function( fromItemData, callback )
227 _setupValidation : function ()
230 $('#btnSaveAppointment').click(function () {
231 $('#btnSaveAppointment').prop('disabled', true);
232 $('#terms').prop('disabled', true);
233 if (!$('#frmAppointmentView').valid())
235 $('#btnSaveAppointment').prop('disabled', false);
240 var data = _w.appointmentedit._prepValuationUpdateData();
242 console.log('data',data);
245 'calendarValuationUpdate:' + _w.appointmentedit.itemId, data, {},
246 _w.appointmentedit._onValuationUpdated,
247 _w.appointmentedit._onValuationFail
251 $('.appointmentCancelledComments').hide();
252 $('.appointmentCompleted').hide();
253 $('.datepicker').datepicker({format:"yyyy-mm-dd"});
255 if($('#appointmentCancelled').is(':checked'))
257 $('.appointmentCancelledComments').show();
258 $('.appointmentCancelledComments').removeClass('hide');
259 $('#appointmentCancelledComments').attr('required',true);
262 $('#appointmentCancelled').change(function() {
264 if($('#appointmentCancelled').is(':checked'))
266 $('.appointmentCancelledComments').show();
267 $('.appointmentCancelledComments').removeClass('hide');
268 $('#appointmentCancelledComments').attr('required',true);
272 $('.appointmentCancelledComments').hide();
273 $('#appointmentCancelledComments').removeAttr('required')
277 var calendarAppointmentDateData = _w.appointmentDateData.replace(/-/g,'');
278 var calendarAppointmentTimeSlotData = _w.appointmentTimeSlotData.replace(/:/g,'');
280 var date = new Date();
281 var day = (date.getDate() < 10 ? '0' : '') + date.getDate();
283 var month = ((date.getMonth() + 1) < 10 ? '0' : '') + (date.getMonth() + 1);
284 var year = date.getFullYear();
285 var hour = (date.getHours() < 10 ? '0' : '') + date.getHours();
286 var minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes();
288 if(year+month+day+hour+minutes > calendarAppointmentDateData+calendarAppointmentTimeSlotData)
290 $('.appointmentCompleted').show();
291 $('.appointmentCompleted').removeClass('hide');
294 $('#appointmentCompleted').change(function() {
296 if($('#appointmentCompleted').is(':checked'))
298 $('.appointmentCancelled').hide();
299 $('.appointmentCancelledComments').hide();
303 $('.appointmentCancelled').show();
304 if($('#appointmentCancelled').is(':checked'))
306 $('.appointmentCancelledComments').show();
312 App.DataStore.listen('regValidation', 'damages', function(id, damages) {
314 firstName: {required: true, minlength: 3},
315 familyName: {required: true, minlength: 3},
316 email: {required: true, email: true},
317 mobile: {required: true, mobile: true},
318 requiredPrice: {required: true, number: true, min: 0.01},
319 amountOffered: {required: true, number: true, min: 0.01},
321 customerAddressStreet: {required: true},
322 customerAddressStreetName: {required: true},
323 customerAddressSuburb: {required: true},
324 customerAddressCity: {required: true},
325 customerAddressPostalCode: { required: true, digits: true }
328 for (var i = 0; i < damages.length; i++)
330 rules['damage' + damages[i].value + 'Amount'] = {number: true};
332 $('#frmAppointmentView').validate({
336 minlength: "This field is required."
339 minlength: "This field is required."
342 required: "This field is required.",
343 email: "Please enter a valid<br/>email address."
345 customerAddressStreet : "This field is required.",
346 customerAddressStreetName : "This field is required.",
347 customerAddressSuburb : "This field is required.",
348 customerAddressCity : "This field is required.",
349 customerAddressPostalCode : {required: "This field is required."}
351 invalidHandler: function(event, validator) {
352 var errors = validator.numberOfInvalids();
353 if (0 < _w.appointmentedit.validations && errors) {
354 var message = errors == 1
355 ? 'You missed 1 field. It has been highlighted'
356 : 'You missed ' + errors + ' fields. They have been highlighted';
359 _w.appointmentedit.validations++;
361 submitHandler: function( form ) {
366 _w.appointmentedit.validations = 0;
367 $('#frmAppointmentView').valid();
369 $('label.error').remove();
370 $('.valid').removeClass('valid');
374 _prepValuationUpdateData : function()
376 function isValidEmailAddress(emailAddress) {
377 var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
378 return pattern.test(emailAddress);
381 var data = _w.appointmentedit.ti.harvest();
384 var postData = {ValuationAppointments:{}, Valuation:{}};
385 var valuationFields = [
386 "firstName","familyName","mobile",
387 "email", "customerAddressStreet", "customerAddressStreetName", "customerAddressSuburb", "customerAddressCity", "customerAddressPostalCode",
390 for (var field in data)
392 if (-1 == valuationFields.indexOf(field))
394 postData.ValuationAppointments[field] = data[field];
398 postData.Valuation[field] = data[field];
402 if ('' != postData.ValuationAppointments.appointmentDate)
404 //var appointmentDate = new Date(postData.ValuationAppointments.appointmentDate);
406 //postData.ValuationAppointments.appointmentDate = appointmentDate;
408 postData.ValuationAppointments.appointmentDate = postData.ValuationAppointments.appointmentDate + ' 00:00:00';
411 if( !isValidEmailAddress( postData.Valuation.email ) )
413 testEmail = postData.Valuation.email;
414 //console.log("went through check", testEmail);
415 postData.Valuation.email = null;
419 if ('' == postData.Valuation.email)
421 postData.Valuation.email = null;
427 _onValuationUpdated : function( response )
429 //alert('Your vehicle has successfully been submitted.');
430 //window.location.hash = '/valuationcalendar';
432 //window.location.hash = "/valuationcalendar"; //Whatever is your hash value
435 $('#calendar').fullCalendar('removeEvents');
437 var userId = App.userData.id
440 "url" : 'workspace/get-calendar-events',
441 "data" : {'userId' : userId}
443 $.proxy(function(response) {
445 //console.log('response',response);
447 var calendarEvents = [];
449 $.each( response, function( responseKey, responseValue ) {
451 $.each( responseValue, function( responseK, responseV ) {
453 var startDate = responseV.start.replace("SAST", "T");
454 var endDate = responseV.end.replace("SAST", "T");
458 'title' : responseV.title,
461 //'url' : '/#/appointmentedit',
462 'id' : responseV.appointmentId,
463 'appointmentCompleted' : responseV.appointmentCompleted,
464 'appointmentCancelled' : responseV.appointmentCancelled
470 //this.createCalendar(calendarEvents);
472 //console.log('calendarEvents',calendarEvents);
474 $('#calendar').fullCalendar( 'addEventSource', calendarEvents);
477 $.proxy(function(response) {
478 console.log('App.Notification.remove Error', response);
484 $('#frmModal .close').click();
487 _onValuationFail : function( response )
489 alert('Oops, something went wrong, please check your data carefully and try again.');
490 //window.location.hash = '/public-landing';