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

View File

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