Move notifications into notify function

This commit is contained in:
Grégory Soutadé 2015-01-21 18:49:26 +01:00
parent f5a0da3f69
commit a5b3dec5b0
1 changed files with 23 additions and 38 deletions

View File

@ -54,6 +54,15 @@ function debug(s)
console.log(s);
}
function notify(text, data)
{
notifications.notify({
title: "gPass",
text: "Error : It seems that it's not a gPass server",
data: this.responseText,
});
}
function generate_request(domain, login, mkey)
{
v = "@@" + domain + ";" + login;
@ -89,10 +98,8 @@ function ask_server(form, field, logins, domain, wdomain, mkey, salt, submit)
debug("Keys " + keys);
// Need to do a synchronous request
var gPassRequest = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].
createInstance(Ci.nsIXMLHttpRequest);
var ret = SERVER.OK;
// gPassRequest.addEventListener("progress", function(evt) { ; }, false);
@ -111,11 +118,8 @@ function ask_server(form, field, logins, domain, wdomain, mkey, salt, submit)
params = r[a].split("=");
if (params.length != 2 && params[0] != "<end>")
{
notifications.notify({
title: "gPasss",
text: "Error : It seems that it's not a gPass server",
data: this.responseText,
});
notify("Error : It seems that it's not a gPass server",
this.responseText);
ret = SERVER.FAILED;
break;
}
@ -127,11 +131,8 @@ function ask_server(form, field, logins, domain, wdomain, mkey, salt, submit)
if (params[1].indexOf("gpass-") != 0)
{
notifications.notify({
title: "gPasss",
text: "Error : It seems that it's not a gPass server",
data: this.responseText,
});
notify("Error : It seems that it's not a gPass server",
this.responseText);
ret = SERVER.FAILED;
break;
}
@ -140,11 +141,8 @@ function ask_server(form, field, logins, domain, wdomain, mkey, salt, submit)
if (server_protocol_version > protocol_version)
{
notifications.notify({
title: "gPasss",
text: "Protocol version not supported, please upgrade your addon",
data: "Protocol version not supported, please upgrade your addon",
});
notify("Protocol version not supported, please upgrade your addon",
"Protocol version not supported, please upgrade your addon");
ret = SERVER.FAILED;
}
else
@ -180,11 +178,8 @@ function ask_server(form, field, logins, domain, wdomain, mkey, salt, submit)
default:
debug("Unknown command " + params[0]);
notifications.notify({
title: "gPasss",
text: "Error : It seems that it's not a gPass server",
data: this.responseText,
});
notify("Error : It seems that it's not a gPass server",
this.responseText);
ret = SERVER.FAILED;
break;
}
@ -211,11 +206,8 @@ function ask_server(form, field, logins, domain, wdomain, mkey, salt, submit)
}
else
{
notifications.notify({
title: "gPasss",
text: "Password successfully replaced",
data: "Password successfully replaced",
});
notify("Password successfully replaced",
"Password successfully replaced");
}
}
else
@ -224,22 +216,15 @@ function ask_server(form, field, logins, domain, wdomain, mkey, salt, submit)
ret = SERVER.FAILED;
notifications.notify({
title: "gPasss",
text: "No password found in database",
data: "No password found in database",
});
notify("No password found in database",
"No password found in database");
}
}, false);
gPassRequest.addEventListener("error", function(evt) {
debug("error");
ret = false;
notifications.notify({
title: "gPasss",
text: "Error",
data: "Error",
});
notify("Error",
"Error");
}, false);
debug("connect to " + prefSet.prefs.account_url);
gPassRequest.open("POST", prefSet.prefs.account_url, true);