root / src / app / teachers / teachers.component.ts @ f3d5fa3b
Historique | Voir | Annoter | Télécharger (4,89 ko)
1 |
import { Component, OnInit } from "@angular/core"; |
---|---|
2 |
import { RadSideDrawer } from "nativescript-ui-sidedrawer"; |
3 |
import { EventData } from "tns-core-modules/data/observable"; |
4 |
import { TextField } from "tns-core-modules/ui/text-field"; |
5 |
import * as app from "tns-core-modules/application"; |
6 |
import { getViewById } from "tns-core-modules/ui/core/view"; |
7 |
import { getString, setString, hasKey, remove, clear } from "tns-core-modules/application-settings"; |
8 |
import { borderTopRightRadiusProperty } from "tns-core-modules/ui/page/page"; |
9 |
import * as dialogs from "tns-core-modules/ui/dialogs"; |
10 |
import { getFile, getImage, getJSON, request, HttpResponse } from "tns-core-modules/http"; |
11 |
import { RouterExtensions } from "nativescript-angular/router"; |
12 |
import { ActivatedRoute } from "@angular/router"; |
13 |
|
14 |
@Component({ |
15 |
selector: "Teachers", |
16 |
templateUrl: "./teachers.component.html" |
17 |
}) |
18 |
export class TeachersComponent implements OnInit { |
19 |
public album: string; |
20 |
public albumPass: string; |
21 |
public albumPassAdmin: string; |
22 |
public serverURI: string; |
23 |
public email: string; |
24 |
|
25 |
constructor(private routerExtensions: RouterExtensions, private activeRoute: ActivatedRoute) { |
26 |
// Use the component constructor to inject providers. |
27 |
this.email = getString("email", ""); |
28 |
this.album = getString("album", ""); |
29 |
this.albumPass = getString("albumPass", ""); |
30 |
this.albumPassAdmin = getString("albumPassAdmin", ""); |
31 |
this.serverURI = getString("serverURI", ""); |
32 |
} |
33 |
|
34 |
ngOnInit(): void { |
35 |
// Init your component properties here. |
36 |
} |
37 |
|
38 |
onDrawerButtonTap(): void { |
39 |
const sideDrawer = <RadSideDrawer>app.getRootView(); |
40 |
sideDrawer.showDrawer(); |
41 |
} |
42 |
|
43 |
onBlur(args: EventData): void { |
44 |
let obj = <TextField>args.object; |
45 |
if (obj.id == "album") { |
46 |
this.album = obj.text.toLowerCase().replace(/[^a-z0-9]/g, ""); |
47 |
} |
48 |
if (obj.id == "albumPass") { |
49 |
this.albumPass = obj.text.toLowerCase().replace(/[^a-z0-9]/g, ""); |
50 |
} |
51 |
if (obj.id == "albumPassAdmin") { |
52 |
this.albumPassAdmin = obj.text.toLowerCase().replace(/[^a-z0-9]/g, ""); |
53 |
} |
54 |
} |
55 |
|
56 |
onSaveTap(args) { |
57 |
let a = <TextField>getViewById(app.getRootView(), "album"); |
58 |
this.album = a.text; |
59 |
a = <TextField>getViewById(app.getRootView(), "albumPass"); |
60 |
this.albumPass = a.text; |
61 |
a = <TextField>getViewById(app.getRootView(), "albumPassAdmin"); |
62 |
this.albumPassAdmin = a.text; |
63 |
|
64 |
|
65 |
console.log(" on save : ", this.album, this.albumPass, this.albumPassAdmin); |
66 |
if (this.album == "" || this.albumPassAdmin == "") { |
67 |
dialogs.alert({ |
68 |
title: "Informations manquantes", |
69 |
message: "Le nom de l'album et le mot de passe d'administration sont nécessaires ...", |
70 |
okButtonText: "Ok" |
71 |
}).then(() => { |
72 |
}); |
73 |
} |
74 |
else { |
75 |
this.createAlbum(); |
76 |
} |
77 |
} |
78 |
|
79 |
//On lance la demande de création de l'album ... |
80 |
createAlbum() { |
81 |
request({ |
82 |
url: "https://" + this.serverURI + "/api.php", |
83 |
method: "POST", |
84 |
headers: { "Content-Type": "application/json" }, |
85 |
content: JSON.stringify({ |
86 |
command: "createAlbum", |
87 |
email: this.email, |
88 |
album: this.album, |
89 |
albumPass: this.albumPass, |
90 |
albumPassAdmin: this.albumPassAdmin, |
91 |
}) |
92 |
}).then((response) => { |
93 |
const result = response.content.toJSON(); |
94 |
console.log("Valeur de albumOK dans le retour request : ", result['createAlbumOK']); |
95 |
|
96 |
if (result['createAlbumOK'] == true) { |
97 |
setString("album", this.album); |
98 |
setString("albumPass", this.albumPass); |
99 |
setString("albumPassAdmin", this.albumPassAdmin); |
100 |
dialogs.alert({ |
101 |
title: result['messageTitle'], |
102 |
message: result['message'], |
103 |
okButtonText: "Ok" |
104 |
}).then(() => { |
105 |
this.routerExtensions.navigate(["/home"], { relativeTo: this.activeRoute }); |
106 |
}); |
107 |
} |
108 |
else { |
109 |
console.log("Album refusé"); |
110 |
dialogs.alert({ |
111 |
title: "Création d'album impossible !", |
112 |
message: "Malheureusement la création de cet album n'a pas été possible. Essayez de changer le nom de votre album et tentez à nouveau votre chance :-)", |
113 |
okButtonText: "Ok" |
114 |
}); |
115 |
} |
116 |
}, (e) => { |
117 |
console.log("request Error :", e); |
118 |
dialogs.alert({ |
119 |
title: "Erreur de vérification !", |
120 |
message: "Une erreur de communication avec le serveur nous empêche de faire les vérifications nécessaires ... ré-essayez plus tard.", |
121 |
okButtonText: "Ok" |
122 |
}); |
123 |
}); |
124 |
} |
125 |
} |