Touchgui/plugins/org.apache.cordova.dialogs/src/blackberry10/index.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.

     1 /*
     2 * Copyright 2013 Research In Motion Limited.
     3 *
     4 * Licensed under the Apache License, Version 2.0 (the "License");
     5 * you may not use this file except in compliance with the License.
     6 * You may obtain a copy of the License at
     7 *
     8 * http://www.apache.org/licenses/LICENSE-2.0
     9 *
    10 * Unless required by applicable law or agreed to in writing, software
    11 * distributed under the License is distributed on an "AS IS" BASIS,
    12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13 * See the License for the specific language governing permissions and
    14 * limitations under the License.
    15 */
    17 function showDialog(args, dialogType, result) {
    18     //Unpack and map the args
    19     var msg = JSON.parse(decodeURIComponent(args[0])),
    20     title = JSON.parse(decodeURIComponent(args[1])),
    21     btnLabel = JSON.parse(decodeURIComponent(args[2]));
    23     if (!Array.isArray(btnLabel)) {
    24         //Converts to array for (string) and (string,string, ...) cases
    25         btnLabel = btnLabel.split(",");
    26     }
    28     if (msg && typeof msg === "string") {
    29         msg = msg.replace(/^"|"$/g, "").replace(/\\"/g, '"');
    30     } else {
    31         result.error("message is undefined");
    32         return;
    33     }
    35     var messageObj = {
    36         title : title,
    37         htmlmessage :  msg,
    38         dialogType : dialogType,
    39         optionalButtons : btnLabel
    40     };
    42     //TODO replace with getOverlayWebview() when available in webplatform
    43     qnx.webplatform.getWebViews()[2].dialog.show(messageObj, function (data) {
    44         if (typeof data === "number") {
    45             //Confirm dialog call back needs to be called with one-based indexing [1,2,3 etc]
    46             result.callbackOk(++data, false);
    47         } else {
    48             //Prompt dialog callback expects object
    49             result.callbackOk({
    50                 buttonIndex: data.ok ? 1 : 0,
    51                 input1: (data.oktext) ? decodeURIComponent(data.oktext) : ""
    52             }, false);
    53         }
    54     });
    56     result.noResult(true);
    57 }
    59 module.exports = {
    60     alert: function (success, fail, args, env) {
    61         var result = new PluginResult(args, env);
    63         if (Object.keys(args).length < 3) {
    64             result.error("Notification action - alert arguments not found.");
    65         } else {
    66             showDialog(args, "CustomAsk", result);
    67         }
    68     },
    69     confirm: function (success, fail, args, env) {
    70         var result = new PluginResult(args, env);
    72         if (Object.keys(args).length < 3) {
    73             result.error("Notification action - confirm arguments not found.");
    74         } else {
    75             showDialog(args, "CustomAsk", result);
    76         }
    77     },
    78     prompt: function (success, fail, args, env) {
    79         var result = new PluginResult(args, env);
    81         if (Object.keys(args).length < 3) {
    82             result.error("Notification action - prompt arguments not found.");
    83         } else {
    84             showDialog(args, "JavaScriptPrompt", result);
    85         }
    86     }
    87 };

mercurial