1
0
forked from ScoDoc/ScoDoc
ScoDoc/app/static/js/etud_debouche.js

139 lines
4.9 KiB
JavaScript
Raw Normal View History

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 () {
2020-09-26 16:19:37 +02:00
display_itemsuivis(false);
});
function display_itemsuivis(active) {
var etudid = $('div#fichedebouche').data("etudid");
var readonly = $('div#fichedebouche').data('readonly'); // present ro interface
2021-06-21 18:46:35 +02:00
2020-09-26 16:19:37 +02:00
if (!readonly) {
2021-06-21 18:46:35 +02:00
$('#adddebouchelink').off("click").click(function (e) {
e.preventDefault();
$.post(SCO_URL + "/itemsuivi_create", { etudid: etudid, format: 'json' }).done(item_insert_new);
2021-06-21 18:46:35 +02:00
return false;
});
2020-09-26 16:19:37 +02:00
}
// add existing items
2021-06-21 18:46:35 +02:00
$.get(SCO_URL + "/itemsuivi_list_etud", { etudid: etudid, format: 'json' }, function (L) {
for (var i in L) {
item_insert(L[i]['itemsuivi_id'], L[i]['item_date'], L[i]['situation'], L[i]['tags'], readonly);
}
2020-09-26 16:19:37 +02:00
});
2021-06-21 18:46:35 +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) {
item_insert(it.itemsuivi_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) {
if (item_date === undefined)
item_date = Date2DMY(new Date());
if (situation === undefined)
situation = '';
if (tags === undefined)
tags = '';
2020-09-26 16:19:37 +02:00
var nodes = item_nodes(itemsuivi_id, item_date, situation, tags, readonly);
// insert just before last li:
if ($('ul.listdebouches li.adddebouche').length > 0) {
2021-06-21 18:46:35 +02:00
$('ul.listdebouches').children(':last').before(nodes);
2020-09-26 16:19:37 +02:00
} else {
2021-06-21 18:46:35 +02:00
// 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) {
// console.log('item_nodes: itemsuivi_id=' + itemsuivi_id);
2021-06-21 18:46:35 +02:00
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>';
2020-09-26 16:19:37 +02:00
var h = sel_mois;
// situation
h += '<div class="itemsituation editable" data-type="textarea" data-url="itemsuivi_set_situation" data-placeholder="<em>décrire situation...</em>" data-object="' + itemsuivi_id + '">' + situation + '</div>';
// tags:
h += '<div class="itemsuivi_tag_edit"><textarea class="itemsuivi_tag_editor">' + tags + '</textarea></div>';
2021-06-21 18:46:35 +02:00
var nodes = $($.parseHTML('<li class="itemsuivi">' + h + '</li>'));
2020-09-26 16:19:37 +02:00
var dp = nodes.find('.itemsuividatepicker');
2021-06-21 18:46:35 +02:00
dp.blur(function (e) {
var date = this.value;
// console.log('selected text: ' + date);
$.post(SCO_URL + "/itemsuivi_set_date", { item_date: date, itemsuivi_id: itemsuivi_id });
2020-09-26 16:19:37 +02:00
});
dp.datepicker({
2021-06-21 18:46:35 +02:00
onSelect: function (date, instance) {
// console.log('selected: ' + date + 'for itemsuivi_id ' + itemsuivi_id);
$.post(SCO_URL + "/itemsuivi_set_date", { item_date: date, itemsuivi_id: itemsuivi_id });
},
showOn: 'button',
buttonImage: '/ScoDoc/static/icons/calendar_img.png',
2020-09-26 16:19:37 +02:00
buttonImageOnly: true,
2021-06-21 18:46:35 +02:00
dateFormat: 'dd/mm/yy',
duration: 'fast',
disabled: readonly
2020-09-26 16:19:37 +02:00
});
2021-06-21 18:46:35 +02:00
dp.datepicker('option', $.extend({ showMonthAfterYear: false },
$.datepicker.regional['fr']));
2020-09-26 16:19:37 +02:00
if (readonly) {
2021-06-21 18:46:35 +02:00
// show tags read-only
readOnlyTags(nodes.find('.itemsuivi_tag_editor'));
2020-09-26 16:19:37 +02:00
}
else {
2021-06-21 18:46:35 +02:00
// bind tag editor
nodes.find('.itemsuivi_tag_editor').tagEditor({
initialTags: '',
2020-09-26 16:19:37 +02:00
placeholder: 'Tags...',
2021-06-21 18:46:35 +02:00
onChange: function (field, editor, tags) {
$.post('itemsuivi_tag_set',
{
itemsuivi_id: itemsuivi_id,
taglist: tags.join()
});
2020-09-26 16:19:37 +02:00
},
autocomplete: {
2021-06-21 18:46:35 +02:00
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
},
2021-06-21 18:46:35 +02:00
});
2020-09-26 16:19:37 +02:00
2021-06-21 18:46:35 +02:00
// bind inplace editor
nodes.find('div.itemsituation').jinplace();
2020-09-26 16:19:37 +02:00
}
2021-06-21 18:46:35 +02:00
2020-09-26 16:19:37 +02:00
return nodes;
};
function Date2DMY(date) {
2021-06-21 18:46:35 +02:00
var year = date.getFullYear();
var month = (1 + date.getMonth()).toString();
month = month.length > 1 ? month : '0' + month;
2020-09-26 16:19:37 +02:00
2021-06-21 18:46:35 +02:00
var day = date.getDate().toString();
day = day.length > 1 ? day : '0' + day;
2020-09-26 16:19:37 +02:00
2021-06-21 18:46:35 +02:00
return day + '/' + month + '/' + year;
2020-09-26 16:19:37 +02:00
}
function itemsuivi_suppress(itemsuivi_id) {
2021-06-21 18:46:35 +02:00
$.post(SCO_URL + "/itemsuivi_suppress", { itemsuivi_id: itemsuivi_id });
2020-09-26 16:19:37 +02:00
// Clear items and rebuild:
$("ul.listdebouches li.itemsuivi").remove();
display_itemsuivis(0);
}