import {Component, EventEmitter, Output, ViewChild} from "@angular/core"; import {BasicDialog} from "../../sharedmodules/controls/Dialog/BasicDialog"; import {NgForm} from "@angular/forms"; import {WpJsonApi} from "../../sharedmodules/wp-elements/Services/WpJsonApi"; @Component({ selector:'user-dialog', template:`
Username*
Email*
Password
Business/Client Name
Account First Name
Account Last Name
Address
Phone
Fax
Website
Extra info (like VAT number)
` }) export class UserDialog { @ViewChild('dialog') dialog:BasicDialog; @ViewChild('dialogNgForm') private _formDialog:NgForm; @Output() public UserCreated = new EventEmitter<{Label:string,Id:number}>(); public ClientToEditOrCreate:CreateUserModel={ Address:'', BusinessName:'', Email:'', FirstName:'', LastName:'', Password:'', ShowPassword:false, Username:'', Website:'', Fax:'', Phone:'', Extra:'' }; constructor(public ajax:WpJsonApi) { } async SaveClient() { this.MarkAllFieldsAsDirty(); this.dialog.IsLoading=true; let result=await this.ajax.Post<{Label:string,Id:number}>('/users/create',this._formDialog.value); this.dialog.IsLoading=false; if(result!=null) { this.UserCreated.emit(result); this.dialog.Close(); } } public Open(){ this.ClientToEditOrCreate={ Address:'', BusinessName:'', Email:'', FirstName:'', LastName:'', Password:'', ShowPassword:false, Username:'', Website:'', Fax:'', Phone:'', Extra:'' }; this.UndirtyFields(); this.dialog.Open(); } private UndirtyFields(){ for(let property in this._formDialog.controls) { this._formDialog.controls[property].markAsPristine(); } } private MarkAllFieldsAsDirty() { for(let property in this._formDialog.controls) { this._formDialog.controls[property].markAsDirty(); } } }