2020-09-26 16:19:37 +02:00
// Formulaire saisie des notes
2021-06-21 18:46:35 +02:00
$ ( ) . ready ( function ( ) {
2020-09-26 16:19:37 +02:00
$ ( "#formnotes .note" ) . bind ( "blur" , valid _note ) ;
$ ( "#formnotes input" ) . bind ( "paste" , paste _text ) ;
2021-06-21 18:46:35 +02:00
2020-09-26 16:19:37 +02:00
} ) ;
function is _valid _note ( v ) {
if ( ! v )
2021-06-21 18:46:35 +02:00
return true ;
2020-09-26 16:19:37 +02:00
var note _min = parseFloat ( $ ( "#eval_note_min" ) . text ( ) ) ;
var note _max = parseFloat ( $ ( "#eval_note_max" ) . text ( ) ) ;
2021-06-21 18:46:35 +02:00
if ( ! v . match ( "^-?[0-9.]*$" ) ) {
return ( v == "ABS" ) || ( v == "EXC" ) || ( v == "SUPR" ) || ( v == "ATT" ) || ( v == "DEM" ) ;
2020-09-26 16:19:37 +02:00
} else {
var x = parseFloat ( v ) ;
return ( x >= note _min ) && ( x <= note _max ) ;
}
}
function valid _note ( e ) {
var v = this . value . trim ( ) . toUpperCase ( ) . replace ( "," , "." ) ;
if ( is _valid _note ( v ) ) {
if ( v && ( v != $ ( this ) . attr ( 'data-last-saved-value' ) ) ) {
this . className = "note_valid_new" ;
var etudid = $ ( this ) . attr ( 'data-etudid' ) ;
save _note ( this , v , etudid ) ;
}
} else {
/* Saisie invalide */
this . className = "note_invalid" ;
}
}
function save _note ( elem , v , etudid ) {
var evaluation _id = $ ( "#formnotes_evaluation_id" ) . attr ( "value" ) ;
var formsemestre _id = $ ( "#formnotes_formsemestre_id" ) . attr ( "value" ) ;
$ ( '#sco_msg' ) . html ( "en cours..." ) . show ( ) ;
2021-06-25 18:25:46 +02:00
$ . post ( SCO _URL + '/Notes/save_note' ,
2021-06-21 18:46:35 +02:00
{
'etudid' : etudid ,
'evaluation_id' : evaluation _id ,
'value' : v ,
'comment' : $ ( "#formnotes_comment" ) . attr ( "value" )
} ,
function ( result ) {
sco _message ( "enregistré" ) ;
elem . className = "note_saved" ;
if ( result [ 'nbchanged' ] > 0 ) {
// il y avait une decision de jury ?
if ( result . existing _decisions [ 0 ] == etudid ) {
if ( v != $ ( elem ) . attr ( 'data-orig-value' ) ) {
$ ( "#jurylink_" + etudid ) . html ( '<a href="formsemestre_validation_etud_form?formsemestre_id=' + formsemestre _id + '&etudid=' + etudid + '">mettre à jour décision de jury</a>' ) ;
} else {
$ ( "#jurylink_" + etudid ) . html ( '' ) ;
2020-09-26 16:19:37 +02:00
}
}
2021-06-21 18:46:35 +02:00
// mise a jour menu historique
if ( result [ 'history_menu' ] ) {
$ ( "#hist_" + etudid ) . html ( result [ 'history_menu' ] ) ;
}
2020-09-26 16:19:37 +02:00
}
2021-06-21 18:46:35 +02:00
$ ( elem ) . attr ( 'data-last-saved-value' , v )
}
) ;
2020-09-26 16:19:37 +02:00
}
function change _history ( e ) {
var opt = e . selectedOptions [ 0 ] ;
var val = $ ( opt ) . attr ( "data-note" ) ;
var etudid = $ ( e ) . attr ( 'data-etudid' ) ;
// le input associé a ce menu:
var input _elem = e . parentElement . parentElement . parentElement . childNodes [ 0 ] ;
input _elem . value = val ;
save _note ( input _elem , val , etudid ) ;
}
// Contribution S.L.: copier/coller des notes
function paste _text ( e ) {
var event = e . originalEvent ;
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
var clipb = e . originalEvent . clipboardData ;
var data = clipb . getData ( 'Text' ) ;
var list = data . split ( /\r\n|\r|\n|\t| /g ) ;
var currentInput = event . currentTarget ;
2021-06-21 18:46:35 +02:00
for ( var i = 0 ; i < list . length ; i ++ ) {
currentInput . value = list [ i ] ;
var evt = document . createEvent ( "HTMLEvents" ) ;
evt . initEvent ( "blur" , false , true ) ;
currentInput . dispatchEvent ( evt ) ;
var sibbling = currentInput . parentElement . parentElement . nextElementSibling ;
while ( sibbling && sibbling . style . display == "none" ) {
2020-09-26 16:19:37 +02:00
sibbling = sibbling . nextElementSibling ;
}
2021-06-21 18:46:35 +02:00
if ( sibbling ) {
currentInput = sibbling . querySelector ( "input" ) ;
if ( ! currentInput ) {
return ;
}
} else {
return ;
}
2020-09-26 16:19:37 +02:00
}
2021-06-21 18:46:35 +02:00
}