Touchgui/plugins/org.apache.cordova.dialogs/www/notification.js

Thu, 04 Jun 2015 14:50:33 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 04 Jun 2015 14:50:33 +0200
changeset 0
e8ccd40d0ef6
permissions
-rw-r--r--

Genesis of lecture sources for Droidcon Berlin 2015 in Postbahnhof.

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

mercurial