Bug 872143 - Make InputWidgetHelper use async prompts. r=mfinkle

This commit is contained in:
Wes Johnston 2013-06-03 09:20:44 -07:00
parent 66654705cf
commit ef223b63c9
2 changed files with 35 additions and 29 deletions

View File

@ -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) {

View File

@ -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",