FPDAM2023/Public/ecma/views/FPDAM2023.Admission.ecma.js

81 lines
2.8 KiB
JavaScript
Raw Normal View History

FPDAM2023.Admission = function(fpdam2023, inputs){
const self = this;
let started = false;
const construct = () => {};
this.start = callback => {
const end = status => fpdam2023.is_function(callback) && callback(status);
if(started){
end(false);
return false;
};
started = true;
end(true);
return true;
};
this.refresh = (item, event) => fpdam2023.comp.tables.fill(
item,
"/app/enrollments/list",
{},
null, // callback
"enrollments_refresh_error",
fpdam2023.sessions.get_errors_list().concat([])
);
this.get_pdf = (item, event) => window.open("http://www.edu.xunta.gal/fp/webfm_send/10259", "_blank");
// this.get_pdf = (item, event) => window.open("/data/listaxe_solicitude_provisional_distancia_cs_2023.pdf", "_blank");
this.get_plain_text = (item, event) => window.open("/data/listaxe_solicitude_provisional_distancia_cs_2023.txt", "_blank");
this.create_json = (item, event) => {};
this.create_sql = (item, event) => fpdam2023.ajax.get("/data/listaxe_solicitude_provisional_distancia_cs_2023.txt", response => {
const anchor = fpdam2023.item_self.appendChild(document.createElement("a"));
let sql = "use FPDAM2023;\n\n";
response.split("Código persoal de consulta: ").slice(1).some(block => {
block = block.trim();
partner_code = block.match(/^([0-9a-z]{10})/i)[1];
[
/[^\r\n]+[\r\n]+/,
/Páxina [0-9]+ de [0-9]+[\r\n]+([0-9]{2}\/){2}[0-9]{4}([\r\n]+[^\r\n]+){8}[\r\n]/g
].forEach(re => block = block.replace(re, ""));
block.replace(/([A-Z]{2}[A-Z]{3}[0-9]{2})[\s\-]+([^\r\n]+([\r\n]((?!(puntuaci))[^\r\n])+)*)[\r\n]+puntuaci[oó]n\s+total\s*\:\s*([0-9]+)((?!([0-9]{8}[\s\-]+))(.|[\r\n]))+([0-9]{8})[\s\-]+([^\r\n]+)/gi, (...arguments) => {
const enrollment = {
course_code : arguments[1],
course_name : arguments[2],
score : Number(arguments[6]),
center_code : Number(arguments[10]),
center_name : arguments[11]
};
sql += "call enrollments_add(null, 2023, 'provisionais', '" + partner_code + "', '" + enrollment.course_code + "', '" + enrollment.course_name + "', " + enrollment.center_code + ", '" + enrollment.center_name + "', " + enrollment.score + ", @error, @id);\n";
});
});
anchor.setAttribute("href", "data:application/sql;base64," + btoa(sql));
anchor.setAttribute("download", "admission.my.sql");
anchor.click();
anchor.remove();
});
construct();
};