You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2013/05/14 06:15:30 UTC
[23/50] [abbrv] webworks commit: Cordova Notification API
implementation [alert, confirm, prompt, vibrate]
Cordova Notification API implementation [alert, confirm, prompt, vibrate]
Reviewed By: Bryan Higgins <bh...@blackberry.com>
Tested By: Tracy Li <tl...@blackberry.com>
Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/63452dbf
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/63452dbf
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/63452dbf
Branch: refs/heads/master
Commit: 63452dbf43d6ec27399a74d884d9bffa38b479d7
Parents: 957fc5b
Author: jkeshavarzi <jk...@blackberry.com>
Authored: Fri Apr 5 16:28:41 2013 -0400
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Fri May 3 10:13:30 2013 -0400
----------------------------------------------------------------------
.../project/plugins/Notification/index.js | 91 +++++++++++
.../bin/test/plugins/Notification/index.js | 119 +++++++++++++++
blackberry10/javascript/cordova.blackberry10.js | 69 ++++-----
3 files changed, 239 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/63452dbf/blackberry10/bin/templates/project/plugins/Notification/index.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/Notification/index.js b/blackberry10/bin/templates/project/plugins/Notification/index.js
new file mode 100644
index 0000000..497170b
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/Notification/index.js
@@ -0,0 +1,91 @@
+/*
+* Copyright 2013 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+function showDialog(args, dialogType, result) {
+ //Unpack and map the args
+ var msg = JSON.parse(decodeURIComponent(args[0])),
+ title = JSON.parse(decodeURIComponent(args[1])),
+ btnLabel = JSON.parse(decodeURIComponent(args[2]));
+
+ if (!Array.isArray(btnLabel)) {
+ //Converts to array for (string) and (string,string, ...) cases
+ btnLabel = btnLabel.split(",");
+ }
+
+ if (msg && typeof msg === "string") {
+ msg = msg.replace(/^"|"$/g, "").replace(/\\"/g, '"').replace(/\\\\/g, '\\');
+ } else {
+ result.error("message is undefined");
+ return;
+ }
+
+ var messageObj = {
+ title : title,
+ htmlmessage : msg,
+ dialogType : dialogType,
+ optionalButtons : btnLabel
+ };
+
+ //TODO replace with getOverlayWebview() when available in webplatform
+ qnx.webplatform.getWebViews()[2].dialog.show(messageObj, function (data) {
+ if (typeof data === "number") {
+ //Confirm dialog call back needs to be called with one-based indexing [1,2,3 etc]
+ result.callbackOk(++data, false);
+ } else {
+ //Prompt dialog callback expects object
+ result.callbackOk({
+ buttonIndex: data.ok ? 1 : 0,
+ input1: (data.oktext) ? decodeURIComponent(data.oktext) : null
+ }, false);
+ }
+ });
+
+ result.noResult(true);
+}
+
+module.exports = {
+ alert: function (success, fail, args, env) {
+ var result = new PluginResult(args, env);
+
+ if (Object.keys(args).length < 3) {
+ result.error("Notification action - alert arguments not found.");
+ } else {
+ showDialog(args, "CustomAsk", result);
+ }
+ },
+ confirm: function (success, fail, args, env) {
+ var result = new PluginResult(args, env);
+
+ if (Object.keys(args).length < 3) {
+ result.error("Notification action - confirm arguments not found.");
+ } else {
+ showDialog(args, "CustomAsk", result);
+ }
+ },
+ prompt: function (success, fail, args, env) {
+ var result = new PluginResult(args, env);
+
+ if (Object.keys(args).length < 3) {
+ result.error("Notification action - prompt arguments not found.");
+ } else {
+ showDialog(args, "JavaScriptPrompt", result);
+ }
+ },
+ beep: function (success, fail, args, env) {
+ var result = new PluginResult(args, env);
+ result.error("Beep not supported");
+ }
+};
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/63452dbf/blackberry10/bin/test/plugins/Notification/index.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/test/plugins/Notification/index.js b/blackberry10/bin/test/plugins/Notification/index.js
new file mode 100644
index 0000000..2b585f8
--- /dev/null
+++ b/blackberry10/bin/test/plugins/Notification/index.js
@@ -0,0 +1,119 @@
+/*
+* Copyright 2013 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+function mockAndTestDialog(htmlmessage, title, dialogType, buttonLabel) {
+ GLOBAL.qnx = {
+ webplatform: {
+ getWebViews: function () {
+ var webviews = [{}, {},
+ {//overlayWebview
+ dialog: {
+ show: function(messageObj, callback) {
+ expect(messageObj.title).toEqual(title);
+ expect(messageObj.htmlmessage).toEqual(htmlmessage);
+ expect(messageObj.dialogType).toEqual(dialogType);
+ expect(messageObj.optionalButtons).toEqual(buttonLabel);
+ expect(typeof callback).toEqual("function");
+ }
+ }
+ }];
+ return webviews;
+ }
+ }
+ };
+
+}
+
+describe("Notification", function () {
+ var _apiDir = __dirname + "./../../../templates/project/plugins/Notification/",
+ index,
+ success = function() {},
+ fail = function() {},
+ result = {
+ error: jasmine.createSpy(),
+ noResult: jasmine.createSpy()
+ },
+ args = {
+ 0: "%22Dialog%20message.%22",
+ 1: "%22Dialog%20Title%22",
+ 2: "%22Continue%22"
+ };
+
+ beforeEach(function () {
+ index = require(_apiDir + "index");
+
+ GLOBAL.PluginResult = function () {
+ return result;
+ };
+ });
+
+ afterEach(function () {
+ delete require.cache[require.resolve(_apiDir + "index")];
+ delete GLOBAL.qnx;
+ delete GLOBAL.PluginResult;
+ });
+
+ describe("alert", function () {
+ it("fails with invalid number of args", function () {
+ index.alert(success, fail, {}, {});
+ expect(result.error).toHaveBeenCalledWith("Notification action - alert arguments not found.");
+ });
+
+ it("calls dialog.show with correct params", function () {
+ mockAndTestDialog("Dialog message.", "Dialog Title", "CustomAsk", ["Continue"]);
+ index.alert(success, fail, args, {});
+ expect(result.noResult).toHaveBeenCalled();
+ });
+ });
+
+ describe("confirm", function () {
+ it("fails with invalid number of args", function () {
+ index.confirm(success, fail, {}, {});
+ expect(result.error).toHaveBeenCalledWith("Notification action - confirm arguments not found.");
+ });
+
+ it("calls dialog.show with correct params", function () {
+ mockAndTestDialog("Dialog message.", "Dialog Title", "CustomAsk", ["Continue"]);
+ index.confirm(success, fail, args, {});
+ expect(result.noResult).toHaveBeenCalled();
+ });
+
+ it("calls dialog.show with correct params [deprecated buttonArg]", function () {
+ var args = {
+ 0: "%22Dialog%20message.%22",
+ 1: "%22Dialog%20Title%22",
+ 2: "%22Continue,Cancel%22"
+ };
+
+ mockAndTestDialog("Dialog message.", "Dialog Title", "CustomAsk", ["Continue", "Cancel"]);
+ index.confirm(success, fail, args, {});
+ expect(result.noResult).toHaveBeenCalled();
+ });
+ });
+
+ describe("prompt", function () {
+ it("fails with invalid number of args", function () {
+ index.prompt(success, fail, {}, {});
+ expect(result.error).toHaveBeenCalledWith("Notification action - prompt arguments not found.");
+ });
+
+ it("calls dialog.show with correct params", function () {
+ mockAndTestDialog("Dialog message.", "Dialog Title", "JavaScriptPrompt", ["Continue"]);
+ index.prompt(success, fail, args, {});
+ expect(result.noResult).toHaveBeenCalled();
+ });
+ });
+});
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/63452dbf/blackberry10/javascript/cordova.blackberry10.js
----------------------------------------------------------------------
diff --git a/blackberry10/javascript/cordova.blackberry10.js b/blackberry10/javascript/cordova.blackberry10.js
index 8fd6292..b730b08 100644
--- a/blackberry10/javascript/cordova.blackberry10.js
+++ b/blackberry10/javascript/cordova.blackberry10.js
@@ -1,8 +1,8 @@
// Platform: blackberry10
-// commit 2a6ac9642dcc875318e348c64bf4e69d2e932cc1
+// commit f9ac2930aa892422deff2be5a3b3b8f5e8f7edc0
-// File generated at :: Mon Apr 08 2013 09:08:23 GMT-0400 (EDT)
+// File generated at :: Mon Apr 08 2013 15:58:16 GMT-0400 (EDT)
/*
Licensed to the Apache Software Foundation (ASF) under one
@@ -952,7 +952,6 @@ var cordova = require('cordova'),
'Accelerometer' : require('cordova/plugin/blackberry10/accelerometer'),
'Compass' : require('cordova/plugin/blackberry10/magnetometer'),
'Capture' : require('cordova/plugin/blackberry10/capture'),
- 'Notification' : require('cordova/plugin/blackberry10/notification'),
'Media': require('cordova/plugin/blackberry10/media'),
'FileTransfer': require('cordova/plugin/blackberry10/fileTransfer')
};
@@ -4868,43 +4867,6 @@ module.exports = {
});
-// file: lib/blackberry10/plugin/blackberry10/notification.js
-define("cordova/plugin/blackberry10/notification", function(require, exports, module) {
-
-var cordova = require('cordova');
-
-module.exports = {
- alert: function (args, win, fail) {
- if (args.length !== 3) {
- return {"status" : 9, "message" : "Notification action - alert arguments not found"};
- }
-
- //Unpack and map the args
- var msg = args[0],
- title = args[1],
- btnLabel = args[2];
-
- blackberry.ui.dialog.customAskAsync.apply(this, [ msg, [ btnLabel ], win, { "title" : title } ]);
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- },
- confirm: function (args, win, fail) {
- if (args.length !== 3) {
- return {"status" : 9, "message" : "Notification action - confirm arguments not found"};
- }
-
- //Unpack and map the args
- var msg = args[0],
- title = args[1],
- btnLabel = args[2],
- btnLabels = btnLabel.split(",");
-
- blackberry.ui.dialog.customAskAsync.apply(this, [msg, btnLabels, win, {"title" : title} ]);
- return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
- }
-};
-
-});
-
// file: lib/blackberry10/plugin/blackberry10/platform.js
define("cordova/plugin/blackberry10/platform", function(require, exports, module) {
@@ -4935,6 +4897,17 @@ module.exports = {
clobbers: {
requestFileSystem: {
path: "cordova/plugin/blackberry10/requestFileSystem"
+ },
+ navigator: {
+ children: {
+ notification: {
+ children: {
+ vibrate: {
+ path: 'cordova/plugin/blackberry10/vibrate'
+ }
+ }
+ }
+ }
}
},
merges: {
@@ -5588,6 +5561,22 @@ self = module.exports = {
});
+// file: lib/blackberry10/plugin/blackberry10/vibrate.js
+define("cordova/plugin/blackberry10/vibrate", function(require, exports, module) {
+
+module.exports = function (time) {
+ var proto = Object.getPrototypeOf(navigator);
+
+ if (proto && proto.vibrate) {
+ proto.vibrate(time);
+ } else if (proto && proto.webkitVibrate) {
+ //Older OS contain webkit prefix
+ proto.webkitVibrate(time);
+ }
+};
+
+});
+
// file: lib/common/plugin/capture.js
define("cordova/plugin/capture", function(require, exports, module) {