michael@0: /* michael@0: * michael@0: * Licensed to the Apache Software Foundation (ASF) under one michael@0: * or more contributor license agreements. See the NOTICE file michael@0: * distributed with this work for additional information michael@0: * regarding copyright ownership. The ASF licenses this file michael@0: * to you under the Apache License, Version 2.0 (the michael@0: * "License"); you may not use this file except in compliance michael@0: * with the License. You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, michael@0: * software distributed under the License is distributed on an michael@0: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY michael@0: * KIND, either express or implied. See the License for the michael@0: * specific language governing permissions and limitations michael@0: * under the License. michael@0: * michael@0: */ michael@0: michael@0: var exec = require('cordova/exec'); michael@0: var platform = require('cordova/platform'); michael@0: michael@0: /** michael@0: * Provides access to notifications on the device. michael@0: */ michael@0: michael@0: module.exports = { michael@0: michael@0: /** michael@0: * Open a native alert dialog, with a customizable title and button text. michael@0: * michael@0: * @param {String} message Message to print in the body of the alert michael@0: * @param {Function} completeCallback The callback that is called when user clicks on a button. michael@0: * @param {String} title Title of the alert dialog (default: Alert) michael@0: * @param {String} buttonLabel Label of the close button (default: OK) michael@0: */ michael@0: alert: function(message, completeCallback, title, buttonLabel) { michael@0: var _title = (title || "Alert"); michael@0: var _buttonLabel = (buttonLabel || "OK"); michael@0: exec(completeCallback, null, "Notification", "alert", [message, _title, _buttonLabel]); michael@0: }, michael@0: michael@0: /** michael@0: * Open a native confirm dialog, with a customizable title and button text. michael@0: * The result that the user selects is returned to the result callback. michael@0: * michael@0: * @param {String} message Message to print in the body of the alert michael@0: * @param {Function} resultCallback The callback that is called when user clicks on a button. michael@0: * @param {String} title Title of the alert dialog (default: Confirm) michael@0: * @param {Array} buttonLabels Array of the labels of the buttons (default: ['OK', 'Cancel']) michael@0: */ michael@0: confirm: function(message, resultCallback, title, buttonLabels) { michael@0: var _title = (title || "Confirm"); michael@0: var _buttonLabels = (buttonLabels || ["OK", "Cancel"]); michael@0: michael@0: // Strings are deprecated! michael@0: if (typeof _buttonLabels === 'string') { michael@0: console.log("Notification.confirm(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array)."); michael@0: } michael@0: michael@0: // Some platforms take an array of button label names. michael@0: // Other platforms take a comma separated list. michael@0: // For compatibility, we convert to the desired type based on the platform. michael@0: if (platform.id == "amazon-fireos" || platform.id == "android" || platform.id == "ios" || michael@0: platform.id == "windowsphone" || platform.id == "firefoxos" || platform.id == "ubuntu" || michael@0: platform.id == "windows8" || platform.id == "windows") { michael@0: michael@0: if (typeof _buttonLabels === 'string') { michael@0: _buttonLabels = _buttonLabels.split(","); // not crazy about changing the var type here michael@0: } michael@0: } else { michael@0: if (Array.isArray(_buttonLabels)) { michael@0: var buttonLabelArray = _buttonLabels; michael@0: _buttonLabels = buttonLabelArray.toString(); michael@0: } michael@0: } michael@0: exec(resultCallback, null, "Notification", "confirm", [message, _title, _buttonLabels]); michael@0: }, michael@0: michael@0: /** michael@0: * Open a native prompt dialog, with a customizable title and button text. michael@0: * The following results are returned to the result callback: michael@0: * buttonIndex Index number of the button selected. michael@0: * input1 The text entered in the prompt dialog box. michael@0: * michael@0: * @param {String} message Dialog message to display (default: "Prompt message") michael@0: * @param {Function} resultCallback The callback that is called when user clicks on a button. michael@0: * @param {String} title Title of the dialog (default: "Prompt") michael@0: * @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"]) michael@0: * @param {String} defaultText Textbox input value (default: empty string) michael@0: */ michael@0: prompt: function(message, resultCallback, title, buttonLabels, defaultText) { michael@0: var _message = (message || "Prompt message"); michael@0: var _title = (title || "Prompt"); michael@0: var _buttonLabels = (buttonLabels || ["OK","Cancel"]); michael@0: var _defaultText = (defaultText || ""); michael@0: exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels, _defaultText]); michael@0: }, michael@0: michael@0: /** michael@0: * Causes the device to beep. michael@0: * On Android, the default notification ringtone is played "count" times. michael@0: * michael@0: * @param {Integer} count The number of beeps. michael@0: */ michael@0: beep: function(count) { michael@0: var defaultedCount = count || 1; michael@0: exec(null, null, "Notification", "beep", [ defaultedCount ]); michael@0: } michael@0: };