1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/Touchgui/plugins/org.apache.cordova.dialogs/www/notification.js Thu Jun 04 14:50:33 2015 +0200 1.3 @@ -0,0 +1,112 @@ 1.4 +/* 1.5 + * 1.6 + * Licensed to the Apache Software Foundation (ASF) under one 1.7 + * or more contributor license agreements. See the NOTICE file 1.8 + * distributed with this work for additional information 1.9 + * regarding copyright ownership. The ASF licenses this file 1.10 + * to you under the Apache License, Version 2.0 (the 1.11 + * "License"); you may not use this file except in compliance 1.12 + * with the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, 1.17 + * software distributed under the License is distributed on an 1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1.19 + * KIND, either express or implied. See the License for the 1.20 + * specific language governing permissions and limitations 1.21 + * under the License. 1.22 + * 1.23 +*/ 1.24 + 1.25 +var exec = require('cordova/exec'); 1.26 +var platform = require('cordova/platform'); 1.27 + 1.28 +/** 1.29 + * Provides access to notifications on the device. 1.30 + */ 1.31 + 1.32 +module.exports = { 1.33 + 1.34 + /** 1.35 + * Open a native alert dialog, with a customizable title and button text. 1.36 + * 1.37 + * @param {String} message Message to print in the body of the alert 1.38 + * @param {Function} completeCallback The callback that is called when user clicks on a button. 1.39 + * @param {String} title Title of the alert dialog (default: Alert) 1.40 + * @param {String} buttonLabel Label of the close button (default: OK) 1.41 + */ 1.42 + alert: function(message, completeCallback, title, buttonLabel) { 1.43 + var _title = (title || "Alert"); 1.44 + var _buttonLabel = (buttonLabel || "OK"); 1.45 + exec(completeCallback, null, "Notification", "alert", [message, _title, _buttonLabel]); 1.46 + }, 1.47 + 1.48 + /** 1.49 + * Open a native confirm dialog, with a customizable title and button text. 1.50 + * The result that the user selects is returned to the result callback. 1.51 + * 1.52 + * @param {String} message Message to print in the body of the alert 1.53 + * @param {Function} resultCallback The callback that is called when user clicks on a button. 1.54 + * @param {String} title Title of the alert dialog (default: Confirm) 1.55 + * @param {Array} buttonLabels Array of the labels of the buttons (default: ['OK', 'Cancel']) 1.56 + */ 1.57 + confirm: function(message, resultCallback, title, buttonLabels) { 1.58 + var _title = (title || "Confirm"); 1.59 + var _buttonLabels = (buttonLabels || ["OK", "Cancel"]); 1.60 + 1.61 + // Strings are deprecated! 1.62 + if (typeof _buttonLabels === 'string') { 1.63 + console.log("Notification.confirm(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array)."); 1.64 + } 1.65 + 1.66 + // Some platforms take an array of button label names. 1.67 + // Other platforms take a comma separated list. 1.68 + // For compatibility, we convert to the desired type based on the platform. 1.69 + if (platform.id == "amazon-fireos" || platform.id == "android" || platform.id == "ios" || 1.70 + platform.id == "windowsphone" || platform.id == "firefoxos" || platform.id == "ubuntu" || 1.71 + platform.id == "windows8" || platform.id == "windows") { 1.72 + 1.73 + if (typeof _buttonLabels === 'string') { 1.74 + _buttonLabels = _buttonLabels.split(","); // not crazy about changing the var type here 1.75 + } 1.76 + } else { 1.77 + if (Array.isArray(_buttonLabels)) { 1.78 + var buttonLabelArray = _buttonLabels; 1.79 + _buttonLabels = buttonLabelArray.toString(); 1.80 + } 1.81 + } 1.82 + exec(resultCallback, null, "Notification", "confirm", [message, _title, _buttonLabels]); 1.83 + }, 1.84 + 1.85 + /** 1.86 + * Open a native prompt dialog, with a customizable title and button text. 1.87 + * The following results are returned to the result callback: 1.88 + * buttonIndex Index number of the button selected. 1.89 + * input1 The text entered in the prompt dialog box. 1.90 + * 1.91 + * @param {String} message Dialog message to display (default: "Prompt message") 1.92 + * @param {Function} resultCallback The callback that is called when user clicks on a button. 1.93 + * @param {String} title Title of the dialog (default: "Prompt") 1.94 + * @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"]) 1.95 + * @param {String} defaultText Textbox input value (default: empty string) 1.96 + */ 1.97 + prompt: function(message, resultCallback, title, buttonLabels, defaultText) { 1.98 + var _message = (message || "Prompt message"); 1.99 + var _title = (title || "Prompt"); 1.100 + var _buttonLabels = (buttonLabels || ["OK","Cancel"]); 1.101 + var _defaultText = (defaultText || ""); 1.102 + exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels, _defaultText]); 1.103 + }, 1.104 + 1.105 + /** 1.106 + * Causes the device to beep. 1.107 + * On Android, the default notification ringtone is played "count" times. 1.108 + * 1.109 + * @param {Integer} count The number of beeps. 1.110 + */ 1.111 + beep: function(count) { 1.112 + var defaultedCount = count || 1; 1.113 + exec(null, null, "Notification", "beep", [ defaultedCount ]); 1.114 + } 1.115 +};