2020-09-26 16:19:37 +02:00
|
|
|
// Cadre "debouchés" sur fiche etudiant
|
|
|
|
// affichage et saisie des informations sur l'avenir de l'étudiant.
|
|
|
|
|
|
|
|
// console.log('etud_debouche.js loaded');
|
|
|
|
|
2021-06-21 18:46:35 +02:00
|
|
|
$(function () {
|
2023-09-21 10:24:09 +02:00
|
|
|
display_itemsuivis(false);
|
2020-09-26 16:19:37 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
function display_itemsuivis(active) {
|
2023-09-21 10:24:09 +02:00
|
|
|
var etudid = $("div#fichedebouche").data("etudid");
|
|
|
|
var readonly = $("div#fichedebouche").data("readonly"); // present ro interface
|
|
|
|
|
|
|
|
if (!readonly) {
|
|
|
|
$("#adddebouchelink")
|
|
|
|
.off("click")
|
|
|
|
.click(function (e) {
|
|
|
|
e.preventDefault();
|
2024-09-09 16:21:51 +02:00
|
|
|
$.post(`${SCO_URL}../api/etudiant/${etudid}/itemsuivi/create`, {
|
2023-09-21 10:24:09 +02:00
|
|
|
etudid: etudid,
|
|
|
|
}).done(item_insert_new);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// add existing items
|
|
|
|
$.get(
|
2024-09-09 16:21:51 +02:00
|
|
|
`${SCO_URL}../api/etudiant/${etudid}/itemsuivis`,
|
|
|
|
{ },
|
2023-09-21 10:24:09 +02:00
|
|
|
function (L) {
|
|
|
|
for (var i in L) {
|
|
|
|
item_insert(
|
2024-09-09 16:21:51 +02:00
|
|
|
L[i]["id"],
|
|
|
|
L[i]["item_date_dmy"],
|
2023-09-21 10:24:09 +02:00
|
|
|
L[i]["situation"],
|
|
|
|
L[i]["tags"],
|
|
|
|
readonly
|
|
|
|
);
|
|
|
|
}
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
2023-09-21 10:24:09 +02:00
|
|
|
);
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-09-21 10:24:09 +02:00
|
|
|
$("div#fichedebouche").accordion({
|
|
|
|
heightStyle: "content",
|
|
|
|
collapsible: true,
|
|
|
|
active: active,
|
|
|
|
});
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
|
|
|
|
2021-06-21 18:46:35 +02:00
|
|
|
function item_insert_new(it) {
|
2024-09-09 16:21:51 +02:00
|
|
|
item_insert(it.id, it.item_date, it.situation, "", false);
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
|
|
|
|
2021-06-21 18:46:35 +02:00
|
|
|
function item_insert(itemsuivi_id, item_date, situation, tags, readonly) {
|
2023-09-21 10:24:09 +02:00
|
|
|
if (item_date === undefined) item_date = Date2DMY(new Date());
|
|
|
|
if (situation === undefined) situation = "";
|
|
|
|
if (tags === undefined) tags = "";
|
|
|
|
|
|
|
|
var nodes = item_nodes(itemsuivi_id, item_date, situation, tags, readonly);
|
|
|
|
// insert just before last li:
|
|
|
|
if ($("ul.listdebouches li.adddebouche").length > 0) {
|
|
|
|
$("ul.listdebouches").children(":last").before(nodes);
|
|
|
|
} else {
|
|
|
|
// mode readonly, pas de li "ajouter"
|
|
|
|
$("ul.listdebouches").append(nodes);
|
|
|
|
}
|
|
|
|
}
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
function item_nodes(itemsuivi_id, item_date, situation, tags, readonly) {
|
2023-09-21 10:24:09 +02:00
|
|
|
// console.log('item_nodes: itemsuivi_id=' + itemsuivi_id);
|
|
|
|
var sel_mois =
|
|
|
|
'Situation à la date du <input type="text" class="itemsuividatepicker" size="10" value="' +
|
|
|
|
item_date +
|
|
|
|
'"/><span class="itemsuivi_suppress" onclick="itemsuivi_suppress(\'' +
|
|
|
|
itemsuivi_id +
|
|
|
|
'\')"><img width="10" height="9" border="0" title="" alt="supprimer cet item" src="/ScoDoc/static/icons/delete_small_img.png"/></span>';
|
|
|
|
|
|
|
|
var h = sel_mois;
|
|
|
|
// situation
|
2024-09-09 16:21:51 +02:00
|
|
|
h += `<div class="itemsituation editable"
|
|
|
|
data-type="textarea"
|
|
|
|
data-url="${SCO_URL}../api/etudiant/itemsuivi/${itemsuivi_id}/set_situation"
|
|
|
|
data-placeholder="<em>décrire situation...</em>"
|
|
|
|
data-object="'${itemsuivi_id}'">${situation}</div>`;
|
2023-09-21 10:24:09 +02:00
|
|
|
// tags:
|
|
|
|
h +=
|
2024-09-09 16:21:51 +02:00
|
|
|
`<div class="itemsuivi_tag_edit">
|
|
|
|
<textarea class="itemsuivi_tag_editor"
|
|
|
|
data-itemsuivi_id="${itemsuivi_id}"
|
|
|
|
>${tags}</textarea>
|
|
|
|
</div>`;
|
2023-09-21 10:24:09 +02:00
|
|
|
|
|
|
|
var nodes = $($.parseHTML('<li class="itemsuivi">' + h + "</li>"));
|
|
|
|
var dp = nodes.find(".itemsuividatepicker");
|
|
|
|
dp.blur(function (e) {
|
|
|
|
var date = this.value;
|
2024-09-09 16:21:51 +02:00
|
|
|
if (date) {
|
|
|
|
$.post(`${SCO_URL}../api/etudiant/itemsuivi/${itemsuivi_id}/set_date`, {
|
|
|
|
date_dmy: date,
|
|
|
|
});
|
|
|
|
}
|
2023-09-21 10:24:09 +02:00
|
|
|
});
|
|
|
|
dp.datepicker({
|
|
|
|
onSelect: function (date, instance) {
|
2024-09-09 16:21:51 +02:00
|
|
|
if (date) {
|
|
|
|
$.post(`${SCO_URL}../api/etudiant/itemsuivi/${itemsuivi_id}/set_date`, {
|
|
|
|
date_dmy: date,
|
|
|
|
});
|
|
|
|
}
|
2023-09-21 10:24:09 +02:00
|
|
|
},
|
|
|
|
showOn: "button",
|
|
|
|
buttonImage: "/ScoDoc/static/icons/calendar_img.png",
|
|
|
|
buttonImageOnly: true,
|
|
|
|
dateFormat: "dd/mm/yy",
|
|
|
|
duration: "fast",
|
|
|
|
disabled: readonly,
|
|
|
|
});
|
|
|
|
dp.datepicker(
|
|
|
|
"option",
|
|
|
|
$.extend({ showMonthAfterYear: false }, $.datepicker.regional["fr"])
|
|
|
|
);
|
|
|
|
|
|
|
|
if (readonly) {
|
|
|
|
// show tags read-only
|
|
|
|
readOnlyTags(nodes.find(".itemsuivi_tag_editor"));
|
|
|
|
} else {
|
|
|
|
// bind tag editor
|
|
|
|
nodes.find(".itemsuivi_tag_editor").tagEditor({
|
|
|
|
initialTags: "",
|
|
|
|
placeholder: "Tags...",
|
|
|
|
onChange: function (field, editor, tags) {
|
2024-09-09 16:21:51 +02:00
|
|
|
let itemsuivi_id = field.data("itemsuivi_id");
|
|
|
|
$.post(`${SCO_URL}../api/etudiant/itemsuivi/${itemsuivi_id}/tag`, {
|
2023-09-21 10:24:09 +02:00
|
|
|
itemsuivi_id: itemsuivi_id,
|
|
|
|
taglist: tags.join(),
|
2021-06-21 18:46:35 +02:00
|
|
|
});
|
2023-09-21 10:24:09 +02:00
|
|
|
},
|
|
|
|
autocomplete: {
|
|
|
|
delay: 200, // ms before suggest
|
|
|
|
position: { collision: "flip" }, // automatic menu position up/down
|
|
|
|
source: "itemsuivi_tag_search",
|
|
|
|
},
|
|
|
|
});
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-09-21 10:24:09 +02:00
|
|
|
// bind inplace editor
|
|
|
|
nodes.find("div.itemsituation").jinplace();
|
|
|
|
}
|
2021-06-21 18:46:35 +02:00
|
|
|
|
2023-09-21 10:24:09 +02:00
|
|
|
return nodes;
|
|
|
|
}
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
function Date2DMY(date) {
|
2023-09-21 10:24:09 +02:00
|
|
|
var year = date.getFullYear();
|
2021-06-21 18:46:35 +02:00
|
|
|
|
2023-09-21 10:24:09 +02:00
|
|
|
var month = (1 + date.getMonth()).toString();
|
|
|
|
month = month.length > 1 ? month : "0" + month;
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-09-21 10:24:09 +02:00
|
|
|
var day = date.getDate().toString();
|
|
|
|
day = day.length > 1 ? day : "0" + day;
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-09-21 10:24:09 +02:00
|
|
|
return day + "/" + month + "/" + year;
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
|
|
|
|
2024-09-09 16:21:51 +02:00
|
|
|
async function itemsuivi_suppress(itemsuivi_id) {
|
|
|
|
const deleteUrl = `${SCO_URL}../api/etudiant/itemsuivi/${itemsuivi_id}/delete`;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await fetch(deleteUrl, {
|
|
|
|
method: 'POST'
|
|
|
|
});
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
// Clear items and rebuild:
|
|
|
|
$("ul.listdebouches li.itemsuivi").remove();
|
|
|
|
display_itemsuivis(0);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error deleting itemsuivi:', error);
|
|
|
|
}
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|