Touchgui/plugins/org.apache.cordova.dialogs/src/blackberry10/index.js

changeset 0
e8ccd40d0ef6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Touchgui/plugins/org.apache.cordova.dialogs/src/blackberry10/index.js	Thu Jun 04 14:50:33 2015 +0200
     1.3 @@ -0,0 +1,87 @@
     1.4 +/*
     1.5 +* Copyright 2013 Research In Motion Limited.
     1.6 +*
     1.7 +* Licensed under the Apache License, Version 2.0 (the "License");
     1.8 +* you may not use this file except in compliance with the License.
     1.9 +* You may obtain a copy of the License at
    1.10 +*
    1.11 +* http://www.apache.org/licenses/LICENSE-2.0
    1.12 +*
    1.13 +* Unless required by applicable law or agreed to in writing, software
    1.14 +* distributed under the License is distributed on an "AS IS" BASIS,
    1.15 +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 +* See the License for the specific language governing permissions and
    1.17 +* limitations under the License.
    1.18 +*/
    1.19 +
    1.20 +function showDialog(args, dialogType, result) {
    1.21 +    //Unpack and map the args
    1.22 +    var msg = JSON.parse(decodeURIComponent(args[0])),
    1.23 +    title = JSON.parse(decodeURIComponent(args[1])),
    1.24 +    btnLabel = JSON.parse(decodeURIComponent(args[2]));
    1.25 +
    1.26 +    if (!Array.isArray(btnLabel)) {
    1.27 +        //Converts to array for (string) and (string,string, ...) cases
    1.28 +        btnLabel = btnLabel.split(",");
    1.29 +    }
    1.30 +
    1.31 +    if (msg && typeof msg === "string") {
    1.32 +        msg = msg.replace(/^"|"$/g, "").replace(/\\"/g, '"');
    1.33 +    } else {
    1.34 +        result.error("message is undefined");
    1.35 +        return;
    1.36 +    }
    1.37 +
    1.38 +    var messageObj = {
    1.39 +        title : title,
    1.40 +        htmlmessage :  msg,
    1.41 +        dialogType : dialogType,
    1.42 +        optionalButtons : btnLabel
    1.43 +    };
    1.44 +
    1.45 +    //TODO replace with getOverlayWebview() when available in webplatform
    1.46 +    qnx.webplatform.getWebViews()[2].dialog.show(messageObj, function (data) {
    1.47 +        if (typeof data === "number") {
    1.48 +            //Confirm dialog call back needs to be called with one-based indexing [1,2,3 etc]
    1.49 +            result.callbackOk(++data, false);
    1.50 +        } else {
    1.51 +            //Prompt dialog callback expects object
    1.52 +            result.callbackOk({
    1.53 +                buttonIndex: data.ok ? 1 : 0,
    1.54 +                input1: (data.oktext) ? decodeURIComponent(data.oktext) : ""
    1.55 +            }, false);
    1.56 +        }
    1.57 +    });
    1.58 +
    1.59 +    result.noResult(true);
    1.60 +}
    1.61 +
    1.62 +module.exports = {
    1.63 +    alert: function (success, fail, args, env) {
    1.64 +        var result = new PluginResult(args, env);
    1.65 +
    1.66 +        if (Object.keys(args).length < 3) {
    1.67 +            result.error("Notification action - alert arguments not found.");
    1.68 +        } else {
    1.69 +            showDialog(args, "CustomAsk", result);
    1.70 +        }
    1.71 +    },
    1.72 +    confirm: function (success, fail, args, env) {
    1.73 +        var result = new PluginResult(args, env);
    1.74 +
    1.75 +        if (Object.keys(args).length < 3) {
    1.76 +            result.error("Notification action - confirm arguments not found.");
    1.77 +        } else {
    1.78 +            showDialog(args, "CustomAsk", result);
    1.79 +        }
    1.80 +    },
    1.81 +    prompt: function (success, fail, args, env) {
    1.82 +        var result = new PluginResult(args, env);
    1.83 +
    1.84 +        if (Object.keys(args).length < 3) {
    1.85 +            result.error("Notification action - prompt arguments not found.");
    1.86 +        } else {
    1.87 +            showDialog(args, "JavaScriptPrompt", result);
    1.88 +        }
    1.89 +    }
    1.90 +};

mercurial