You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/03/21 03:53:46 UTC

js commit: CB-2679 Add prompt to Notification API for js

Updated Branches:
  refs/heads/master c6edd5723 -> bbf1562d4


CB-2679 Add prompt to Notification API for js

- added a native prompt method to Notification API
- added 2 jasmine unit tests for new prompt method
- note that the prompt method expects an Array for buttonLabels


Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/bbf1562d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/bbf1562d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/bbf1562d

Branch: refs/heads/master
Commit: bbf1562d4934b1331ffb263424b6ae054cedeb71
Parents: c6edd57
Author: James Jong <wj...@gmail.com>
Authored: Mon Mar 18 12:26:02 2013 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Mar 20 22:52:50 2013 -0400

----------------------------------------------------------------------
 lib/common/plugin/notification.js |   18 ++++++++++++++++++
 test/test.notification.js         |   17 +++++++++++++++++
 2 files changed, 35 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/bbf1562d/lib/common/plugin/notification.js
----------------------------------------------------------------------
diff --git a/lib/common/plugin/notification.js b/lib/common/plugin/notification.js
index 16b3877..d877044 100644
--- a/lib/common/plugin/notification.js
+++ b/lib/common/plugin/notification.js
@@ -78,6 +78,24 @@ module.exports = {
     },
 
     /**
+     * Open a native prompt dialog, with a customizable title and button text.
+     * The following results are returned to the result callback:
+     *  buttonIndex     Index number of the button selected.
+     *  input1          The text entered in the prompt dialog box.
+     *
+     * @param {String} message              Dialog message to display (default: "Prompt message")
+     * @param {Function} resultCallback     The callback that is called when user clicks on a button.
+     * @param {String} title                Title of the dialog (default: "Prompt")
+     * @param {Array} buttonLabels          Array of strings for the button labels (default: ["OK","Cancel"])
+     */
+    prompt: function(message, resultCallback, title, buttonLabels) {
+        var _message = (message || "Prompt message");
+        var _title = (title || "Prompt");
+        var _buttonLabels = (buttonLabels || ["OK","Cancel"]);
+        exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels]);
+    },
+
+    /**
      * Causes the device to vibrate.
      *
      * @param {Integer} mills       The number of milliseconds to vibrate for.

http://git-wip-us.apache.org/repos/asf/cordova-js/blob/bbf1562d/test/test.notification.js
----------------------------------------------------------------------
diff --git a/test/test.notification.js b/test/test.notification.js
index 7e670b9..a7122c9 100644
--- a/test/test.notification.js
+++ b/test/test.notification.js
@@ -57,6 +57,23 @@ describe("notification", function () {
         });
     });
 
+    describe("when prompting", function () {
+        it("defaults the title to Prompt, the message to Prompt message and the buttons to OK,Cancel", function () {
+            notification.prompt();
+            expect(exec).toHaveBeenCalledWith(
+                undefined, null, "Notification", "prompt",
+                ["Prompt message", "Prompt", ['OK','Cancel']]);
+        });
+
+        it("passes the provided params to the exec method", function () {
+            var cb = jasmine.createSpy();
+            notification.prompt("baby prompt me one more time!", cb, "oh baby baby", ["Yes", "No"]);
+            expect(exec).toHaveBeenCalledWith(
+                cb, null, "Notification", "prompt", 
+                ["baby prompt me one more time!", "oh baby baby", ['Yes','No']]);
+        });
+    });
+
     it("causes the device to vibrate", function () {
         notification.vibrate(1000);
         expect(exec).toHaveBeenCalledWith(