Fix: autocomplete recherche etudiant

This commit is contained in:
Emmanuel Viennet 2021-02-16 22:07:56 +01:00
parent 96b22ac5ca
commit 5ffeae3e1f
2 changed files with 51 additions and 48 deletions

View File

@ -108,7 +108,7 @@ def search_etud_in_dept(
REQUEST=None, REQUEST=None,
): ):
"""Page recherche d'un etudiant """Page recherche d'un etudiant
expnom est un regexp sur le nom ou un code_nip expnom est un regexp sur le nom ou un code_nip ou un etudid
dest_url est la page sur laquelle on sera redirigé après choix dest_url est la page sur laquelle on sera redirigé après choix
parameters spécifie des arguments additionnels à passer à l'URL (en plus de etudid) parameters spécifie des arguments additionnels à passer à l'URL (en plus de etudid)
""" """
@ -134,8 +134,10 @@ def search_etud_in_dept(
etuds = search_etuds_infos(context, code_nip=expnom, REQUEST=REQUEST) etuds = search_etuds_infos(context, code_nip=expnom, REQUEST=REQUEST)
elif expnom: elif expnom:
etuds = search_etuds_infos(context, expnom=expnom, REQUEST=REQUEST) etuds = search_etuds_infos(context, expnom=expnom, REQUEST=REQUEST)
else: if expnom and not etuds:
etuds = [] etuds = context.getEtudInfo(filled=1, etudid=expnom, REQUEST=REQUEST)
if len(etuds) != 1:
etuds = []
if len(etuds) == 1: if len(etuds) == 1:
# va directement a la destination # va directement a la destination
return REQUEST.RESPONSE.redirect( return REQUEST.RESPONSE.redirect(
@ -268,14 +270,14 @@ def search_etud_by_name(context, term, REQUEST=None):
else: else:
r = ndb.SimpleDictFetch( r = ndb.SimpleDictFetch(
context, context,
"SELECT nom, prenom FROM identite WHERE nom LIKE %(beginning)s ORDER BY nom", "SELECT etudid, nom, prenom FROM identite WHERE nom LIKE %(beginning)s ORDER BY nom",
{"beginning": term + "%"}, {"beginning": term + "%"},
) )
data = [ data = [
{ {
"label": "%s %s" % (x["nom"], scolars.format_prenom(x["prenom"])), "label": "%s %s" % (x["nom"], scolars.format_prenom(x["prenom"])),
"value": x["nom"], "value": x["etudid"],
} }
for x in r for x in r
] ]

View File

@ -1,7 +1,7 @@
// JS for all ScoDoc pages (using jQuery UI) // JS for all ScoDoc pages (using jQuery UI)
$(function() { $(function () {
// Autocomplete recherche etudiants par nom // Autocomplete recherche etudiants par nom
$("#in-expnom").autocomplete( $("#in-expnom").autocomplete(
{ {
@ -9,49 +9,50 @@ $(function() {
minLength: 2, // min nb of chars before suggest minLength: 2, // min nb of chars before suggest
position: { collision: 'flip' }, // automatic menu position up/down position: { collision: 'flip' }, // automatic menu position up/down
source: "search_etud_by_name", source: "search_etud_by_name",
select: function(event, ui) { select: function (event, ui) {
$("#form-chercheetud").submit(); $("#in-expnom").val(ui.item.value);
$("#form-chercheetud").submit();
} }
}); });
// Date picker // Date picker
$(".datepicker").datepicker({ $(".datepicker").datepicker({
showOn: 'button', showOn: 'button',
buttonImage: '/ScoDoc/static/icons/calendar_img.png', buttonImage: '/ScoDoc/static/icons/calendar_img.png',
buttonImageOnly: true, buttonImageOnly: true,
dateFormat: 'dd/mm/yy', dateFormat: 'dd/mm/yy',
duration : 'fast', duration: 'fast',
}); });
$('.datepicker').datepicker('option', $.extend({showMonthAfterYear: false}, $('.datepicker').datepicker('option', $.extend({ showMonthAfterYear: false },
$.datepicker.regional['fr'])); $.datepicker.regional['fr']));
/* Barre menu */ /* Barre menu */
var sco_menu_position = {my: "left top", at: "left bottom"}; var sco_menu_position = { my: "left top", at: "left bottom" };
$("#sco_menu").menu({ $("#sco_menu").menu({
position: sco_menu_position, position: sco_menu_position,
blur: function() { blur: function () {
$(this).menu("option", "position", sco_menu_position); $(this).menu("option", "position", sco_menu_position);
}, },
focus: function(e, ui) { focus: function (e, ui) {
if ($("#sco_menu").get(0) !== $(ui).get(0).item.parent().get(0)) { if ($("#sco_menu").get(0) !== $(ui).get(0).item.parent().get(0)) {
$(this).menu("option", "position", {my: "left top", at: "right top"}); $(this).menu("option", "position", { my: "left top", at: "right top" });
} }
} }
}).mouseleave(function(x, y) { }).mouseleave(function (x, y) {
$( "#sco_menu" ).menu('collapseAll'); $("#sco_menu").menu('collapseAll');
}); });
$("#sco_menu > li > a > span").switchClass("ui-icon-carat-1-e", "ui-icon-carat-1-s"); $("#sco_menu > li > a > span").switchClass("ui-icon-carat-1-e", "ui-icon-carat-1-s");
/* Les menus isoles dropdown */ /* Les menus isoles dropdown */
$(".sco_dropdown_menu").menu({ $(".sco_dropdown_menu").menu({
position: sco_menu_position position: sco_menu_position
}).mouseleave(function(x, y) { }).mouseleave(function (x, y) {
$( ".sco_dropdown_menu" ).menu('collapseAll'); $(".sco_dropdown_menu").menu('collapseAll');
} }
); );
$(".sco_dropdown_menu > li > a > span").switchClass("ui-icon-carat-1-e", "ui-icon-carat-1-s"); $(".sco_dropdown_menu > li > a > span").switchClass("ui-icon-carat-1-e", "ui-icon-carat-1-s");
}); });
@ -65,14 +66,14 @@ function sco_message(msg, color) {
$('#sco_msg').css('color', color); $('#sco_msg').css('color', color);
} }
setTimeout( setTimeout(
function() { function () {
$('#sco_msg').fadeOut( $('#sco_msg').fadeOut(
'slow', 'slow',
function() { function () {
$('#sco_msg').html(''); $('#sco_msg').html('');
} }
); );
}, },
2000 // <-- duree affichage en milliseconds 2000 // <-- duree affichage en milliseconds
); );
} }
@ -81,30 +82,30 @@ function sco_message(msg, color) {
function get_query_args() { function get_query_args() {
var s = window.location.search; // eg "?x=1&y=2" var s = window.location.search; // eg "?x=1&y=2"
var vars = {}; var vars = {};
s.replace( s.replace(
/[?&]+([^=&]+)=?([^&]*)?/gi, // regexp /[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
function( m, key, value ) { // callback function (m, key, value) { // callback
vars[key] = value !== undefined ? value : ''; vars[key] = value !== undefined ? value : '';
} }
); );
return vars; return vars;
} }
// Tables (gen_tables) // Tables (gen_tables)
$(function() { $(function () {
$('table.gt_table').DataTable( { $('table.gt_table').DataTable({
"paging" : false, "paging": false,
"searching" : false, "searching": false,
"info" : false, "info": false,
/* "autoWidth" : false, */ /* "autoWidth" : false, */
"fixedHeader" : { "fixedHeader": {
"header": true, "header": true,
"footer": true "footer": true
}, },
"orderCellsTop": true, // cellules ligne 1 pour tri "orderCellsTop": true, // cellules ligne 1 pour tri
"aaSorting": [ ], // Prevent initial sorting "aaSorting": [], // Prevent initial sorting
} ); });
}); });
@ -112,9 +113,9 @@ $(function() {
function readOnlyTags(nodes) { function readOnlyTags(nodes) {
// nodes are textareas, hide them and create a span showing tags // nodes are textareas, hide them and create a span showing tags
for (var i = 0; i < nodes.length; i++) { for (var i = 0; i < nodes.length; i++) {
var node = $(nodes[i]); var node = $(nodes[i]);
node.hide(); node.hide();
var tags = nodes[i].value.split(','); 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>'); node.after('<span class="ro_tags"><span class="ro_tag">' + tags.join('</span><span class="ro_tag">') + '</span></span>');
} }
} }