platypuce.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. function checkPromoId(promoid)
  2. {
  3. return promoid.match(/A[1-5]/) != null;
  4. }
  5. function editRow() {
  6. var row = $(this).parent().parent();
  7. var rang = $(row.children()[0]);
  8. var promo = $(row.children()[1]);
  9. var rangValeur = rang.html();
  10. var promoValeur = $(promo[0]).attr("class");
  11. var promos = $("#promo").children();
  12. var str = '<select class="tempPromos">';
  13. var selected = "";
  14. rang.html('<input type="number" value="'+rangValeur+'" size="2" style="width:35px" />');
  15. $(promo[0]).removeClass(promoValeur);
  16. for(var i = 0; i < promos.length; i++)
  17. {
  18. if (promos[i].value === promoValeur)
  19. {
  20. selected = "selected";
  21. }
  22. else
  23. {
  24. selected = "";
  25. }
  26. str += '<option value="'+promos[i].value+'" '+selected+'>'+promos[i].text+'</option>';
  27. }
  28. str += "</select>";
  29. promo.html(str);
  30. $(this).addClass("fa-check");
  31. $(this).removeClass("fa-pencil");
  32. $(this).off("click");
  33. $(this).on("click", function () {
  34. rangValeur = $(rang.children()[0]).val();
  35. rang.html(rangValeur);
  36. promoValeur = promo.children().val();
  37. promo.addClass(promoValeur);
  38. var promoName = "";
  39. for(var i = 0; i < promos.length; i++)
  40. {
  41. if (promos[i].value === promoValeur)
  42. {
  43. promoName = promos[i].text;
  44. }
  45. }
  46. promo.html(promoName);
  47. $(this).addClass("fa-pencil");
  48. $(this).removeClass("fa-check");
  49. // Insert AJAX request here
  50. $(this).off("click");
  51. $(this).on("click", editRow);
  52. });
  53. }
  54. $('.fa-pencil').on("click", editRow);
  55. $('#addForm').submit(function(e) {
  56. e.preventDefault();
  57. var data = new FormData();
  58. switch ($("title").html())
  59. {
  60. case "Documents":
  61. data.append("document", $("#file")[0].files[0]);
  62. data.append("promo", $("#promo").val());
  63. data.append("rang", $("#rang").val());
  64. data.append("libelle", $("#libelle").val());
  65. $.ajax({
  66. method: "POST",
  67. url: "document",
  68. data: data,
  69. dataType: 'json',
  70. processData: false,
  71. contentType: false,
  72. complete: function (result) {
  73. }
  74. });
  75. break;
  76. case "Promotions":
  77. if(checkPromoId($("#id").val()))
  78. {
  79. data.append("id", $("#id").val());
  80. data.append("libelle", $("#libelle").val());
  81. $.ajax({
  82. method: "POST",
  83. url: "promo",
  84. data: data,
  85. processData: false,
  86. contentType: false,
  87. complete: function (result) {
  88. console.log(result);
  89. }
  90. });
  91. }
  92. else
  93. {
  94. var block = $(".form-group:first-child");
  95. block.addClass("has-error");
  96. block.html(block.html()+'<span id="helpBlock2" class="help-block">Votre identifiant doit contenir "A" suivi de l\'année correspondant à la promotion.</span>')
  97. }
  98. break;
  99. }
  100. });