import { Component } from '@angular/core'; import { LoadAlertsService } from 'src/app/services/load-alerts.service'; import { StorageService } from 'src/app/services/storage.service'; import { UserService } from 'src/app/services/user.service'; import { RouterService } from 'src/app/services/router.service'; import { Platform,AlertController } from '@ionic/angular'; @Component({ selector: 'app-home', templateUrl: 'home.page.html', styleUrls: ['home.page.scss'], }) export class HomePage { constructor( private User:UserService, private router:RouterService, private loadAlertsService:LoadAlertsService, private storage:StorageService, private plt:Platform ) { } accept; UserName:string; PWD:string; signupPWD:string; lang; /*{ text: 'Cancel', role: 'cancel', handler: (blah) => { console.log('Confirm Cancel: blah'); } }, { text: 'Okay', handler: () => { console.log('Confirm Okay'); } }*/ ionViewWillEnter(){ this.plt.ready().then(() => { this.plt.backButton.subscribeWithPriority(9999999, () => { this.router.exitApp(); }) }); this.storage.get("lang").then(data=>{console.log(data,'lang'); this.lang=data; if(data==2) { document.dir='rtl' } else { document.dir='ltr' } }, error=>{console.log(error,'langError');}); } IsSignUp; CreateAccount(){ this.IsSignUp=1; } back() { this.IsSignUp=undefined; } SignUpFn(){ if(this.accept==true){ if(this.signupPWD!='' && this.signupPWD!=undefined) { let body={ request_category : "sign_up", oss_language : this.lang==1?"en":"ar", oss_secret :this.signupPWD }; console.log(body); this.loadAlertsService.presentLoading('Please Wait...'); this.User.SignUp(body).subscribe(data=>{ this.loadAlertsService.dismissLoading(); console.log(data,"data"); this.router.navByUrl("layout/main"); },error=>{ this.loadAlertsService.dismissLoading(); console.log(error,'error'); }); } else{ this.loadAlertsService.PresentAlert("","Attention",'Password cannot be empty.') } }else{ this.loadAlertsService.PresentAlert("","Attention",'You have to accept the terms and conditions first.') } } ionViewWillLeave(){ this.plt.ready().then(() => { this.plt.backButton.subscribeWithPriority(9999999, () => { this.router.goBack(); }) }); } SubmitFn(){ let body={ request_category : 'sign_in', oss_language :this.lang==1?'en':'ar', oss_username :this.UserName, oss_secret:this.PWD }; console.log(body); // this.router.navByUrl("layout/main"); if(this.PWD==undefined || this.PWD=='') { this.loadAlertsService.PresentAlert("","Attention",'Password cannot be empty.') }else{ if(this.UserName==undefined || this.UserName=='') { this.loadAlertsService.PresentAlert("","Attention",'User Name cannot be empty.') }else{ this.loadAlertsService.presentLoading('Please Wait...'); this.User.SignIn(body).subscribe(data=>{ this.loadAlertsService.dismissLoading(); console.log(data,"data"); this.router.navByUrl("layout/main"); },error=>{ this.loadAlertsService.dismissLoading(); console.log(error,'error'); }); } } } }