From 5b37bbda6b848eb295f8ea16973652c2133e43a6 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Mon, 3 Jun 2013 09:20:44 -0700 Subject: [PATCH] Bug 872143 - Make InputWidgetHelper use async prompts. r=mfinkle --- .../chrome/content/InputWidgetHelper.js | 55 +++++++++---------- mobile/android/modules/Prompt.jsm | 9 +++ 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/mobile/android/chrome/content/InputWidgetHelper.js b/mobile/android/chrome/content/InputWidgetHelper.js index 77f06023c45..5f140b5e09c 100644 --- a/mobile/android/chrome/content/InputWidgetHelper.js +++ b/mobile/android/chrome/content/InputWidgetHelper.js @@ -23,44 +23,41 @@ var InputWidgetHelper = { show: function(aElement) { let type = aElement.getAttribute('type'); - let msg = { - type: "Prompt:Show", + let p = new Prompt({ + window: aElement.ownerDocument.defaultView, title: Strings.browser.GetStringFromName("inputWidgetHelper." + aElement.getAttribute('type')), buttons: [ Strings.browser.GetStringFromName("inputWidgetHelper.set"), Strings.browser.GetStringFromName("inputWidgetHelper.clear"), Strings.browser.GetStringFromName("inputWidgetHelper.cancel") ], - inputs: [ - { type: type, value: aElement.value } - ] - }; - - let data = JSON.parse(sendMessageToJava(msg)); - - let changed = false; - if (data.button == -1) { - // This type is not supported with this android version. - return; - } - if (data.button == 1) { - // The user cleared the value. - if (aElement.value != "") { - aElement.value = ""; - changed = true; + }).addDatePicker({ + value: aElement.value, + type: type, + }).show((function(data) { + let changed = false; + if (data.button == -1) { + // This type is not supported with this android version. + return; } - } else if (data.button == 0) { - // Commit the new value. - if (aElement.value != data[type]) { - aElement.value = data[type]; - changed = true; + if (data.button == 1) { + // The user cleared the value. + if (aElement.value != "") { + aElement.value = ""; + changed = true; + } + } else if (data.button == 0) { + // Commit the new value. + if (aElement.value != data[type]) { + aElement.value = data[type + "0"]; + changed = true; + } } - } - // Else the user canceled the input. - - if (changed) - this.fireOnChange(aElement); + // Else the user canceled the input. + if (changed) + this.fireOnChange(aElement); + }).bind(this)); }, _isValidInput: function(aElement) { diff --git a/mobile/android/modules/Prompt.jsm b/mobile/android/modules/Prompt.jsm index 687044a75ec..d28337432ec 100644 --- a/mobile/android/modules/Prompt.jsm +++ b/mobile/android/modules/Prompt.jsm @@ -48,6 +48,8 @@ Prompt.prototype = { obj.id = aOptions.id || (aOptions.type + this[aOptions.type + "_count"]); this[aOptions.type + "_count"]++; + if (!this.msg.inputs) + this.msg.inputs = []; this.msg.inputs.push(obj); return this; }, @@ -81,6 +83,13 @@ Prompt.prototype = { }); }, + addDatePicker: function(aOptions) { + return this._addInput({ + type: aOptions.type || "date", + value: aOptions.value, + }); + }, + addMenulist: function(aOptions) { return this._addInput({ type: "menulist",