Files
modoboa/static/js/confirmation.js
T
Antoine Nguyen db24deb216 * Domain removal is working again
* Fixed old references to 'response.error'
2011-07-03 11:43:27 +02:00

94 lines
2.4 KiB
JavaScript

var Confirmation = new Class({
Implements: [Options, Events],
options: {
checkboxes: []
},
build_checkboxes: function() {
var result = "";
var cbhash = new Hash(this.options.checkboxes);
cbhash.each(function(value, key, hash) {
result += "<input type='checkbox' name='" + key + "' value='' />";
result += "<label>" + value + "</label>";
});
return result;
},
initialize: function(url, urlparams, question, options) {
this.setOptions(options);
Confirmation.url = url;
Confirmation.urlparams = urlparams;
var content = new Element("div", {id: "confirmbox"});
var icondiv = new Element("div", {
id: "dlg-iconbox",
html: "<img src='/static/pics/dialog-warning.png' alt='Warning' />"
}).inject(content);
this.textdiv = new Element("div", {
id: "dlg-textbox",
html: "<b>" + question + "</b>"
+ "<p>" + this.build_checkboxes() + "</p>"
}).inject(content);
var buttonsdiv = new Element("div", {
id: "dlg-buttons"
}).inject(content);
new Element("input", {type: "button", name: "ok", id: "ok", value: "Ok"})
.addEvent("click", this.ok_handler)
.inject(buttonsdiv);
new Element("input", {type: "button", name: "cancel", value: "Cancel"})
.addEvent("click", this.cancel_handler)
.inject(buttonsdiv);
new Element("input", {type: "hidden", name: "result",
id: "result", value: "cancel"})
.inject(content);
SqueezeBox.open(content, {
size: {x: 350, y: 140},
handler: "adopt",
onClose: this.close_handler.bind(content)
});
},
close_handler: function(content) {
var result = this.getElement("input[name=result]");
if (result.get("value") != "ok") {
return;
}
var params = Confirmation.urlparams;
$$("input[type=checkbox]:checked").each(function(item) {
if (params != "") {
params += "&";
}
params += item.get("name") + "=true";
});
new Request.JSON({
method: "get",
url: Confirmation.url,
onSuccess: function(res) {
if (res.status == "ok") {
window.location.reload();
} else {
infobox.error(res.respmsg);
infobox.hide(2);
}
},
onFailure: function(xhr) {
$(parent.document.body).set("html", xhr.responseText);
}
}).send(params);
},
ok_handler: function(evt) {
$("result").value = "ok";
parent.SqueezeBox.close();
},
cancel_handler: function(evt) {
parent.SqueezeBox.close();
}
});