|
1 /* |
|
2 * |
|
3 * Licensed to the Apache Software Foundation (ASF) under one |
|
4 * or more contributor license agreements. See the NOTICE file |
|
5 * distributed with this work for additional information |
|
6 * regarding copyright ownership. The ASF licenses this file |
|
7 * to you under the Apache License, Version 2.0 (the |
|
8 * "License"); you may not use this file except in compliance |
|
9 * with the License. You may obtain a copy of the License at |
|
10 * |
|
11 * http://www.apache.org/licenses/LICENSE-2.0 |
|
12 * |
|
13 * Unless required by applicable law or agreed to in writing, |
|
14 * software distributed under the License is distributed on an |
|
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|
16 * KIND, either express or implied. See the License for the |
|
17 * specific language governing permissions and limitations |
|
18 * under the License. |
|
19 * |
|
20 */ |
|
21 |
|
22 var exec = require('cordova/exec'); |
|
23 var platform = require('cordova/platform'); |
|
24 |
|
25 /** |
|
26 * Provides access to notifications on the device. |
|
27 */ |
|
28 |
|
29 module.exports = { |
|
30 |
|
31 /** |
|
32 * Open a native alert dialog, with a customizable title and button text. |
|
33 * |
|
34 * @param {String} message Message to print in the body of the alert |
|
35 * @param {Function} completeCallback The callback that is called when user clicks on a button. |
|
36 * @param {String} title Title of the alert dialog (default: Alert) |
|
37 * @param {String} buttonLabel Label of the close button (default: OK) |
|
38 */ |
|
39 alert: function(message, completeCallback, title, buttonLabel) { |
|
40 var _title = (title || "Alert"); |
|
41 var _buttonLabel = (buttonLabel || "OK"); |
|
42 exec(completeCallback, null, "Notification", "alert", [message, _title, _buttonLabel]); |
|
43 }, |
|
44 |
|
45 /** |
|
46 * Open a native confirm dialog, with a customizable title and button text. |
|
47 * The result that the user selects is returned to the result callback. |
|
48 * |
|
49 * @param {String} message Message to print in the body of the alert |
|
50 * @param {Function} resultCallback The callback that is called when user clicks on a button. |
|
51 * @param {String} title Title of the alert dialog (default: Confirm) |
|
52 * @param {Array} buttonLabels Array of the labels of the buttons (default: ['OK', 'Cancel']) |
|
53 */ |
|
54 confirm: function(message, resultCallback, title, buttonLabels) { |
|
55 var _title = (title || "Confirm"); |
|
56 var _buttonLabels = (buttonLabels || ["OK", "Cancel"]); |
|
57 |
|
58 // Strings are deprecated! |
|
59 if (typeof _buttonLabels === 'string') { |
|
60 console.log("Notification.confirm(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array)."); |
|
61 } |
|
62 |
|
63 // Some platforms take an array of button label names. |
|
64 // Other platforms take a comma separated list. |
|
65 // For compatibility, we convert to the desired type based on the platform. |
|
66 if (platform.id == "amazon-fireos" || platform.id == "android" || platform.id == "ios" || |
|
67 platform.id == "windowsphone" || platform.id == "firefoxos" || platform.id == "ubuntu" || |
|
68 platform.id == "windows8" || platform.id == "windows") { |
|
69 |
|
70 if (typeof _buttonLabels === 'string') { |
|
71 _buttonLabels = _buttonLabels.split(","); // not crazy about changing the var type here |
|
72 } |
|
73 } else { |
|
74 if (Array.isArray(_buttonLabels)) { |
|
75 var buttonLabelArray = _buttonLabels; |
|
76 _buttonLabels = buttonLabelArray.toString(); |
|
77 } |
|
78 } |
|
79 exec(resultCallback, null, "Notification", "confirm", [message, _title, _buttonLabels]); |
|
80 }, |
|
81 |
|
82 /** |
|
83 * Open a native prompt dialog, with a customizable title and button text. |
|
84 * The following results are returned to the result callback: |
|
85 * buttonIndex Index number of the button selected. |
|
86 * input1 The text entered in the prompt dialog box. |
|
87 * |
|
88 * @param {String} message Dialog message to display (default: "Prompt message") |
|
89 * @param {Function} resultCallback The callback that is called when user clicks on a button. |
|
90 * @param {String} title Title of the dialog (default: "Prompt") |
|
91 * @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"]) |
|
92 * @param {String} defaultText Textbox input value (default: empty string) |
|
93 */ |
|
94 prompt: function(message, resultCallback, title, buttonLabels, defaultText) { |
|
95 var _message = (message || "Prompt message"); |
|
96 var _title = (title || "Prompt"); |
|
97 var _buttonLabels = (buttonLabels || ["OK","Cancel"]); |
|
98 var _defaultText = (defaultText || ""); |
|
99 exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels, _defaultText]); |
|
100 }, |
|
101 |
|
102 /** |
|
103 * Causes the device to beep. |
|
104 * On Android, the default notification ringtone is played "count" times. |
|
105 * |
|
106 * @param {Integer} count The number of beeps. |
|
107 */ |
|
108 beep: function(count) { |
|
109 var defaultedCount = count || 1; |
|
110 exec(null, null, "Notification", "beep", [ defaultedCount ]); |
|
111 } |
|
112 }; |