|
| 1 | +import { Component, ViewContainerRef } from "@angular/core"; |
| 2 | +import * as dialogs from "ui/dialogs"; |
| 3 | +import { ModalDialogService, ModalDialogOptions } from "nativescript-angular/directives/dialogs"; |
| 4 | +import { ModalContent } from "./modal-content"; |
| 5 | + |
| 6 | +@Component({ |
| 7 | + selector: "modal-test", |
| 8 | + template: ` |
| 9 | + <GridLayout rows="*, auto"> |
| 10 | + <StackLayout verticalAlignment="top" margin="12"> |
| 11 | + <Button text="show component" (tap)="showModal(false)"></Button> |
| 12 | + <Button text="show component fullscreen" (tap)="showModal(true)"></Button> |
| 13 | +
|
| 14 | + <Button text="alert" (tap)="showAlert()"></Button> |
| 15 | + <Button text="confirm" (tap)="showConfirm()"></Button> |
| 16 | + <Button text="prompt" (tap)="showPrompt()"></Button> |
| 17 | + <Button text="action" (tap)="showAction()"></Button> |
| 18 | + <Button text="login" (tap)="showLogin()"></Button> |
| 19 | + </StackLayout> |
| 20 | + <Label [text]="'RESULT: ' + result" row="1" margin="12"></Label> |
| 21 | + </GridLayout> |
| 22 | + ` |
| 23 | +}) |
| 24 | +export class ModalTest { |
| 25 | + |
| 26 | + public result: string = "result"; |
| 27 | + |
| 28 | + constructor(private modal: ModalDialogService, private vcRef: ViewContainerRef) { } |
| 29 | + |
| 30 | + static entries = [ |
| 31 | + ModalContent |
| 32 | + ]; |
| 33 | + |
| 34 | + public showModal(fullscreen: boolean) { |
| 35 | + const options: ModalDialogOptions = { |
| 36 | + context: { promptMsg: "This is the prompt message!" }, |
| 37 | + fullscreen: fullscreen, |
| 38 | + viewContainerRef: this.vcRef |
| 39 | + }; |
| 40 | + |
| 41 | + this.modal.showModal(ModalContent, options).then((res: string) => { |
| 42 | + this.result = res || "empty result"; |
| 43 | + // console.log("MODAL:" + this.result); |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + public showAlert() { |
| 48 | + dialogs.alert({ |
| 49 | + title: "Alert Title", |
| 50 | + message: "The name will change.", |
| 51 | + okButtonText: "OK" |
| 52 | + }).then(() => { |
| 53 | + this.result = "alert closed"; |
| 54 | + }); |
| 55 | + } |
| 56 | + |
| 57 | + public showConfirm() { |
| 58 | + dialogs.confirm({ |
| 59 | + title: "Name", |
| 60 | + message: "Do you want to change the name?", |
| 61 | + cancelButtonText: "No", |
| 62 | + neutralButtonText: "Ignore", |
| 63 | + okButtonText: "Yes" |
| 64 | + }).then((confirmResult) => { |
| 65 | + this.result = confirmResult + ""; |
| 66 | + }); |
| 67 | + } |
| 68 | + |
| 69 | + public showPrompt() { |
| 70 | + dialogs.prompt({ |
| 71 | + title: "Name", |
| 72 | + message: "Enter name:", |
| 73 | + cancelButtonText: "Cancel", |
| 74 | + neutralButtonText: "Ignore", |
| 75 | + okButtonText: "OK", |
| 76 | + defaultText: "John Reese", |
| 77 | + inputType: dialogs.inputType.text |
| 78 | + }).then((promptResult) => { |
| 79 | + this.result = promptResult.result ? promptResult.text : "no result"; |
| 80 | + }); |
| 81 | + } |
| 82 | + |
| 83 | + public showAction() { |
| 84 | + dialogs.action({ |
| 85 | + message: "Choose action:", |
| 86 | + cancelButtonText: "Close", |
| 87 | + actions: ["Foo", "Bar"] |
| 88 | + }).then((actionResult) => { |
| 89 | + this.result = actionResult; |
| 90 | + }); |
| 91 | + } |
| 92 | + |
| 93 | + public showLogin() { |
| 94 | + dialogs.login({ |
| 95 | + title: "Name", |
| 96 | + message: "Enter name:", |
| 97 | + cancelButtonText: "Cancel", |
| 98 | + neutralButtonText: "Ignore", |
| 99 | + okButtonText: "OK", |
| 100 | + userName: "John", |
| 101 | + password: "Reese" |
| 102 | + }).then((loginResult) => { |
| 103 | + this.result = loginResult.result ? |
| 104 | + ("user: " + loginResult.userName + " pass: " + loginResult.password) : |
| 105 | + "no result"; |
| 106 | + }); |
| 107 | + } |
| 108 | + |
| 109 | +} |
0 commit comments