Commit 42e579c2781a3d298b28cd0e3639c48bde82eebc
1 parent
bcc8215a
Exists in
master
and in
3 other branches
bugfixes dates
Showing
4 changed files
with
57 additions
and
17 deletions
Show diff stats
src/Controller/AppController.php
... | ... | @@ -285,6 +285,7 @@ class AppController extends Controller { |
285 | 285 | case 'delete' : |
286 | 286 | $subject = "Suppression d'un matériel"; |
287 | 287 | $msg = "$acteur a supprimé le matériel $nom_materiel"; |
288 | +// if ($materiel->description != "") $msg .= "\n\nDescription :\n\n". $materiel->description; | |
288 | 289 | break; |
289 | 290 | case 'statusValidated' : |
290 | 291 | $subject = "Validation d'un matériel"; | ... | ... |
src/Model/Table/MaterielsTable.php
... | ... | @@ -192,7 +192,7 @@ class MaterielsTable extends AppTable { |
192 | 192 | 'message' => 'Ce champ contient des caractères interdits', |
193 | 193 | 'provider' => 'table' |
194 | 194 | ]); |
195 | - $validator->allowEmpty('nom_responsable')->add('nom_responsable', 'valid', [ | |
195 | + $validator->notEmpty('nom_responsable')->add('nom_responsable', 'valid', [ | |
196 | 196 | 'rule' => 'check_string', |
197 | 197 | 'message' => 'Ce champ contient des caractères interdits', |
198 | 198 | 'provider' => 'table' | ... | ... |
src/Template/Materiels/edit.ctp
... | ... | @@ -459,14 +459,18 @@ $(document).ready(function () { |
459 | 459 | * Event Mail change |
460 | 460 | */ |
461 | 461 | $("#nom-responsable").bind("change", function(event) { |
462 | - var url = document.URL; | |
463 | - var reg = new RegExp("(materiels).*$", "g"); | |
464 | - var emailUrl = url.replace(reg, "Users/getLdapEmail/"); | |
465 | - $.ajax({ | |
466 | - url: emailUrl + $("#nom-responsable").val() | |
467 | - }).done(function(data) { | |
468 | - $("#email-responsable").val(data) | |
469 | - }); | |
462 | + if ($("#nom-responsable").val() == "") { | |
463 | + $("#email-responsable").val(""); | |
464 | + } else { | |
465 | + var url = document.URL; | |
466 | + var reg = new RegExp("(materiels).*$", "g"); | |
467 | + var emailUrl = url.replace(reg, "Users/getLdapEmail/"); | |
468 | + $.ajax({ | |
469 | + url: emailUrl + $("#nom-responsable").val() | |
470 | + }).done(function(data) { | |
471 | + $("#email-responsable").val(data) | |
472 | + }); | |
473 | + } | |
470 | 474 | }); |
471 | 475 | |
472 | 476 | |
... | ... | @@ -474,9 +478,11 @@ $(document).ready(function () { |
474 | 478 | * Event calcul date fin de garantie |
475 | 479 | */ |
476 | 480 | /* On formatte COMME IL FAUT les dates des formulaires */ |
477 | - $("#date-acquisition")[0].value = $("#date-acquisition")[0].value.replace(/\//g, "-"); | |
478 | - $("#date-reception")[0].value = $("#date-reception")[0].value.replace(/\//g, "-"); | |
479 | - $("#date-fin-garantie")[0].value = $("#date-fin-garantie")[0].value.replace(/\//g, "-"); | |
481 | + $('.datepicker').each(function(){ | |
482 | + this.value = this.value.replace(/\//g, "-"); | |
483 | + this.value = twoToFourth(this.value); | |
484 | + }); | |
485 | + | |
480 | 486 | |
481 | 487 | /* Puis si nécessaire on update la date de fin de gurantie au chargement de la page */ |
482 | 488 | if ($("#date-fin-garantie")[0].value != "") dateUpdate(); |
... | ... | @@ -494,18 +500,39 @@ $(document).ready(function () { |
494 | 500 | s1 = $("#date-acquisition")[0].value; |
495 | 501 | s2 = $("#date-reception")[0].value; |
496 | 502 | s3 = $("#date-fin-garantie")[0].value; |
497 | - if (!checkDate(s1) || !checkDate(s2) || !checkDate(s3)) { | |
498 | - alert("Les dates doivent être de la forme dd-mm-YYYY"); | |
499 | - event.preventDefault(); | |
500 | - } | |
503 | +// if () { | |
504 | +// alert("Les dates doivent être de la forme dd-mm-YYYY"); | |
505 | +// event.preventDefault(); | |
506 | +// } | |
507 | + | |
508 | + $('.datepicker').each(function(){ | |
509 | + if(this.value != "") { | |
510 | + console.log(this.value); | |
511 | + if(!checkDate(this.value)){ | |
512 | + alert("Les dates doivent être de la forme dd-mm-YYYY"); | |
513 | + event.preventDefault(); | |
514 | + } | |
515 | + } | |
516 | + }); | |
517 | + | |
501 | 518 | d1 = toDate($("#date-acquisition")[0].value); /* Date de la commande */ |
502 | 519 | d2 = toDate($("#date-reception")[0].value); /* Date de réception */ |
520 | + d3 = toDate($("#date-fin-garantie")[0].value); /* Date fin de garantie */ | |
521 | + | |
503 | 522 | if($("#date-reception")[0].value != undefined){ |
504 | 523 | if(d1 > d2) { |
505 | 524 | alert("Les dates ne correspondent pas, la date de réception doit être supérieure à la date de commande."); |
506 | 525 | event.preventDefault(); |
507 | 526 | } |
508 | 527 | } |
528 | + | |
529 | + if($("#date-reception")[0].value != undefined){ | |
530 | + if(d2 > d3) { | |
531 | + alert("Les dates ne correspondent pas, la date de fin de garantie doit être supérieure à la date de réception."); | |
532 | + event.preventDefault(); | |
533 | + } | |
534 | + } | |
535 | + | |
509 | 536 | }); |
510 | 537 | }); |
511 | 538 | |
... | ... | @@ -517,6 +544,18 @@ function checkDate(str) { |
517 | 544 | } |
518 | 545 | |
519 | 546 | /** |
547 | + * Fonction qui passe l'années de deux à quatres chiffres | |
548 | + */ | |
549 | +function twoToFourth(str) { | |
550 | + if (str.match(/^(\d{1,2})-(\d{1,2})-(\d{2})$/)) { | |
551 | + tabStr = str.split("-"); | |
552 | + tabStr[2] = "20"+tabStr[2]; | |
553 | + str = tabStr[0]+tabStr[1]+tabStr[2]; | |
554 | + } | |
555 | + return str; | |
556 | +} | |
557 | + | |
558 | +/** | |
520 | 559 | * Fonction de mise à jour de la date de fin de guarantie |
521 | 560 | */ |
522 | 561 | function dateUpdate() { | ... | ... |
src/Template/Materiels/view.ctp