ScoDoc/app/static/js/scodoc.js

136 lines
4.0 KiB
JavaScript
Raw Normal View History

2020-09-26 16:19:37 +02:00
// JS for all ScoDoc pages (using jQuery UI)
2021-02-16 22:07:56 +01:00
$(function () {
2020-09-26 16:19:37 +02:00
// Autocomplete recherche etudiants par nom
$(".in-expnom").autocomplete(
2020-09-26 16:19:37 +02:00
{
delay: 300, // wait 300ms before suggestions
minLength: 2, // min nb of chars before suggest
position: { collision: 'flip' }, // automatic menu position up/down
source: SCO_URL + "/search_etud_by_name",
2021-02-16 22:07:56 +01:00
select: function (event, ui) {
$(".in-expnom").val(ui.item.value);
2021-02-16 22:07:56 +01:00
$("#form-chercheetud").submit();
2020-09-26 16:19:37 +02:00
}
2021-02-16 22:07:56 +01:00
});
2020-09-26 16:19:37 +02:00
// Date picker
$(".datepicker").datepicker({
2021-02-16 22:07:56 +01:00
showOn: 'button',
buttonImage: '/ScoDoc/static/icons/calendar_img.png',
2020-09-26 16:19:37 +02:00
buttonImageOnly: true,
2021-02-16 22:07:56 +01:00
dateFormat: 'dd/mm/yy',
duration: 'fast',
2020-09-26 16:19:37 +02:00
});
2021-02-16 22:07:56 +01:00
$('.datepicker').datepicker('option', $.extend({ showMonthAfterYear: false },
$.datepicker.regional['fr']));
2020-09-26 16:19:37 +02:00
/* Barre menu */
2021-02-16 22:07:56 +01:00
var sco_menu_position = { my: "left top", at: "left bottom" };
2020-09-26 16:19:37 +02:00
$("#sco_menu").menu({
position: sco_menu_position,
2021-02-16 22:07:56 +01:00
blur: function () {
2020-09-26 16:19:37 +02:00
$(this).menu("option", "position", sco_menu_position);
},
2021-02-16 22:07:56 +01:00
focus: function (e, ui) {
2020-09-26 16:19:37 +02:00
if ($("#sco_menu").get(0) !== $(ui).get(0).item.parent().get(0)) {
2021-02-16 22:07:56 +01:00
$(this).menu("option", "position", { my: "left top", at: "right top" });
2020-09-26 16:19:37 +02:00
}
}
2021-02-16 22:07:56 +01:00
}).mouseleave(function (x, y) {
$("#sco_menu").menu('collapseAll');
});
2020-09-26 16:19:37 +02:00
$("#sco_menu > li > a > span").switchClass("ui-icon-carat-1-e", "ui-icon-carat-1-s");
/* Les menus isoles dropdown */
$(".sco_dropdown_menu").menu({
position: sco_menu_position
2021-02-16 22:07:56 +01:00
}).mouseleave(function (x, y) {
$(".sco_dropdown_menu").menu('collapseAll');
2020-09-26 16:19:37 +02:00
}
2021-02-16 22:07:56 +01:00
);
2020-09-26 16:19:37 +02:00
$(".sco_dropdown_menu > li > a > span").switchClass("ui-icon-carat-1-e", "ui-icon-carat-1-s");
2021-02-16 22:07:56 +01:00
/* up-to-date status */
var update_div = document.getElementById("update_warning");
if (update_div) {
fetch('install_info').then(
response => response.text()
2022-03-20 23:12:30 +01:00
).then(text => {
update_div.innerHTML = text;
if (text) {
update_div.style.display = "block";
}
});
}
2020-09-26 16:19:37 +02:00
});
// Affiche un message transitoire
function sco_message(msg, color) {
if (color === undefined) {
color = "green";
}
$('#sco_msg').html(msg).show();
if (color) {
$('#sco_msg').css('color', color);
}
setTimeout(
2021-02-16 22:07:56 +01:00
function () {
2020-09-26 16:19:37 +02:00
$('#sco_msg').fadeOut(
'slow',
2021-02-16 22:07:56 +01:00
function () {
2020-09-26 16:19:37 +02:00
$('#sco_msg').html('');
}
2021-02-16 22:07:56 +01:00
);
},
2020-09-26 16:19:37 +02:00
2000 // <-- duree affichage en milliseconds
);
}
function get_query_args() {
var s = window.location.search; // eg "?x=1&y=2"
var vars = {};
2021-02-16 22:07:56 +01:00
s.replace(
/[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
function (m, key, value) { // callback
vars[key] = value !== undefined ? value : '';
}
2020-09-26 16:19:37 +02:00
);
return vars;
}
// Tables (gen_tables)
2021-02-16 22:07:56 +01:00
$(function () {
var table_options = {
2021-02-16 22:07:56 +01:00
"paging": false,
"searching": false,
"info": false,
2020-09-26 16:19:37 +02:00
/* "autoWidth" : false, */
2021-02-16 22:07:56 +01:00
"fixedHeader": {
2020-09-26 16:19:37 +02:00
"header": true,
"footer": true
},
"orderCellsTop": true, // cellules ligne 1 pour tri
2021-02-16 22:07:56 +01:00
"aaSorting": [], // Prevent initial sorting
};
$('table.gt_table').DataTable(table_options);
table_options["searching"] = true;
$('table.gt_table_searchable').DataTable(table_options);
2020-09-26 16:19:37 +02:00
});
// Show tags (readonly)
function readOnlyTags(nodes) {
// nodes are textareas, hide them and create a span showing tags
for (var i = 0; i < nodes.length; i++) {
2021-02-16 22:07:56 +01:00
var node = $(nodes[i]);
node.hide();
var tags = nodes[i].value.split(',');
node.after('<span class="ro_tags"><span class="ro_tag">' + tags.join('</span><span class="ro_tag">') + '</span></span>');
2020-09-26 16:19:37 +02:00
}
}