3 window._w.customercompletevaluation = {
12 highestOfferId : false,
14 publicCentreList : {},
17 onCustomerCompleteValuationViewTemplateReady : function( template, event, eventData )
19 //console.log('onCustomerCompleteValuationViewTemplateReady');
21 _w.customercompletevaluation.itemData = null;
22 _w.customercompletevaluation.ti = _t[template];
23 _w.customercompletevaluation.limited = false;
24 // Retrieve initial view data.
25 _w.customercompletevaluation.itemId = 0;
27 var customerHash = App.Util.getUrlParam('customer');
28 //console.log('hash', customerHash);
31 "url" : 'workspace/complete-valuation-get-customer',
32 "data" : {'customerHash' : customerHash}
34 $.proxy(function(response) {
36 console.log('response',response);
40 alert(response.Error);
44 _w.customercompletevaluation.itemId = response.Success.valuationId;
46 'updateValuation:' + _w.customercompletevaluation.itemId, 'Valuation', 'Valuation.UpdateCompleteCustomerPublic', null,
47 {'id':_w.customercompletevaluation.itemId}, $.proxy( _w.customercompletevaluation._onCustomerCompleteValuationViewDataReceived, this ), _w.taskContractError
52 "url" : 'workspace/populate-complete-valuation-appointment-table',
53 "data" : {'currentPosition' : '0','valuationId' : _w.customercompletevaluation.itemId}
55 $.proxy(function(response) {
56 $('#completeValuationGridColumnHeaders').html(response.outputTableHeader);
57 $('#completeValuationGridRowRepeater').html(response.outputTableBody);
61 $.proxy(function(response) {
62 console.log('App.Notification.remove Error', response);
67 $.proxy(function(response) {
68 console.log('App.Notification.remove Error', response);
73 _w.customercompletevaluation.setValuationViewFormMeta();
74 _w.customercompletevaluation.ti.hydrate(_w.customercompletevaluation.formMeta);
77 _w.customercompletevaluation.newItem = true;
78 _w.customercompletevaluation.itemData = {stock:{}};
80 'createCustomerValuation', 'Valuation', 'Valuation.CreateCompleteCustomerPublic',
81 null, {}, function(){}, _w.taskContractError
85 onCustomerCompleteValuationViewPublished : function( template, event, eventData )
89 'createCustomerValuation', 'Valuation', 'Valuation.CreateCompleteCustomerPublic',
90 null, {}, function(){}, _w.taskContractError
93 $('#table-form-actions-prev').click(function () {
96 "url" : 'workspace/populate-complete-valuation-appointment-table',
97 "data" : {'currentPosition' : '-1','valuationId' : _w.customercompletevaluation.itemId}
99 $.proxy(function(response) {
101 //console.log('response',response.outputTableHeader);
103 $('#completeValuationGridColumnHeaders').html(response.outputTableHeader);
105 $('#completeValuationGridRowRepeater').html(response.outputTableBody);
109 $.proxy(function(response) {
110 console.log('App.Notification.remove Error', response);
115 $('#table-form-actions-next').click(function () {
118 "url" : 'workspace/populate-complete-valuation-appointment-table',
119 "data" : {'currentPosition' : '+1','valuationId' : _w.customercompletevaluation.itemId}
121 $.proxy(function(response) {
123 //console.log('response',response.outputTableHeader);
125 $('#completeValuationGridColumnHeaders').html(response.outputTableHeader);
127 $('#completeValuationGridRowRepeater').html(response.outputTableBody);
131 $.proxy(function(response) {
132 console.log('App.Notification.remove Error', response);
139 // Do a check here for the ie browser - if ie show upload file buttons
140 // IE browsers prevent submitting files when the input field didn't receive a direct click
142 if(navigator.appVersion.indexOf("MSIE ")!=-1)
144 $('#terms').parent().addClass("IE");
148 _w.customercompletevaluation.limited = false;
149 _w.customercompletevaluation._setupValidation();
151 $('.back-btn').on('click', function(){
152 window.history.back();
155 $('#btnContinue1').click(function () {
157 $('.btn-next').click();
160 $('#btnContinue2').click(function () {
162 $('.btn-next').click();
165 $('#btnContinue3').click(function () {
168 $('#btnContinue4').click(function () {
169 //$('#frmCustomerCompleteValuationView').submit();
170 _w.customercompletevaluation._setupValidation();
173 var data = _w.customercompletevaluation._prepValuationUpdateData();
175 console.log('updateValuation ' + _w.customercompletevaluation.itemId + ' data',data);
178 'updateValuation:' + _w.customercompletevaluation.itemId, data, {},
179 _w.customercompletevaluation._onValuationUpdated,
180 _w.customercompletevaluation._onValuationFail
183 $('.btn-prev').click($.proxy(function () {
184 _w.customercompletevaluation.currentStep--;
186 //$('.btn-next').click($.proxy(function () {
187 // console.log('button .btn-next','click');
189 // $('.btn-next').prop('disabled', true);
190 // _w.customercompletevaluation.currentStep++;
191 // //_w.customercompletevaluation.validatePage(_w.customercompletevaluation.currentStep);
194 $('.btn-next').click($.proxy(function () {
195 //console.log('button .btn-next','click');
196 //console.log('button .btn-next _w.customervaluation.currentStep',_w.customervaluation.currentStep);
197 $('.btn-next').prop('disabled', true);
198 _w.customercompletevaluation.currentStep++;
199 //_w.customercompletevaluation.validatePage(_w.customercompletevaluation.currentStep);
202 $('#btnContinue2').hide();
203 $('#btnContinue3').hide();
205 $('#btnContinue4').prop('disabled', true);
207 $('#terms').change($.proxy(function () {
209 if($('#terms').is(':checked'))
211 $('#btnContinue4').prop('disabled', false);
215 $('#btnContinue4').prop('disabled', true);
221 _onCustomerCompleteValuationViewDataReceived : function( response )
223 console.log('response.Data',response.Data);
225 _w.customercompletevaluation.itemId = response.Data.id;
226 _w.customercompletevaluation.itemData = response.Data;
227 _w.customercompletevaluation.setValuationViewFormMeta(response.Data);
228 _w.customercompletevaluation.ti.hydratePartial(_w.customercompletevaluation.formMeta);
229 if (_w.customercompletevaluation.ti.published)
231 _w.customercompletevaluation._setupValidation();
235 goToNext : function(profile,dateNo,valuatorNo)
237 //console.log('profile',profile);
238 //console.log('dateNo',dateNo);
241 "url" : 'workspace/populate-complete-valuation-appointment-time-table',
242 "data" : {'profileId' : profile,'dateNo' : dateNo,'valuatorNo' : valuatorNo}
244 $.proxy(function(response) {
246 //console.log('goToNext response',response);
249 $('#valuatorSelected').val(profile);
250 $('#dateSelected').val(response.dateSelected);
252 $('#completeValuationGridColumnHeadersTime').html(response.outputTableHeader);
254 $('#completeValuationGridRowRepeaterTime').html(response.outputTableBody);
256 $('.btn-next').click();
259 $.proxy(function(response) {
260 console.log('App.Notification.remove Error', response);
265 goToFinish : function(timeSlotId,timeSlot)
267 //console.log('timeSlot',timeSlot);
269 $('#timeSelected').val(timeSlot);
270 $('#timeIdSelected').val(timeSlotId);
273 firstName: {required: true, minlength: 3},
274 familyName: {required: true, minlength: 3},
275 email: {required: true, email: true},
276 mobile: {required: true, mobile: true},
277 customerAddressStreet: {required: true},
278 customerAddressStreetName: {required: true},
279 customerAddressSuburb: {required: true},
280 customerAddressCity: {required: true},
281 customerAddressPostalCode: { required: true, digits: true }
283 $('#frmCustomerCompleteValuationView').validate({
287 minlength: "This field is required."
290 minlength: "This field is required."
293 required: "This field is required.",
294 email: "Please enter a valid<br/>email address."
296 customerAddressStreet : "This field is required.",
297 customerAddressStreetName : "This field is required.",
298 customerAddressSuburb : "This field is required.",
299 customerAddressCity : "This field is required.",
300 customerAddressPostalCode : {required: "This field is required."}
302 invalidHandler: function(event, validator) {
303 var errors = validator.numberOfInvalids();
304 if (0 < _w.customercompletevaluation.validations && errors) {
305 var message = errors == 1
306 ? 'You missed 1 field. It has been highlighted'
307 : 'You missed ' + errors + ' fields. They have been highlighted';
310 _w.customercompletevaluation.validations++;
312 submitHandler: function( form ) {
317 _w.customercompletevaluation.validations = 0;
318 var formValid = $('#frmCustomerCompleteValuationView').valid();
322 var confirmationOfpublicDealer = $('#publicDealer').val();
323 var confirmationOfpublicDealerContactNumber = $('#publicDealerContactNumber').val();
325 var confirmationOffirstName = $('#firstName').val();
326 var confirmationOffamilyName = $('#familyName').val();
327 var confirmationOfmobile = $('#mobile').val();
328 var confirmationOfemail = $('#email').val();
330 var confirmationOfcustomerAddressStreet = $('#customerAddressStreet').val();
331 var confirmationOfpublicustomerAddressStreetName = $('#customerAddressStreetName').val();
332 var confirmationOfcustomerAddressSuburb = $('#customerAddressSuburb').val();
333 var confirmationOfcustomerAddressCity = $('#customerAddressCity').val();
334 var confirmationOfcustomerAddressPostalCode = $('#customerAddressPostalCode').val();
336 var confirmationOfdateSelected = $('#dateSelected').val();
337 var confirmationOftimeSelected = $('#timeSelected').val();
339 var confirmationOfInfoHtml =
340 '<div class="span12">'
342 + confirmationOfpublicDealer
344 + confirmationOfpublicDealerContactNumber
351 + '<h4>Date / Time:<h4>'
353 + '<h5>' + confirmationOfdateSelected + '</h5>'
354 + '<h5>' + confirmationOftimeSelected + '</h5>'
359 + '<h4>Your Address:<h4>'
361 + '<h5>' + confirmationOfcustomerAddressStreet + '</h5>'
362 + '<h5>' + confirmationOfpublicustomerAddressStreetName + '</h5>'
363 + '<h5>' + confirmationOfcustomerAddressSuburb + '</h5>'
364 + '<h5>' + confirmationOfcustomerAddressCity + '</h5>'
365 + '<h5>' + confirmationOfcustomerAddressPostalCode + '</h5>'
372 + '<h5>' + confirmationOfemail + '</h5>'
375 $('#confirmationOfInfo').html(confirmationOfInfoHtml);
377 $('.btn-next').click();
381 $('label.error').remove();
382 $('.valid').removeClass('valid');
384 //$('.btn-next').click();
387 validatePage : function(step)
389 //console.log('validatePage step',step)
401 '#customerAddressStreet': true,
402 '#customerAddressStreetName': true,
403 '#customerAddressSuburb': true,
404 '#customerAddressCity': true,
405 '#customerAddressPostalCode': true
410 for (var field in fields)
412 if ('' !== $(field).val() && null !== $(field).val())
414 if (!$(field).valid())
416 $('.btn-next').prop('disabled', true);
417 $('#btnContinue' + step).prop('disabled', true);
421 else if (fields[field])
423 $('.btn-next').prop('disabled', true);
424 $('#btnContinue' + step).prop('disabled', true);
430 $('.btn-next').prop('disabled', false);
431 $('#btnContinue' + step).prop('disabled', false);
435 setValuationViewFormMeta : function(data)
443 $('#vehicleYear').val(data.stock.vehicleYear);
444 $('#registrationNumber').val(data.stock.registrationNumber);
445 $('#fuelType').val(data.stock.fuelType);
446 $('#transmissionType').val(data.stock.transmissionType);
448 $('#publicDealer').val(data.stock.company.name);
449 $('#publicDealerContactNumber').val(null != data.stock.company.contact.office && '' != data.stock.company.contact.office ? data.stock.company.contact.office : data.stock.company.contact.mobile);
452 //console.log('data',data);
454 _w.customercompletevaluation.formMeta = {
459 value : data.firstName ? data.firstName : '',
460 onChange : function (evt) {
461 var value = $(evt.currentTarget).val();
462 if (null == value || '' == value)
466 _w.customercompletevaluation.validatePage(1);
473 value : data.familyName ? data.familyName : '',
474 onChange : function (evt) {
475 var value = $(evt.currentTarget).val();
476 if (null == value || '' == value)
480 _w.customercompletevaluation.validatePage(1);
486 title : 'Email address',
487 value : data.email ? data.email : '',
488 onChange : function (evt) {
489 var value = $(evt.currentTarget).val();
490 if (null == value || '' == value)
494 _w.customercompletevaluation.validatePage(1);
501 value : data.mobile ? data.mobile : '',
502 onChange : function (evt) {
503 var value = $(evt.currentTarget).val();
504 if (null == value || '' == value)
508 _w.customercompletevaluation.validatePage(1);
511 'customerAddressStreet' : {
513 id : 'customerAddressStreet',
514 title : 'Street/Unit/Building No',
515 value : data.customerAddressStreet ? data.customerAddressStreet : '',
516 onChange : function (evt) {
517 var value = $(evt.currentTarget).val();
518 if (null == value || '' == value)
522 _w.customercompletevaluation.validatePage(1);
525 'customerAddressStreetName' : {
527 id : 'customerAddressStreetName',
528 title : 'Street Name',
529 value : data.customerAddressStreetName ? data.customerAddressStreetName : '',
530 onChange : function (evt) {
531 var value = $(evt.currentTarget).val();
532 if (null == value || '' == value)
536 _w.customercompletevaluation.validatePage(1);
539 'customerAddressSuburb' : {
541 id : 'customerAddressSuburb',
542 title : 'Suburb / District',
543 value : data.customerAddressSuburb ? data.customerAddressSuburb : '',
544 onChange : function (evt) {
545 var value = $(evt.currentTarget).val();
546 if (null == value || '' == value)
550 _w.customercompletevaluation.validatePage(1);
553 'customerAddressCity' : {
555 id : 'customerAddressCity',
556 title : 'City / Town',
557 value : data.customerAddressCity ? data.customerAddressCity : '',
558 onChange : function (evt) {
559 var value = $(evt.currentTarget).val();
560 if (null == value || '' == value)
564 _w.customercompletevaluation.validatePage(1);
567 'customerAddressPostalCode' : {
569 id : 'customerAddressPostalCode',
570 title : 'Postal Code',
571 value : data.customerAddressPostalCode ? data.customerAddressPostalCode : '',
572 onChange : function (evt) {
573 var value = $(evt.currentTarget).val();
574 if (null == value || '' == value)
578 _w.customercompletevaluation.validatePage(1);
584 _listMakesModelsTypes : function( fromItemData, callback )
588 _setupValidation : function ()
591 firstName: {required: true, minlength: 3},
592 familyName: {required: true, minlength: 3},
593 email: {required: true, email: true},
594 mobile: {required: true, mobile: true},
595 customerAddressStreet: {required: true},
596 customerAddressStreetName: {required: true},
597 customerAddressSuburb: {required: true},
598 customerAddressCity: {required: true},
599 customerAddressPostalCode: { required: true, digits: true }
601 $('#frmCustomerCompleteValuationView').validate({
605 minlength: "This field is required."
608 minlength: "This field is required."
611 required: "This field is required.",
612 email: "Please enter a valid<br/>email address."
614 customerAddressStreet : "This field is required.",
615 customerAddressStreetName : "This field is required.",
616 customerAddressSuburb : "This field is required.",
617 customerAddressCity : "This field is required.",
618 customerAddressPostalCode : {required: "This field is required."}
620 invalidHandler: function(event, validator) {
621 var errors = validator.numberOfInvalids();
622 if (0 < _w.customercompletevaluation.validations && errors) {
623 var message = errors == 1
624 ? 'You missed 1 field. It has been highlighted'
625 : 'You missed ' + errors + ' fields. They have been highlighted';
628 _w.customercompletevaluation.validations++;
630 submitHandler: function( form ) {
635 _w.customercompletevaluation.validations = 0;
636 $('#frmCustomerCompleteValuationView').valid();
638 $('label.error').remove();
639 $('.valid').removeClass('valid');
643 _prepValuationUpdateData : function()
645 function isValidEmailAddress(emailAddress) {
646 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);
647 return pattern.test(emailAddress);
650 var data = _w.customercompletevaluation.ti.harvest();
652 data.valuatorId = $('#valuatorSelected').val();
653 data.dateSelected = $('#dateSelected').val();
654 data.timeIdSelected = $('#timeIdSelected').val();
655 data.vehicleYear = $('#vehicleYear').val();
656 data.registrationNumber = $('#registrationNumber').val();
657 data.fuelType = $('#fuelType').val();
658 data.transmissionType = $('#transmissionType').val();
660 //console.log('data',data);
662 var postData = {Stock:{}, Valuation:{}};
663 var valuationFields = [
664 "firstName","familyName","mobile", "email", "customerAddressStreet", "customerAddressStreetName", "customerAddressSuburb", "customerAddressCity", "customerAddressPostalCode"
666 for (var field in data)
668 if (-1 == valuationFields.indexOf(field))
670 postData.Stock[field] = data[field];
674 postData.Valuation[field] = data[field];
679 if( !isValidEmailAddress( postData.Valuation.email ) )
681 testEmail = postData.Valuation.email;
682 //console.log("went through check", testEmail);
683 postData.Valuation.email = null;
687 postData.Valuation.valuatorSelected = data.valuatorId;
688 postData.Valuation.dateSelected = data.dateSelected;
689 postData.Valuation.timeIdSelected = data.timeIdSelected;
691 if ('' == postData.Valuation.email)
693 postData.Valuation.email = null;
699 _onValuationUpdated : function( response )
701 //alert('Your vehicle has successfully been submitted.');
702 window.location.hash = '/thankyouvaluation';
704 //send customer valuation email
706 _onValuationFail : function( response )
708 console.log('_onValuationFail response',response);
710 alert('Oops, something went wrong, please check your data carefully and try again.');
711 //window.location.hash = '/public-landing';