13 onTemplateReady : function( template, event, eventData )
15 _w.register.ti = _t[template];
16 _w.register.limited = ('limitedregister' == template)
20 //App.DataStore.setData('companytypes', [
21 // {"value":"Limited", "label":"Limited"},
22 // {"value":"PTY Limited", "label":"PTY Limited"},
23 // {"value":"Closed Corporation", "label":"Closed Corporation"},
24 // {"value":"Sole Proprietor", "label":"Sole Proprietor"}
26 //App.DataStore.setData('dealertypes', [
27 // {"value":"Dealer", "label":"Dealer"},
28 // {"value":"Wholesale / Trader", "label":"Wholesale / Trader"},
29 // {"value":"Trade Center", "label":"Trade Center"}
31 //App.DataStore.setData('clienttypes', [
32 // {"value":"Buyer", "label":"Buyer"},
33 // {"value":"Buyer & Seller", "label":"Buyer & Seller"}
35 //App.DataStore.setData('companyturnover', [
36 // {"value":"Turnover > R500,000", "label":"Turnover > R500,000"},
37 // {"value":"Turnover > R2,000,000", "label":"Turnover > R2,000,000"},
38 // {"value":"Turnover > R3,000,000", "label":"Turnover > R3,000,000"}
40 App.DataStore.loadSelectListData('permissions', true, 'User', 'Permissions.SelectList');
41 //App.DataStore.loadSelectListData('countries', true, 'Location', 'Country.SelectList');
42 //App.DataStore.loadSelectListData('groups', true, 'Company', 'Group.SelectList');
43 //App.DataStore.loadSelectListData('foundmethods', true, 'Company', 'FoundMethod.SelectList');
47 _w.register.setRegisterViewFormMeta();
48 _w.register.ti.hydrate(_w.register.formMeta);
50 'register', 'User', 'Registration.RegisterFull', null,
51 {}, function() {}, _w.taskContractError
56 onTemplatePublished : function( template, event, eventData )
58 _w.register.ti = _t[template];
59 _w.register.setRegisterViewFormMeta();
60 _w.register.ti.hydrate(_w.register.formMeta);
61 _w.register._setupValidation();
62 $('#btnAddOwner').click(_w.register.addOwner);
65 setRegisterViewFormMeta : function( data )
71 _w.register.formMeta = {
89 // id : 'permissions',
90 // title : 'User type',
92 // dataStoreId : 'permissions',
98 title : 'Email address',
105 title : 'Confirm email address',
112 title : '4 Digit pin',
119 title : 'Confirm 4 digit pin',
129 onChange : function() {
130 var dig = $(this).val().substring(0, 6);
131 $('#dateOfBirth').val(
132 '19' + dig.substring(0, 2) +
133 '-' + dig.substring(2, 4) +
134 '-' + dig.substring(4, 6)
141 title : 'Date of birth',
142 style : 'datepicker',
148 title : 'Mobile number',
153 // Dealership contact
154 //'contactFirstName' : {
156 // id : 'contactFirstName',
161 //'contactFamilyName' : {
163 // id : 'contactFamilyName',
164 // title : 'Surname',
168 //'contactOffice' : {
170 // id : 'contactOffice',
171 // title : 'Landline',
175 //'contactMobile' : {
177 // id : 'contactMobile',
178 // title : 'Mobile number',
184 // id : 'contactEmail',
190 //// Dealership details
193 // id : 'dealerType',
194 // title : 'Registration type',
196 // dataStoreId : 'dealertypes'
200 // id : 'clientType',
201 // title : 'Register as',
203 // dataStoreId : 'clienttypes'
208 // title : 'Group Member',
210 // dataStoreId : 'groups',
211 // onChange : function () {
212 // if (!App.DataStore.getItem('BuildSelect:group', false))
214 // var groupId = $('#group').val();
215 // App.DataStore.loadSelectListData(
216 // 'groupdivisions', false, 'Company', 'GroupDivision.SelectList',
217 // null, {Filter: {group: groupId}}
222 //'groupDivision' : {
224 // id : 'groupDivision',
225 // title : 'Group Division',
227 // dataStoreId : 'groupdivisions'
231 // id : 'companyType',
232 // title : 'Company type',
234 // dataStoreId : 'companytypes',
235 // onChange : function() {
236 // if (!App.DataStore.getItem('BuildSelect:companyType', false))
238 // if ('Sole Proprietor' == $(this).val())
240 // $('#' + _w.register.ti.tid + '_docCopyOfDirectorId').hide();
241 // $('#' + _w.register.ti.tid + '_docCompanyRegistration').hide();
242 // $('#' + _w.register.ti.tid + '_docStockCertificate').show();
243 // $('#' + _w.register.ti.tid + '_docCopyOfId').show();
244 // $('#' + _w.register.ti.tid + '_docAddressProof').show();
248 // $('#' + _w.register.ti.tid + '_docStockCertificate').hide();
249 // $('#' + _w.register.ti.tid + '_docCopyOfId').hide();
250 // $('#' + _w.register.ti.tid + '_docAddressProof').show();
251 // $('#' + _w.register.ti.tid + '_docCopyOfDirectorId').show();
252 // $('#' + _w.register.ti.tid + '_docCompanyRegistration').show();
259 // id : 'businessName',
260 // title : 'Registered business name',
267 // title : 'Trading name',
271 //'companyRegistrationNumber' : {
273 // id : 'companyRegistrationNumber',
274 // title : 'Company Reg no',
276 // mask : '9999/999999/99',
288 // id : 'turmiNumber',
289 // title : 'TransUnion membership no',
293 //'dealerStockNumber' : {
295 // id : 'dealerStockNumber',
296 // title : 'Dealer stock no',
303 // title : 'Turnover',
305 // dataStoreId : 'companyturnover'
309 // id : 'foundMethod',
310 // title : 'Where did you find us?',
312 // dataStoreId : 'foundmethods',
313 // onChange : function () {
314 // if (!App.DataStore.getItem('BuildSelect:foundMethod', false))
316 // var foundId = $('#foundMethod').val();
317 // App.DataStore.loadSelectListData(
318 // 'foundmethoddetails', false, 'Company', 'FoundMethodDetail.SelectList',
319 // null, {Filter: {foundMethod: foundId}}
324 //'foundMethodDetail' : {
326 // id : 'foundMethodDetail',
327 // title : 'Details',
329 // dataStoreId : 'foundmethoddetails'
333 //// Adresses and billing contact
337 // title : 'Country',
338 // dataStoreId : 'countries',
340 // onChange : function () {
341 // if (!App.DataStore.getItem('BuildSelect:country', false))
343 // App.DataStore.loadSelectListData(
344 // 'regions', false, 'Location', 'Region.SelectList', null,
346 // "country" : $(this).val()
349 // App.DataStore.setData('cities', []);
350 // if ($('#sameAsBusinessAddress').prop('checked'))
352 // $('#billingCountry').selectpicker('val', $('#country').val());
361 // dataStoreId : 'regions',
363 // onChange : function () {
364 // if (!App.DataStore.getItem('BuildSelect:region', false))
366 // App.DataStore.loadSelectListData(
367 // 'cities', false, 'Location', 'Town.SelectList', null,
369 // "region" : $(this).val()
372 // if ($('#sameAsBusinessAddress').prop('checked'))
374 // $('#billingRegion').selectpicker('val', $('#region').val());
383 // dataStoreId : 'cities',
395 // id : 'postalCode',
400 //'sameAsBusinessAddress' : {
401 // type : 'checkbox',
402 // id : 'sameAsBusinessAddress',
403 // title : 'Same as business address',
405 // onChange : function() {
406 // if ($(this).prop('checked'))
408 // App.DataStore.setItem('BuildSelect:migrateCountry', true);
409 // $('#billingCountry').selectpicker('val', $('#country').val());
410 // App.DataStore.removeItem('BuildSelect:migrateCountry');
411 // App.DataStore.setItem('BuildSelect:migrateRegion', true);
412 // App.DataStore.loadSelectListData(
413 // 'billregions', false, 'Location', 'Region.SelectList', null,
415 // "country" : $('#country').val()
416 // }}, {}, function() {
417 // $('#billingRegion').selectpicker('val', $('#region').val());
418 // App.DataStore.removeItem('BuildSelect:migrateRegion');
421 // App.DataStore.setItem('BuildSelect:migrateTown', true);
422 // App.DataStore.loadSelectListData(
423 // 'billcities', false, 'Location', 'Town.SelectList', null,
425 // "region" : $('#region').val()
426 // }}, {}, function() {
427 // $('#billingCity').selectpicker('val', $('#city').val());
430 // $('#billingStreet').val($('#street').val());
431 // $('#billingPostalCode').val($('#postalCode').val());
435 // $('#billingCountry').selectpicker('val', '');
436 // App.DataStore.setData('billregions', []);
437 // App.DataStore.setData('billcities', []);
438 // $('#billingStreet').val('');
439 // $('#billingPostalCode').val('');
443 //'billingCountry' : {
445 // id : 'billingCountry',
446 // title : 'Country',
447 // dataStoreId : 'countries',
449 // onChange : function () {
450 // if (!App.DataStore.getItem('BuildSelect:billingCountry', false)
451 // && !App.DataStore.getItem('BuildSelect:migrateCountry', false))
453 // App.DataStore.loadSelectListData(
454 // 'billregions', false, 'Location', 'Region.SelectList', null,
456 // "country" : $(this).val()
459 // App.DataStore.setData('billcities', []);
463 //'billingRegion' : {
465 // id : 'billingRegion',
467 // dataStoreId : 'billregions',
469 // onChange : function () {
470 // if (!App.DataStore.getItem('BuildSelect:billingRegion', false)
471 // && !App.DataStore.getItem('BuildSelect:migrateRegion', false))
473 // App.DataStore.loadSelectListData(
474 // 'billcities', false, 'Location', 'Town.SelectList', null,
476 // "region" : $(this).val()
484 // id : 'billingCity',
486 // dataStoreId : 'billcities',
489 //'billingStreet' : {
491 // id : 'billingStreet',
496 //'billingPostalCode' : {
498 // id : 'billingPostalCode',
504 //'sameAsDealerContact' : {
505 // type : 'checkbox',
506 // id : 'sameAsDealerContact',
507 // title : 'Same as dealership contact',
509 // onChange : function() {
510 // if ($(this).prop('checked'))
512 // $('#billingFirstName').val($('#contactFirstName').val());
513 // $('#billingFamilyName').val($('#contactFamilyName').val());
514 // $('#billingOffice').val($('#contactOffice').val());
515 // $('#billingMobile').val($('#contactMobile').val());
516 // $('#billingEmail').val($('#contactEmail').val());
520 // $('#billingFirstName').val('');
521 // $('#billingFamilyName').val('');
522 // $('#billingOffice').val('');
523 // $('#billingMobile').val('');
524 // $('#billingEmail').val('');
528 //'billingFirstName' : {
530 // id : 'billingFirstName',
535 //'billingFamilyName' : {
537 // id : 'billingFamilyName',
538 // title : 'Surname',
542 //'billingOffice' : {
544 // id : 'billingOffice',
545 // title : 'Landline',
549 //'billingMobile' : {
551 // id : 'billingMobile',
552 // title : 'Mobile number',
558 // id : 'billingEmail',
565 //'ownerFirstName' : {
567 // id : 'ownerFirstName',
572 //'ownerFamilyName' : {
574 // id : 'ownerFamilyName',
575 // title : 'Surname',
579 //'ownerIdNumber' : {
581 // id : 'ownerIdNumber',
582 // title : 'ID Number',
587 // type : 'collector',
593 //'docStockCertificate' : {
594 // type : 'document',
595 // id : 'docStockCertificate',
596 // title : 'Dealer stock certificate',
599 //'docAddressProof' : {
600 // type : 'document',
601 // id : 'docAddressProof',
602 // title : 'Proof of business address',
606 // type : 'document',
607 // id : 'docCopyOfId',
608 // title : 'Copy of ID document',
611 //'docCopyOfDirectorId' : {
612 // type : 'document',
613 // id : 'docCopyOfDirectorId',
614 // title : 'Copy of directors ID document',
617 //'docCompanyRegistration' : {
618 // type : 'document',
619 // id : 'docCompanyRegistration',
620 // title : 'Company registration document',
624 'subscribeNewsletter' : {
626 id : 'subscribeNewsletter',
627 title : 'Sign me up for the monthly newsletter and Bid4Cars updates.',
630 'acceptTermsAndConditions' : {
632 id : 'acceptTermsAndConditions',
633 title : 'I agree to the Terms & Conditions, Website Terms & Conditions and Privacy Policy of Bid4Cars.',
635 onChange : function() {
636 $('#btnUpdate').prop('disabled', !$(this).prop('checked'));
642 addOwner : function()
644 var name = $('#ownerFirstName').val();
645 var surname = $('#ownerFamilyName').val();
646 var idnum = $('#ownerIdNumber').val();
647 if ('' == name || '' == surname || !$('#ownerIdNumber').valid())
649 alert('Please provide Name, Surname and ID number.');
652 _w.register.owners['colItem' + _w.register.counter] = {
654 familyName : surname,
657 var html = '<div class="accordion-group" id="colItem' + _w.register.counter + '">';
658 html += '<div class="accordion-heading">';
659 html += '<a class="accordion-toggle" data-toggle="collapse" data-parent="#owners" href="#collapse' + _w.register.counter + '">';
660 html += name + ' ' + surname;
663 html += '<div id="collapse' + _w.register.counter + '" class="accordion-body collapse in">';
664 html += '<div class="accordion-inner">';
665 html += name + ' ' + surname + ' (' + idnum + ')';
666 html += '<br/><button type="button" class="btn pull-right" onClick="_w.register.removeOwner(' + _w.register.counter + ');">Remove</button>';
670 $('#owners').append(html);
671 $('#collapse' + _w.register.counter).collapse('toggle');
672 _w.register.counter++;
673 _w.register.ownerCount++;
675 $('#ownerFirstName').val('');
676 $('#ownerFamilyName').val('');
677 $('#ownerIdNumber').val('');
680 removeOwner : function( id )
682 delete _w.register.owners['colItem' + id];
683 $('#colItem' + id).remove();
684 _w.register.ownerCount--;
687 _setupValidation : function ()
689 $('#frmRegister').validate({
691 firstName: {required: true},
692 familyName: {required: true},
693 permissions: {required: false},
694 email: {required: true, email: true, remote: {
695 url: "/workspace/check-unique-email",
698 confirmEmail: {required: true, email: true, equalTo: "#email"},
699 pin: {required: true, digits: true},
700 confirmPin: {required: true, digits: true, equalTo: "#pin"},
701 idNumber: {required: true, minlength: 13, maxlength: 13, digits: true},
702 dateOfBirth: {required: true, dateISO: true},
703 mobile: {required: true, mobile: true},
705 //contactFirstName: {required: true},
706 //contactFamilyName: {required: true},
707 //contactOffice: {required: true, digits: true},
708 //contactMobile: {required: true, mobile: true},
709 //contactEmail: {required: true, email: true},
711 //dealerType: {required: true},
712 //clientType: {required: true},
713 //companyType: {required: true},
714 //businessName: {required: true},
715 //name: {required: true, remote: {
716 // url: "/workspace/check-unique-company",
719 //companyRegistrationNumber: {companyReg: true},
720 //vatNumber: {digits: true},
722 //country: {required: true},
723 //region: {required: true},
724 //city: {required: true},
725 //street: {required: true},
726 //postalCode: {required: true, digits: true},
727 //billingCountry: {required: true},
728 //billingRegion: {required: true},
729 //billingCity: {required: true},
730 //billingStreet: {required: true},
731 //billingPostalCode: {required: true, digits: true},
732 //billingFirstName: {required: true},
733 //billingFamilyName: {required: true},
734 //billingOffice: {required: true, digits: true},
735 //billingMobile: {required: true, mobile: true},
736 //billingEmail: {required: true, email: true},
738 //ownerIdNumber: {minlength: 13, maxlength: 13, digits: true}
741 email: { email: "Must be a valid email address.", remote: "Email address already in use."},
742 confirmEmail: { equalTo: "Values are not the same." },
743 confirmPin: { equalTo: "Values are not the same." },
744 contactEmail: { email: "Must be a valid email address." },
745 billingEmail: { email: "Must be a valid email address." },
746 country : "This field is required.",
747 region : "This field is required.",
748 city : "This field is required.",
749 billingCountry : "This field is required.",
750 billingRegion : "This field is required.",
751 billingCity : "This field is required.",
752 permissions : "This field is required.",
753 companyType : "This field is required.",
754 dealerType : "This field is required.",
755 clientType : "This field is required."
757 submitHandler: function( form ) {
758 //if (0 == _w.register.ownerCount) {
759 //$('#ownerFirstName').addClass('error');
760 //$('#ownerFamilyName').addClass('error');
761 //$('#ownerIdNumber').addClass('error');
762 // alert('At least 1 owner / director required.');
765 $('#ownerFirstName').removeClass('error');
766 $('#ownerFamilyName').removeClass('error');
767 $('#ownerIdNumber').removeClass('error');
769 $('#btnUpdate').prop('disabled', true);
770 var data = _w.register._prepRegisterUpdateData();
772 'register', data, {},
773 _w.register._onRegisterUpdated, _w.taskExecError
777 $('#frmRegister').valid();
778 $('label.error').remove();
779 $('.valid').removeClass('valid');
782 _prepRegisterUpdateData : function()
784 var data = _w.register.ti.harvest();
791 var profileFields = [
792 "firstName","familyName","permissions","email","confirmEmail",
793 "pin","confirmPin","idNumber","dateOfBirth","mobile", "subscribeNewsletter"
795 //var companyFields = [
796 // "dealerType","clientType","group","groupDivision","companyType",
797 // "businessName","name","companyRegistrationNumber","vatNumber","turmiNumber",
798 // "dealerStockNumber","turnover","foundMethod","foundMethodDetail",
799 // "country","region","city","street","postalCode",
800 // "billingCountry","billingRegion","billingCity","billingStreet","billingPostalCode",
801 // "docStockCertificate","docAddressProof","docCopyOfId",
802 // "docCopyOfDirectorId","docCompanyRegistration"
804 var contactFields = {
805 "contactFirstName" : "firstName",
806 "contactFamilyName" : "familyName",
807 "contactOffice" : "office",
808 "contactMobile" : "mobile",
809 "contactEmail" : "email"
811 var billingContactFields = {
812 "billingFirstName" : "firstName",
813 "billingFamilyName" : "familyName",
814 "billingOffice" : "office",
815 "billingMobile" : "mobile",
816 "billingEmail" : "email"
818 for (var field in data)
820 //if (-1 != companyFields.indexOf(field))
822 // postData.Company[field] = '' != data[field] ? data[field] : null;
825 if (-1 != profileFields.indexOf(field))
827 postData.Profile[field] = '' != data[field] ? data[field] : null;
829 //else if (contactFields[field])
831 // postData.Contact[contactFields[field]] = '' != data[field] ? data[field] : null;
833 //else if (billingContactFields[field])
835 // postData.BillingContact[billingContactFields[field]] = '' != data[field] ? data[field] : null;
838 postData.Profile.password = postData.Profile.pin;
839 postData.Company.owners = _w.register.owners;
843 _onRegisterUpdated : function( response )
845 window.location.hash = '/registered';