| Current Path : /home/happyrenas/old/huissier-express.fr/administration/2020/js/ |
Linux webd005.cluster105.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 |
| Current File : /home/happyrenas/old/huissier-express.fr/administration/2020/js/table-datatables-editable.js |
var TableDatatablesEditable = function () {
var handleTable = function () {
function restoreRow(oTable, nRow) {
var aData = oTable.fnGetData(nRow);
var jqTds = $('>td', nRow);
for (var i = 0, iLen = jqTds.length; i < iLen; i++) {
oTable.fnUpdate(aData[i], nRow, i, false);
}
oTable.fnDraw();
}
function editRow(oTable, nRow) {
var aData = oTable.fnGetData(nRow);
var jqTds = $('>td', nRow);
jqTds[0].innerHTML = '<input disabled readonly type="text" class="form-control input-x-small" value="' + aData[0] + '">';
jqTds[1].innerHTML = '<input type="text" class="form-control input-small" value="' + aData[1] + '">';
jqTds[2].innerHTML = '<input type="text" class="form-control input-small" value="' + aData[2] + '">';
jqTds[3].innerHTML = '<input type="text" class="form-control input-small" value="' + aData[3] + '">';
jqTds[4].innerHTML = '<input type="email" class="form-control input-small" value="' + aData[4] + '">';
jqTds[5].innerHTML = '<input type="text" class="form-control input-small" value="' + aData[5] + '">';
jqTds[6].innerHTML = '<input type="text" class="form-control input-large" value="' + aData[6] + '">';
jqTds[7].innerHTML = '<a class="edit" href="">Enregistrer</a>';
jqTds[8].innerHTML = '<a class="cancel" href="">Cancel</a>';
}
function saveRow(oTable, nRow) {
var jqInputs = $('input', nRow);
event.preventDefault();
if (jqInputs[1].value=='') {alert('Le nom de l\'interlocuteur est requis');jqInputs[1].focus(); exit;}
$.post( "client_interlocuteur_maj.php", {client_id: jqInputs[0].value, nom: jqInputs[1].value , prenom: jqInputs[2].value , fonction: jqInputs[3].value , email: jqInputs[4].value , telephone: jqInputs[5].value, commentaire: jqInputs[6].value })
.done(function( data ) {
//alert( "Data Loaded: " + data );
});
oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
oTable.fnUpdate(jqInputs[2].value, nRow, 2, false);
oTable.fnUpdate(jqInputs[3].value, nRow, 3, false);
oTable.fnUpdate(jqInputs[4].value, nRow, 4, false);
oTable.fnUpdate(jqInputs[5].value, nRow, 5, false);
oTable.fnUpdate(jqInputs[6].value, nRow, 6, false);
oTable.fnUpdate('<a class="edit" href="">Edition Rapide</a>', nRow, 7, false);
oTable.fnUpdate('<a class="" href="'+jqInputs[0].value+'">Modifier</a>', nRow, 8, false);
oTable.fnDraw();
}
function cancelEditRow(oTable, nRow) {
var jqInputs = $('input', nRow);
oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
oTable.fnUpdate(jqInputs[2].value, nRow, 2, false);
oTable.fnUpdate(jqInputs[3].value, nRow, 3, false);
oTable.fnUpdate(jqInputs[4].value, nRow, 4, false);
oTable.fnUpdate(jqInputs[5].value, nRow, 5, false);
oTable.fnUpdate(jqInputs[6].value, nRow, 6, false);
oTable.fnUpdate('<a class="edit" href="">Edition Rapide</a>', nRow, 7, false);
oTable.fnDraw();
}
var table = $('#sample_editable_1');
var oTable = table.dataTable({
paging: false,
"columnDefs": [
{"targets": [0], "visible": true, "orderable": false},
{"targets": [1], "visible": true, "orderable": false}
],
"searching": false,
"language": {
"zeroRecords": "Aucun enregistrement dans la base",
"info": "",
"infoEmpty": "Résultat vide",
"infoFiltered": "(Sur _MAX_ résultats)",
"sSearch": "Rechercher : "
}
});
var tableWrapper = $("#sample_editable_1_wrapper");
var nEditing = null;
var nNew = false;
$('#sample_editable_1_new').click(function (e) {
e.preventDefault();
if (nNew && nEditing) {
if (confirm("Previose row not saved. Do you want to save it ?")) {
saveRow(oTable, nEditing); // save
$(nEditing).find("td:first").html("Untitled");
nEditing = null;
nNew = false;
} else {
oTable.fnDeleteRow(nEditing); // cancel
nEditing = null;
nNew = false;
return;
}
}
var aiNew = oTable.fnAddData(['', '', '', '','','', '', '', '']);
var nRow = oTable.fnGetNodes(aiNew[0]);
editRow(oTable, nRow);
nEditing = nRow;
nNew = true;
});
table.on('click', '.delete', function (e) {
e.preventDefault();
if (confirm("Are you sure to delete this row ?") == false) {
return;
}
var nRow = $(this).parents('tr')[0];
oTable.fnDeleteRow(nRow);
//alert("Deleted! Do not forget to do some ajax to sync with backend :)");
});
table.on('click', '.cancel', function (e) {
e.preventDefault();
if (nNew) {
oTable.fnDeleteRow(nEditing);
nEditing = null;
nNew = false;
} else {
restoreRow(oTable, nEditing);
nEditing = null;
}
});
table.on('click', '.edit', function (e) {
e.preventDefault();
nNew = false;
/* Get the row as a parent of the link that was clicked on */
var nRow = $(this).parents('tr')[0];
if (nEditing !== null && nEditing != nRow) {
/* Currently editing - but not this row - restore the old before continuing to edit mode */
restoreRow(oTable, nEditing);
editRow(oTable, nRow);
nEditing = nRow;
} else if (nEditing == nRow && this.innerHTML == "Enregistrer") {
/* Editing this row and want to save it */
saveRow(oTable, nEditing);
nEditing = null;
//alert("Updated! Do not forget to do some ajax to sync with backend :)");
} else {
/* No edit in progress - let's start one */
editRow(oTable, nRow);
nEditing = nRow;
}
});
}
return {
//main function to initiate the module
init: function () {
handleTable();
}
};
}();
jQuery(document).ready(function() {
TableDatatablesEditable.init();
});