import { Component, Injector, OnInit, 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,VendorsServiceProxy,
LocationServiceProxy, CreateLocationContactInput, CreateContactInput,
CreateAddressInput, PostalCodeServiceProxy,
CreateContactAddressInput,PasswordComplexitySetting,UserRoleDto,
CreateContactUserAddressInput, UpdateContactInput,
ContactServiceProxy, UpdateAddressInput,
UserEditDto,
AddressTypeServiceProxy,
AddressServiceProxy,
CreatePostalCodeInput, FleetsServiceProxy, CreateOrEditVendorInput, NameValueDto} 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 { AddressFormComponent } from '@app/shared/layout/form/address-form.component';
import { ContactFormComponent } from '@app/shared/layout/form/contact.form.component';
declare var KTWizard: any;
declare var $: any;
declare var KTApp: any;
declare let swal: any;
@Component({
templateUrl: './create-vendor.component.html',
encapsulation: ViewEncapsulation.None,
animations: [appModuleAnimation()]
})
export class CreateVendorComponent extends AppComponentBase implements OnInit {
@ViewChild(AddressFormComponent, { static: false }) addressForm;
@ViewChild(ContactFormComponent, { static: false }) contactForm;
vendor: CreateOrEditVendorInput = new CreateOrEditVendorInput();
postalCodeInput: CreatePostalCodeInput = new CreatePostalCodeInput();
setRandomPassword = true;
userPasswordRepeat = '';
passwordComplexityInfo = '';
active = false;
saving = false;
id: any;
contactInput: CreateContactInput = new CreateContactInput();
filteredLocations: any;
getUserLocationId: any;
getAddressId: any;
getLocationId: any;
selectedAddressType: any;
selectedCountry: any;
selectedPostalCode: any;
selectedState: any;
selectedCity: any;
filteredAddressType: any;
canChangeUserName = true;
isActive = true;
passwordComplexitySetting: PasswordComplexitySetting = new PasswordComplexitySetting();
sendActivationEmail = true;
shouldChangePasswordOnNextLogin = true;
isTwoFactorEnabled: boolean = this.setting.getBoolean('Abp.Zero.UserManagement.TwoFactorLogin.IsEnabled');
isLockoutEnabled: boolean = this.setting.getBoolean('Abp.Zero.UserManagement.UserLockOut.IsEnabled');
stateFeature: boolean;
fleets: any;
fleetSelected: any;
constructor(
injector: Injector,
private _locationService: LocationServiceProxy,
private _addressTypeService: AddressTypeServiceProxy,
private _postalCodeServiceProxy: PostalCodeServiceProxy,
private router: Router,
private route: ActivatedRoute,
private _location: Location,
private _vendorServiceProxy: VendorsServiceProxy,
private _fleetService: FleetsServiceProxy,
) {
super(injector);
}
setPasswordComplexityInfo(): void {
this.passwordComplexityInfo = '
';
if (this.passwordComplexitySetting.requireDigit) {
this.passwordComplexityInfo += '- ' + this.l('PasswordComplexity_RequireDigit_Hint') + '
';
}
if (this.passwordComplexitySetting.requireLowercase) {
this.passwordComplexityInfo += '- ' + this.l('PasswordComplexity_RequireLowercase_Hint') + '
';
}
if (this.passwordComplexitySetting.requireUppercase) {
this.passwordComplexityInfo += '- ' + this.l('PasswordComplexity_RequireUppercase_Hint') + '
';
}
if (this.passwordComplexitySetting.requireNonAlphanumeric) {
this.passwordComplexityInfo += '- ' + this.l('PasswordComplexity_RequireNonAlphanumeric_Hint') + '
';
}
if (this.passwordComplexitySetting.requiredLength) {
this.passwordComplexityInfo += '- ' + this.l('PasswordComplexity_RequiredLength_Hint', this.passwordComplexitySetting.requiredLength) + '
';
}
this.passwordComplexityInfo += '
';
}
ngOnInit() {
this.stateFeature = abp.features.isEnabled('App.StateFeature');
$('.kt-select2').select2({
placeholder: "Select.."
});
this.route.paramMap.subscribe(params => {
this.id = params.get("id")
})
$("#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 + ",");
});
$("#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 },
Address1: { required: !0 },
postalSelectInput: { required: !0 }
},
invalidHandler: function (e, r) {
},
submitHandler: function (e) { }
})
}
}
}();
jQuery(document).ready(function () { KTWizard2.init() });
this.getFleets();
}
ngAfterViewInit(userId?: number) {
let maxcount = 1000;
this.filterLocations();
this.filterAddressTypes(maxcount);
}
save(): void {
this.saving = true;
if (this.contactForm.pNumber == null) {
this.contactForm.pNumber = "n/a";
}
this.vendor.user.name = this.contactForm.fName;
this.vendor.user.surname = this.contactForm.sName;
this.vendor.user.phoneNumber = this.contactForm.pNumber;
this.vendor.user.emailAddress = this.contactForm.emailAddress;
this.vendor.user.shouldChangePasswordOnNextLogin = this.shouldChangePasswordOnNextLogin;
this.vendor.user.sendActivationEmail = this.sendActivationEmail;
this.vendor.setRandomPassword = this.setRandomPassword;
this.vendor.sendActivationEmail = this.sendActivationEmail;
this.vendor.user.isActive = this.isActive;
this.vendor.user.isLockoutEnabled = this.isLockoutEnabled;
this.vendor.user.isTwoFactorEnabled = this.isTwoFactorEnabled;
this.vendor.location = $("#locationSelectInput").val();
this.vendor.address = this.addressForm.address;
this.vendor.address.formattedAddress = this.addressForm.formattedAddress;
this.vendor.latitude = this.addressForm.latitude;
this.vendor.longitude = this.addressForm.longitude;
// this.employee.address.postalCodeId = Number((document.getElementById('postalSelectInput')).value);
this.vendor.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.vendor.contact = this.contactInput;
this.vendor.startDate = this.vendor.startDate ? moment.utc(this.vendor.startDate) : null;
this.postalCodeInput.city = this.addressForm.city;
// this.postalCodeInput.state = this.addressForm.state;
if(!this.stateFeature){
this.postalCodeInput.state = "";
}
else{
this.postalCodeInput.state = this.addressForm.state;
}
this.postalCodeInput.value = this.addressForm.value;
this.postalCodeInput.country = this.addressForm.country;
this.vendor.fleetId = $("#FleetsVendor").val();
this._postalCodeServiceProxy.createPostalCode(this.postalCodeInput)
.pipe()
.subscribe(result => {
this.vendor.address.postalCodeId = result
this._vendorServiceProxy.createOrUpdateVendor(this.vendor).subscribe(
() => {
this.saving = false;
this.notify.info(this.l('SavedSuccessfully'));
this.router.navigate(['/app/sprintship/vendors']);
});
});
}
filterLocations(): void {
this._locationService.getLocationNames(
undefined,
undefined,
undefined,
undefined,
undefined,
undefined
).subscribe(result => {
this.filteredLocations = result;
});
}
filterAddressTypes(maxCount): void {
this._addressTypeService.getAddressType(
undefined,
undefined,
undefined,
undefined,
maxCount,
undefined
).subscribe(result => {
this.filteredAddressType = result.items;
});
}
goBack() {
this._location.back();
}
getFleets(){
this._fleetService.getAllFleets(undefined, undefined, undefined, undefined, undefined)
.subscribe(result=>{
this.fleets = result.items
// console.log(this.fleets)
})
}
}