1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function showDialog(args, dialogType, result) {
|
20 |
|
21 | var msg = JSON.parse(decodeURIComponent(args[0])),
|
22 | title = JSON.parse(decodeURIComponent(args[1])),
|
23 | btnLabel = JSON.parse(decodeURIComponent(args[2]));
|
24 |
|
25 | if (!Array.isArray(btnLabel)) {
|
26 |
|
27 | btnLabel = btnLabel.split(",");
|
28 | }
|
29 |
|
30 | if (msg && typeof msg === "string") {
|
31 | msg = msg.replace(/^"|"$/g, "").replace(/\\"/g, '"');
|
32 | } else {
|
33 | result.error("message is undefined");
|
34 | return;
|
35 | }
|
36 |
|
37 | var messageObj = {
|
38 | title : title,
|
39 | htmlmessage : msg,
|
40 | dialogType : dialogType,
|
41 | optionalButtons : btnLabel
|
42 | };
|
43 |
|
44 |
|
45 | qnx.webplatform.getWebViews()[2].dialog.show(messageObj, function (data) {
|
46 | if (typeof data === "number") {
|
47 |
|
48 | result.callbackOk(++data, false);
|
49 | } else {
|
50 |
|
51 | result.callbackOk({
|
52 | buttonIndex: data.ok ? 1 : 0,
|
53 | input1: (data.oktext) ? decodeURIComponent(data.oktext) : ""
|
54 | }, false);
|
55 | }
|
56 | });
|
57 |
|
58 | result.noResult(true);
|
59 | }
|
60 |
|
61 | module.exports = {
|
62 | alert: function (success, fail, args, env) {
|
63 | var result = new PluginResult(args, env);
|
64 |
|
65 | if (Object.keys(args).length < 3) {
|
66 | result.error("Notification action - alert arguments not found.");
|
67 | } else {
|
68 | showDialog(args, "CustomAsk", result);
|
69 | }
|
70 | },
|
71 | confirm: function (success, fail, args, env) {
|
72 | var result = new PluginResult(args, env);
|
73 |
|
74 | if (Object.keys(args).length < 3) {
|
75 | result.error("Notification action - confirm arguments not found.");
|
76 | } else {
|
77 | showDialog(args, "CustomAsk", result);
|
78 | }
|
79 | },
|
80 | prompt: function (success, fail, args, env) {
|
81 | var result = new PluginResult(args, env);
|
82 |
|
83 | if (Object.keys(args).length < 3) {
|
84 | result.error("Notification action - prompt arguments not found.");
|
85 | } else {
|
86 | showDialog(args, "JavaScriptPrompt", result);
|
87 | }
|
88 | }
|
89 | };
|