-
-
Notifications
You must be signed in to change notification settings - Fork 295
/
Copy pathsample-modal-page-module-example.ts
66 lines (62 loc) · 2.42 KB
/
sample-modal-page-module-example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// >> time-picker-configure-code
import { ModalDialogService, ModalDialogOptions } from "nativescript-angular";
import { Component, ViewContainerRef } from "@angular/core";
import { DatePicker } from "ui/date-picker";
import { ModalViewComponent } from "./modal-view";
@Component({
moduleId: module.id,
providers: [ModalDialogService],
templateUrl: "./sample-modal-page-module-example.html"
})
export class SampleModalPageModuleExampleComponent {
public startDate: Date;
public endDate: Date;
public date: Date;
public days: number;
public weekday: string;
public weekdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
constructor(private _modalService: ModalDialogService, private vcRef: ViewContainerRef) {
let oneDay = 24 * 60 * 60 * 1000;
this.startDate = new Date("2015-12-12");
this.endDate = new Date();
this.date = new Date();
this.days = Math.round(Math.abs((this.startDate.getTime() - this.endDate.getTime()) / (oneDay)));
this.weekday = this.weekdays[this.date.getDay()];
}
createModelView(args) {
let that = this;
let currentDate = new Date();
let options: ModalDialogOptions = {
viewContainerRef: this.vcRef,
context: currentDate.toDateString(),
fullscreen: false
};
// >> returning-result
this._modalService.showModal(ModalViewComponent, options)
.then((dateresult: Date) => {
console.log("date result " + dateresult);
// >> (hide)
if (args === "start") {
this.startDate = dateresult;
} else if (args === "end") {
this.endDate = dateresult;
} else if (args === "findTheDay") {
this.date = dateresult;
this.weekday = this.weekdays[this.date.getDay()];
}
// << (hide)
});
// << returning-result
}
findDays() {
let oneDay = 24 * 60 * 60 * 1000;
if (this.startDate.getTime() > this.endDate.getTime()) {
alert("Enter correct end date");
} else {
let tmpDays = Math.round(Math.abs((this.startDate.getTime() - this.endDate.getTime()) / (oneDay)));
console.log(tmpDays);
this.days = tmpDays;
}
}
}
// << time-picker-configure-code