Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var t;//data table
- $("#crea-form").submit(function (event) {
- // désactive bouton création
- disableCreaButton(true);
- // empêche le comportement par défaut du form càd l'envoi direct du formulaire
- event.preventDefault();
- creaViaAjax();
- });
- $("#rechid-form").submit(function (event) {
- // désactive bouton recherche
- disableSearchButton(true);
- // empêche le comportement par défaut du form càd l'envoi direct du formulaire
- event.preventDefault();
- rechViaAjaxId();
- });
- $('#edit-form').submit(function (event) {
- event.preventDefault();
- var cours = {};
- cours["idcours"] = $("#id").val();
- cours["matiere"] = $("#matiere").val();
- cours["heures"] = $("#heures").val();
- sauveViaAjax(cours);
- document.location.reload(true);
- });
- var ficlangue = $("#container").data("langue");
- t = $('#tabcours').DataTable({
- "language": {
- // "url": "https://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/French.json"
- "url": ficlangue
- },
- columns: [
- {data: "idcours"},
- {data: "matiere"},
- {data: "heures"}
- ]
- }); //pour dataTables
- $('#tabcours tbody').on('click', 'tr', function () {
- if ($(this).hasClass('selected')) {
- $(this).removeClass('selected');
- } else {
- t.$('tr.selected').removeClass('selected');
- $(this).addClass('selected');
- var data = t.row('.selected').data().idcours;
- $('#id').val(data);
- data = t.row('.selected').data().matiere;
- $('#matiere').val(data);
- data = t.row('.selected').data().heures;
- $('#heures').val(data);
- }
- });
- function sauveViaAjax(cours) {
- $.ajax({
- type: "POST",
- contentType: "application/json",
- url: "../../coursrest/updatecours",
- data: JSON.stringify(cours),
- dataType: 'json',
- timeout: 100000,
- success : function (data) {
- alert("sauvegarde effectuée");
- },
- error : function (e) {
- alert("erreur de sauvegarde : " + e);
- }
- });
- }
- function rechAllViaAjax() {
- $.ajax({
- type: "POST",
- contentType: "application/json",
- url: "../../coursrest/touscours",
- dataType: 'json',
- timeout: 100000,
- success : function (data) {
- console.log("SUCCESS: ", data);
- displayrechall(data);
- },
- error: function (e) {
- alert("aucun cours trouvé");
- $('#result').html("");
- }
- });
- }
- function rechViaAjaxId() {
- var rech = {};
- rech["idcours"] = $("#idgest").val();
- $.ajax({
- type: "POST",
- contentType: "application/json",
- url: "../../coursrest/rechid",
- data: JSON.stringify(rech),
- dataType: 'json',
- timeout: 100000,
- success: function (data) {
- console.log("SUCCESS: ", data);
- displayRechId(data);
- disableSearchButton(false);
- },
- error: function (e) {
- alert("aucun cours trouvé");
- $('#resultcrea').html("");
- disableSearchButton(false);
- }
- });
- }
- function creaViaAjax() {
- var cours = {};
- cours["matiere"] = $("#matiere").val();
- cours["heures"] = $("#heures").val();
- $.ajax({
- type: "POST",
- contentType: "application/json",
- url: "../../coursrest/creacours",
- data: JSON.stringify(cours),
- dataType: 'json',
- timeout: 100000,
- success : function (data) {
- alert("cours créé");
- console.log("SUCCESS: ", data);
- displaycrea(data);
- disableCreaButton(false);
- },
- error: function (e) {
- alert("erreur de création : " + e);
- $('#resultcrea').html("");
- disableCreaButton(false);
- }
- });
- }
- function disableSearchButton(flag) {
- $("#btn-rech").prop("disabled", flag);
- }
- function disableCreaButton(flag) {
- $("#btn-crea").prop("disabled", flag);
- }
- function displaycrea(data) {
- var htmlrow = "";
- htmlrow += "<tr>" +
- "<td>" + data.idcours + "</td>" +
- "<td>" + data.matiere + "</td>" +
- "<td>" + data.heures + "</td>" +
- "</tr>";
- $('#resultcrea').html(htmlrow);
- }
- function displayRechId(data) {
- $('#id').val(data.idcours);
- $('#matiere').val(data.matiere);
- $('#heures').val(data.heures);
- }
- function displayrechall(data) {
- t.clear().draw(); //pour dataTables-efface valeurs actuelles
- console.log("debut");
- $.each(data, function (cle, valeur) {
- t.row.add(valeur).draw(false);
- console.log(valeur);
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement