Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component } from '@angular/core';
- import { NavController } from 'ionic-angular';
- import { AlertController, Platform } from 'ionic-angular';
- import {Network} from "ionic-native";
- import {Observable} from 'rxjs/Rx';
- import { Http, Response, Headers, RequestOptions, Request, RequestMethod } from '@angular/http';
- import {FORM_DIRECTIVES, FormBuilder, ControlGroup, Validators, AbstractControl} from '@angular/common';
- // declare var navigator: any;
- // declare var Connection: any;
- /*
- Generated class for the LoginPage page.
- See http://ionicframework.com/docs/v2/components/#navigation for more info on
- Ionic pages and navigation.
- */
- @Component({
- templateUrl: 'build/pages/login/login.html',
- })
- export class LoginPage {
- username: string;
- password: string;
- private restfulURL = 'http://jsonplaceholder.typicode.com/posts/1';
- private soapURL = 'http://smes.silverlakegroup.com.my:49167/mbdes/api/rest/getSpeakerList';
- constructor(private navCtrl: NavController, private alertController: AlertController, private http: Http, private platform: Platform) {
- }
- showAlert(title, string) {
- let alert = this.alertController.create({
- title: title,
- subTitle: string,
- buttons: ['OK']
- });
- alert.present();
- }
- login() {
- if (!this.username || !this.password) {
- this.showAlert('Error', 'User credentials cannot be empty');
- }
- else {
- let isSuccess;
- let msg;
- if (this.checkNetwork()) {
- this.callBDESService({ 'lastModifiedDt': '1362868820000' }).subscribe(res => {
- // this.showAlert('Success', JSON.stringify(res));
- isSuccess = true;
- msg = JSON.stringify(res);
- console.log("RESPONSE" + msg);
- },
- (err) => {
- isSuccess = false;
- console.log(err)
- msg = err;
- // this.showAlert('Error', err);
- },
- () => {
- if (isSuccess) {
- this.showAlert('Complete success', msg);
- } else {
- this.showAlert('Complete but failed', msg);
- }
- }
- );
- }
- }
- }
- callRestFul(): Observable<any[]> {
- return this.http.get(this.restfulURL)
- .map((res: Response) => res.json())
- .catch((error: any) => Observable.throw(error.json().error))
- }
- callBDESService(body: Object): Observable<any[]> {
- let bodyString = JSON.stringify(body);
- console.log("BODY " + bodyString);
- console.log("URL " + this.soapURL);
- let headers = new Headers({ 'Content-Type': 'application/json' });
- let options = new RequestOptions({
- headers: headers,
- method: RequestMethod.Post
- });
- return this.http.post(this.soapURL, bodyString, options)
- .map((res: Response) => res.json())
- .catch((error: any) => Observable.throw(error.json().error));
- }
- checkNetwork(){
- return this.platform.ready().then(() => {
- console.log(Network.connection);
- if (Network.connection === 'none') {
- // if (Network.connection == Connection.None) {
- this.showAlert('Attention', 'No internet connection.');
- return false;
- } else {
- console.log('Network connection true');
- return true;
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement