gmarche/public/js/script.js

196 lines
5.8 KiB
JavaScript

// Add Record
function addRecord() {
// get values
var produit = $("#produit").val();
var vendeur = $("#vendeur").val();
var cle_pub = $("#cle_pub").val();
var prix = $("#prix").val();
// Add record
$.post("ajax/addRecord.php", {
produit: produit,
vendeur: vendeur,
cle_pub: cle_pub,
prix: prix
}, function (data, status) {
// close the popup
$("#add_new_record_modal").modal("hide");
// read records again
readRecords();
// clear fields from the popup
$("#produit").val("");
$("#vendeur").val("");
$("#cle_pub").val("");
$("#prix").val("");
});
}
function addRecord2() {
// get values
var produit_r = $("#produit_r").val();
var vendeur_r = $("#vendeur_r").val();
var cle_pub_r = $("#cle_pub_r").val();
var prix_r = $("#prix_r").val();
// Add record
$.post("ajax/addRecord2.php", {
produit_r: produit_r,
vendeur_r: vendeur_r,
cle_pub_r: cle_pub_r,
prix_r: prix_r
}, function (data, status) {
// close the popup
$("#add_new_record_modal2").modal("hide");
// read records again
readRecords2();
// clear fields from the popup
$("#produit_r").val("");
$("#vendeur_r").val("");
$("#cle_pub_r").val("");
$("#prix_r").val("");
});
}
// READ records
function readRecords(antenne_slug) {
$.get("/ajax/readRecords.php", {
antenne_slug: antenne_slug
}, function (data, status) {
$(".records_content").html(data);
});
}
// READ records2
function readRecords2() {
$.get("ajax/readRecords2.php", {}, function (data, status) {
$(".records_content2").html(data);
});
}
function DeleteProduits(id, antenne_slug) {
$("#hidden_antenne_slug").val(antenne_slug);
var conf = confirm("Etes-vous sûr(e) de vouloir supprimer ce bien ou service ?");
if (conf == true) {
$.post("/ajax/deleteProduits.php", {
id: id
},
function (data, status) {
// Rechargement de la liste Biens/services
readRecords(antenne_slug);
}
);
}
}
function DeleteRecherches(id) {
var conf = confirm("Etes-vous sûr(e) de vouloir supprimer ce bien ou service ?");
if (conf == true) {
$.post("ajax/deleteRecherches.php", {
id_r: id
},
function (data, status) {
// reload Recherches by using readRecords2();
readRecords2();
}
);
}
}
function GetProduitsDetails(id, antenne_slug) {
// Add Products ID to the hidden field for future usage
$("#hidden_user_id").val(id);
$("#hidden_antenne_slug").val(antenne_slug);
$.post("/ajax/readProduitsDetails.php", {
id: id
},
function (data, status) {
var produit = JSON.parse(data);
// Assign existing values to the modal popup fields
$("#update_produit").val(produit.name);
$("#update_vendeur").val(produit.username);
$("#update_quantite").val(produit.quantite);
$("#update_prix").val(produit.prix);
}
);
// Open modal popup
$("#update_user_modal").modal("show");
}
function GetRecherchesDetails(id) {
// Add Recherches ID to the hidden field for future usage
$("#hidden_user_id_r").val(id);
$.post("ajax/readRecherchesDetails.php", {
id_r: id
},
function (data, status) {
// PARSE json data
var produit = JSON.parse(data);
// Assign existing values to the modal popup fields
$("#update_produit_r").val(produit.produit);
$("#update_vendeur_r").val(produit.vendeur);
$("#update_cle_pub_r").val(produit.cle_pub);
$("#update_prix_r").val(produit.prix);
}
);
// Open modal popup
$("#update_user_modal2").modal("show");
}
function UpdateProduitsDetails() {
// get values
var produit = $("#update_produit").val();
//var vendeur = $("#update_vendeur").val();
var quantite = $("#update_quantite").val();
var prix = $("#update_prix").val();
// get hidden field value
var id = $("#hidden_user_id").val();
var antenne_slug = $("#hidden_antenne_slug").val();
// Update the details by requesting to the server using ajax
$.post("/ajax/updateProduitsDetails.php", {
id: id,
produit: produit,
quantite: quantite,
prix: prix
},
function (data, status) {
// hide modal popup
$("#update_user_modal").modal("hide");
// reload Produits by using readRecords();
readRecords(antenne_slug);
}
);
}
function UpdateRecherchesDetails() {
// get values
var produit = $("#update_produit_r").val();
var vendeur = $("#update_vendeur_r").val();
var cle_pub = $("#update_cle_pub_r").val();
var prix = $("#update_prix_r").val();
// get hidden field value
var id = $("#hidden_user_id_r").val();
// Update the details by requesting to the server using ajax
$.post("ajax/updateRecherchesDetails.php", {
id_r: id,
produit_r: produit,
vendeur_r: vendeur,
cle_pub_r: cle_pub,
prix_r: prix
},
function (data, status) {
// hide modal popup
$("#update_user_modal2").modal("hide");
// reload Recherches by using readRecords2();
readRecords2();
}
);
}
$(document).ready(function () {
// On récupère le nom de l'antenne dans l'url pour afficher les biens/services de celle-ci
var url = document.location.href;
var antenne_slug = url.split('/')[5];
// READ records on page load
readRecords(antenne_slug);
//readRecords2();
});