- CSV-be mentés hozzáadva - Új azonosító hozzáadása menet közben implementálva
148 lines
3.4 KiB
JavaScript
148 lines
3.4 KiB
JavaScript
let CP_ID = "";
|
|
|
|
function cp_login() {
|
|
let cp_id = document.getElementById("cpidinput").value.trim();
|
|
if (cp_id.length === 0) {
|
|
return;
|
|
}
|
|
|
|
let request_data = {
|
|
action: "cp_login",
|
|
data: {
|
|
cp_id: cp_id
|
|
}
|
|
}
|
|
request(request_data).then(resp_str => {
|
|
let resp = JSON.parse(resp_str);
|
|
if (resp) {
|
|
CP_ID = cp_id;
|
|
cp_report(); // információk letöltése
|
|
show("control_panel");
|
|
hide("loginbox");
|
|
}
|
|
});
|
|
}
|
|
|
|
function cp_report() {
|
|
let request_data = {
|
|
action: "cp_short_info",
|
|
cp_id: CP_ID,
|
|
}
|
|
request(request_data).then(resp_str => {
|
|
// alapinfók kiírása
|
|
let report = JSON.parse(resp_str);
|
|
let short_info = `<h2>Összefoglaló információk</h2>
|
|
<h4>Szavazatok: ${report["total_votes"]}/${report["total_electors"]}</span></h4>`;
|
|
document.getElementById("short_info").innerHTML = short_info;
|
|
|
|
// gombok láthatóságának vezérlése
|
|
cp_refresh_control_buttons(report["state"]);
|
|
});
|
|
}
|
|
|
|
function cp_toggle_publish_results(en) {
|
|
if (en) {
|
|
show("publishbtn");
|
|
} else {
|
|
hide("publishbtn");
|
|
}
|
|
}
|
|
|
|
function cp_refresh_control_buttons(state) {
|
|
if (state["open_for_submit"]) {
|
|
hide("enablesubmitbtn");
|
|
show("disablesubmitbtn");
|
|
} else {
|
|
show("enablesubmitbtn");
|
|
hide("disablesubmitbtn");
|
|
}
|
|
|
|
if (state["state"] === "open") {
|
|
hide("openelectionbtn");
|
|
show("closeelectionbtn");
|
|
show("submitbox");
|
|
} else if (state["state"] === "closed") {
|
|
show("openelectionbtn");
|
|
hide("closeelectionbtn");
|
|
hide("submitbox");
|
|
}
|
|
|
|
if (state["results_public"]) {
|
|
show("undopublishbtn");
|
|
hide("publishbox");
|
|
} else {
|
|
hide("undopublishbtn");
|
|
show("publishbox");
|
|
}
|
|
|
|
if (state["results_public"]) {
|
|
show("undopublishbtn");
|
|
hide("publishbox");
|
|
} else {
|
|
hide("undopublishbtn");
|
|
show("publishbox");
|
|
}
|
|
}
|
|
|
|
function cp_modify_state(cmd) {
|
|
let request_data = {
|
|
action: "cp_mod_state",
|
|
cp_id: CP_ID,
|
|
data: {
|
|
command: cmd
|
|
}
|
|
};
|
|
|
|
request(request_data).then(resp_str => {
|
|
let state = JSON.parse(resp_str);
|
|
cp_refresh_control_buttons(state);
|
|
});
|
|
}
|
|
|
|
function cp_internal_totaling(filename) {
|
|
let request_data = {
|
|
action: "cp_generate_plot",
|
|
cp_id: CP_ID
|
|
};
|
|
|
|
request(request_data).then(svg => {
|
|
let plotTab = window.open("newtab");
|
|
plotTab.addEventListener("load", () => {
|
|
plotTab.document.write(svg);
|
|
});
|
|
});
|
|
}
|
|
|
|
function cp_download_resport_as_csv() {
|
|
let request_data = {
|
|
action: "cp_csv_report",
|
|
cp_id: CP_ID
|
|
};
|
|
|
|
request(request_data).then(resp_str => {
|
|
let csv_url = JSON.parse(resp_str);
|
|
if (csv_url !== "") {
|
|
let link = document.createElement("a");
|
|
link.download = "report.csv";
|
|
link.href = csv_url;
|
|
link.click();
|
|
}
|
|
});
|
|
}
|
|
|
|
function cp_add_access_code() {
|
|
let ac = window.prompt("Új azonosító hozzáadása", "");
|
|
if (ac == null) {
|
|
return;
|
|
}
|
|
|
|
let request_data = {
|
|
action: "cp_add_access_code",
|
|
cp_id: CP_ID,
|
|
data: {
|
|
access_code: ac
|
|
}
|
|
};
|
|
|
|
request(request_data);
|
|
} |