import { Component, Injector, ViewChild, ViewEncapsulation } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { appModuleAnimation } from '@shared/animations/routerTransition'; import { AppComponentBase } from '@shared/common/app-component-base'; import { CreateOrUpdateContactUserInput, DriversServiceProxy, LocationServiceProxy, CreateLocationInput, UpdateLocationInput, UserLocationServiceProxy, CreateUserLocationInput, UpdateUserLocationInput, PasswordComplexitySetting, UserRoleDto, UserEditDto, CreateContactUserAddressInput, CreateAddressInput, CreateContactInput, CreatePhoneInput, CreateEmailInput, ContactServiceProxy, AddressTypeServiceProxy, PostalCodeServiceProxy, EmailServiceProxy, PhoneServiceProxy, ProfileServiceProxy, AddressServiceProxy, CreateOrUpdateDriverInfoInput, VehicleServiceProxy, CreatePostalCodeInput, CreateDriverInput } from '@shared/service-proxies/service-proxies'; import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent'; import { finalize } from 'rxjs/operators'; import * as moment from 'moment'; import * as _ from 'lodash'; import { Location } from '@angular/common'; import { ContactFormComponent } from '@app/shared/layout/form/contact.form.component'; import { AddressFormComponent } from '@app/shared/layout/form/address-form.component'; declare var KTWizard: any; declare var $: any; declare var KTApp: any; declare let swal: any; @Component({ templateUrl: './create-driver.component.html', encapsulation: ViewEncapsulation.None, animations: [appModuleAnimation()] }) export class CreateDriverComponent extends AppComponentBase { @ViewChild(ContactFormComponent, { static: false }) contactForm; @ViewChild(AddressFormComponent, { static: false }) addressForm; active = false; saving = false; id: any; driver: UserEditDto = new UserEditDto(); contact: CreateContactUserAddressInput = new CreateContactUserAddressInput(); address: CreateAddressInput = new CreateAddressInput(); contactInput: CreateContactInput = new CreateContactInput(); driverInput: CreateOrUpdateDriverInfoInput = new CreateOrUpdateDriverInfoInput(); postalCodeInput: CreatePostalCodeInput = new CreatePostalCodeInput(); _driver: CreateDriverInput = new CreateDriverInput(); // isTwoFactorEnabled: boolean = this.setting.getBoolean('Abp.Zero.UserManagement.TwoFactorLogin.IsEnabled'); isTwoFactorEnabled: boolean = false; isLockoutEnabled: boolean = this.setting.getBoolean('Abp.Zero.UserManagement.UserLockOut.IsEnabled'); defaultLocation: any; selectedLocation: any; location: any; filteredLocations: any; getUserLocationId: any; getAddressId: any; getLocationId: any; defaultAddressType: any; defaultCountry: any; defaultState: any; defaultPostal: any; defaultCity: any; selectedAddressType: any; selectedCountry: any; selectedPostalCode: any; selectedState: any; selectedCity: any; country: any; filteredCountries: any; city: any; filteredCities: any; state: any; filteredStates: any; postal: any; filteredPostal: any; addressType: any; filteredAddressType: any; canChangeUserName = true; isActive = true; skipOrders = false; passwordComplexitySetting: PasswordComplexitySetting = new PasswordComplexitySetting(); roles: UserRoleDto[]; sendActivationEmail = true; shouldChangePasswordOnNextLogin = true setRandomPassword = true; passwordComplexityInfo = ''; addressCheckBox = false; requiredState = true; startDate: Date; endDate: Date; maximumPackageWeight: number; driverLicenseNumber: string; driverLicenseState: string; driverLicenseDate: Date; hourlyRate: number = 0; dailyRate: number = 0; perSprintRate: number = 0; onDemand: false; ownVehicle: false; isActiveDriver: false; filteredVehicle: any; stateFeature: boolean; skipOrderFeature:boolean = false; constructor( injector: Injector, private _locationService: LocationServiceProxy, private _driverService: DriversServiceProxy, private _userLocationService: UserLocationServiceProxy, private _contactService: ContactServiceProxy, // private _countryService: CountryServiceProxy, // private _cityService: CityServiceProxy, // private _stateService: StateServiceProxy, private _addressTypeService: AddressTypeServiceProxy, private _postalCodeService: PostalCodeServiceProxy, private _profileService: ProfileServiceProxy, private _addressService: AddressServiceProxy, private _emailService: EmailServiceProxy, private _phoneService: PhoneServiceProxy, private router: Router, private route: ActivatedRoute, private _location: Location, private _vehicleService: VehicleServiceProxy, private _postalCodeServiceProxy: PostalCodeServiceProxy ) { super(injector); } setPasswordComplexityInfo(): void { this.passwordComplexityInfo = ''; } ngOnInit() { $('.kt-select2').select2({ placeholder: "Select.." }); this.stateFeature = abp.features.isEnabled('App.StateFeature'); this.skipOrderFeature = abp.features.isEnabled('App.SkipOrders'); this.route.paramMap.subscribe(params => { this.id = params.get("id") }) // this.KTWizard2(); // $('#addressCheckbox').prop('checked', false); // $('#address').fadeOut('slow'); $("#addressTypeSelectInput").change(function () { this.selectedAddressType = $("#addressTypeSelectInput option:selected").text(); $("#selectedAddressType").text(this.selectedAddressType); }); $("#countrySelectInput").change(function () { this.selectedCountry = $("#countrySelectInput option:selected").text(); $("#selectedCountry").text(this.selectedCountry + ","); }); // $("#postalSelectInput").change(function () { // this.selectedPostalCode = $("#postalSelectInput option:selected").text(); // $("#selectedPostalCode").text(this.selectedPostalCode + ","); // }); // $("#stateSelectInput").change(function () { // this.selectedState = $("#stateSelectInput option:selected").text(); // $("#selectedState").text(this.selectedState + ","); // }); // $("#citySelectInput").change(function () { // this.selectedCity = $("#citySelectInput option:selected").text(); // $("#selectedCity").text(this.selectedCity + ","); // }); $("#locationSelectInput").change(function () { this.selectedCity = $("#locationSelectInput option:selected").text(); $("#locationSelected").text(this.selectedCity + ""); }); var KTWizard2 = function () { var e, r, i; return { init: function () { var t; KTUtil.get("kt_wizard_v2"), e = $("#kt_form"), (i = new KTWizard("kt_wizard_v2", { startStep: 1, clickableSteps: !0 })).on("beforeNext", function (e) { !0 !== r.form() && e.stop() }), i.on("beforePrev", function (e) { !0 !== r.form() && e.stop() }), i.on("change", function (e) { KTUtil.scrollTop() }), r = e.validate({ ignore: ":hidden", rules: { Name: { required: !0 }, Surname: { required: !0 }, EmailAddress: { required: !0, email: !0 }, locationSelectInput: { required: !0 }, UserName: { required: !0 }, Password: { required: !0, minlength: 5,}, PasswordRepeat: { required: !0, minlength: 5, equalTo: "#Password" }, Address1: { required: !0 }, //State: { required: !0 }, //Country: { required: !0 }, postalSelectInput: { required: !0 }, country: { required: !0 }, state: { required: !0 } // hourlyRate: { required: !0 }, // DailyRate: { required: !0 }, // PerSprintRate: { required: !0 } }, invalidHandler: function (e, r) { // KTUtil.scrollTop(), swal.fire({ // title: "", text: "There are some errors in your submission. Please correct them.", // type: "error", confirmButtonClass: "btn btn-secondary" // }) }, submitHandler: function (e) { } }) } } }(); jQuery(document).ready(function () { KTWizard2.init(); }); this.filterVehicle(); this._profileService.getPasswordComplexitySetting().subscribe(passwordComplexityResult => { this.passwordComplexitySetting = passwordComplexityResult.setting; this.setPasswordComplexityInfo(); }); //this.KTWizard2(); // setTimeout(function(){ this.KTWizard2()}, 3000); } ngAfterViewInit(userId?: number) { let maxcount = 1000; this.filterLocations(maxcount); this.filterAddressTypes(maxcount); $(".select2-container").css("width", "100%"); } save(): void { this.saving = true; let timeId = localStorage.getItem('timeZoneId'); if (this.contactForm.pNumber == null) { this.contactForm.pNumber = "n/a"; } this._driver.user.name = this.contactForm.fName; this._driver.user.surname = this.contactForm.sName; this._driver.user.userName = this.contactForm.fName; this._driver.user.userName = this.driver.userName; this._driver.user.password = this.driver.password; this._driver.user.phoneNumber = this.contactForm.pNumber; this._driver.user.emailAddress = this.contactForm.emailAddress; this._driver.user.isLockoutEnabled = this.isLockoutEnabled; this._driver.user.isActive = this.isActive; this._driver.skipOrders = this.skipOrders; this._driver.user.isTwoFactorEnabled = this.isTwoFactorEnabled; this._driver.user.shouldChangePasswordOnNextLogin = this.shouldChangePasswordOnNextLogin; this._driver.user.sendActivationEmail = this.sendActivationEmail; this._driver.setRandomPassword = this.setRandomPassword; this._driver.sendActivationEmail = this.sendActivationEmail; this._driver.location = $("#locationSelectInput").val(); this._driver.address = this.addressForm.address; this._driver.address.addressTypeId = Number((document.getElementById('addressTypeSelectInput')).value) == 0 ? null : Number((document.getElementById('addressTypeSelectInput')).value); this.contactInput.lastName = this.contactForm.sName; this.contactInput.firstName = this.contactForm.fName; this._driver.contact = this.contactInput; this.postalCodeInput.city = this.addressForm.city; this.postalCodeInput.state = this.addressForm.state; this.postalCodeInput.value = this.addressForm.value; this.postalCodeInput.country = this.addressForm.country; this._driver.postalCode = this.postalCodeInput; this._driver.driverInfo = this.driverInput; this._driver.driverInfo.startDate = this.driverInput.startDate ? moment.tz(this.driverInput.startDate, timeId) : null; this._driver.driverInfo.endDate = this.driverInput.endDate ? moment.tz(this.driverInput.endDate, timeId) : null; this._driver.driverInfo.driverLicenseExpirationDate = this.driverInput.driverLicenseExpirationDate ? moment.tz(this.driverInput.driverLicenseExpirationDate, timeId) : null; // console.log(this.addressForm) this._driverService.createOrUpdateDriverAPI(this._driver).subscribe( (result) => { this.saving = false; this.notify.info(this.l('SavedSuccessfully')); this.router.navigate(['/app/sprintship/drivers']); } , (error : any) =>{ this.saving = false; }); } filterLocations(maxcount): void { this._locationService.getLocationNames( undefined, undefined, undefined, undefined, undefined, undefined ).subscribe(result => { this.filteredLocations = result; }); } getLocation(id): void { this._locationService.getLocation( id, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined ).subscribe(result => { this.getLocationId = result.items[0].contact.address.id; }); } getUserlocation(id): void { this._userLocationService.getUserLocation( undefined, id, undefined, undefined, undefined, undefined, undefined, undefined, 1, undefined ).subscribe(result => { this.getUserLocationId = result.items[0].locationId; // console.log(this.getUserLocationId + "sa"); this.getAddressId = this.getLocation(this.getUserLocationId); // console.log(this.getAddressId + "saa"); }); } filterAddressTypes(maxCount): void { this._addressTypeService.getAddressType( undefined, undefined, undefined, undefined, maxCount, undefined ).subscribe(result => { this.filteredAddressType = result.items; }); } filterVehicle(): void{ this._driverService.getAvailableVehicle( undefined, undefined, undefined, undefined, undefined, undefined, undefined ).subscribe(result => { this.filteredVehicle = result; // console.log(this.filteredVehicle) }); } // Class definition KTWizard2(): void { // Base elements var wizardEl; var formEl; var validator; var wizard; var that = this; function validateEmail(sEmail) { var filter = /^\b[A-Z0-9._%-]+@([A-Z0-9.-])+[\w-]+\b$/i // var filter = /^\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$/i; if (filter.test(sEmail)) { return true; } else { return false; } } function validatePassword(sEmail) { var filter2 = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[A-Z]).{6,20}$/ if (filter2.test(sEmail)) { console.log(true) return true; } else { console.log(false) return false; } } // Private functions var initWizard = function () { // Initialize form wizard wizard = new KTWizard('kt_wizard_v2', { startStep: 1, }); // Validation before going to next page wizard.on('beforeNext', function (wizardObj) { if (wizardObj.currentStep == 1) { console.log("Password"+that.setRandomPassword) console.log("validation" + validatePassword($('#Password').val())) if ($('#Name').val() == '' || ($('#Surname').val() == '') // || ($('#PhoneNumber').val() == ''|| $('#minutesPerStopInput').val()==0) || $('#EmailAddress').val() == '' || $('#UserName').val() == '' || $('#Password').val() == '' || $('#PasswordRepeat').val() == '' ) { wizardObj.stop(); // don't go to the next step } if (!validateEmail($('#EmailAddress').val())) { wizardObj.stop(); } else if (that.setRandomPassword == false){ if (validatePassword($('#Password').val()) == false) { // that.setRandomPassword == true && // if(that.setRandomPassword == false){ wizardObj.stop(); // } } } } // else if (wizardObj.currentStep == 2) { // if ($('#locationSelectInput').val() == null || $('#locationSelectInput').val() == 0 // || $('#address1').val() == '' // || ($('#countrySelectInput').val() == null || $('#countrySelectInput').val() == 0) // || ($('#postalSelectInput').val() == null || $('#postalSelectInput').val() == 0) // || ($('#stateSelectInput').val() == null || $('#stateSelectInput').val() == 0) // || ($('#citySelectInput').val() == null || $('#citySelectInput').val() == 0) // // || ($('#addressTypeSelectInput').val() == null || $('#addressTypeSelectInput').val() == 0) // ) { // wizardObj.stop(); // don't go to the next step // } // } }); // Change event wizard.on('change', function (wizard) { KTUtil.scrollTop(); }); } wizardEl = KTUtil.get('kt_wizard_v2'); formEl = $('#kt_form').serialize(); return initWizard(); //return initValidation(); //return initSubmit(); } goBack() { this._location.back(); } }