Commit 5e6e73bf authored by Sylvain Coulange's avatar Sylvain Coulange
Browse files

ajout fonction de suppression entree dico

parent 3c411e16
......@@ -119,6 +119,14 @@ def newEntry(request):
}
return JsonResponse(rep)
def supprEntry(request):
mot = request.GET.get('mot', None)
ipCli = get_client_ip(request)
rep = {
'reponse': txtphono.delEntry(ipCli,mot)
}
return JsonResponse(rep)
def getLog(request):
rep = txtphono.sendMeLogPlease()
return JsonResponse(rep)
......
......@@ -15,7 +15,7 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path
from colorapp.views import main, dicoView, editEntry, newEntry, redirApp, main0, dicoReq, getLog
from colorapp.views import main, dicoView, editEntry, newEntry, supprEntry, redirApp, main0, dicoReq, getLog
urlpatterns = [
path('admin/', admin.site.urls),
......@@ -26,5 +26,6 @@ urlpatterns = [
path('dicoSearch/', dicoReq),
path('modifEntry/', editEntry),
path('addEntry/', newEntry),
path('delEntry/', supprEntry),
path('getLog/', getLog)
]
......@@ -100,8 +100,9 @@ $(document).ready(function(){
var btnModifier = '<button id="btnModifier'+cptEntr+'" class="btn btn-primary btn-perso" onclick="modifEntry('+cptEntr+',\''+entr+'\')"><span class="glyphicon glyphicon-edit" area-hidden="true" title="Modifier"></span></button>';
var btnValider = '<button id="btnValider'+cptEntr+'" class="btn btn-success btn-perso" style="display: none;" onclick="validEntry(\''+entr+'\','+cptEntr+')"><span class="glyphicon glyphicon-ok" area-hidden="true" title="Valider"></span></button>';
var btnAnnuler = '<button id="btnAnnuler'+cptEntr+'" class="btn btn-secondary btn-perso" style="display: none;" onclick="annuler('+cptEntr+')"><span class="glyphicon glyphicon-remove" area-hidden="true" title="Annuler"></span></button>';
var btnSupprimer = '<button id="btnSupprimer'+cptEntr+'" class="btn btn-danger btn-perso" style="display: none;" onclick="supprimer(\''+entr+'\','+cptEntr+')"><span class="glyphicon glyphicon-trash" area-hidden="true" title="Supprimer cette entrée"></span></button>';
document.getElementById('resultTable').innerHTML += '<tr id="tr'+cptEntr+'" class="tr"><td><span class="numEntr">'+cptEntr+'</span>'+lienWiki+' '+entr+'</td><td><input class="api-kb inputTrans" disabled="true" type="text" id="td'+cptEntr+'" value="'+transList+'">'+logEntr+'</td><td style="text-align:center">'+btnModifier+btnValider+btnAnnuler+'</td></tr>';
document.getElementById('resultTable').innerHTML += '<tr id="tr'+cptEntr+'" class="tr"><td><span class="numEntr">'+cptEntr+'</span>'+lienWiki+' '+entr+'</td><td><input class="api-kb inputTrans" disabled="true" type="text" id="td'+cptEntr+'" value="'+transList+'">'+logEntr+'</td><td style="text-align:center">'+btnModifier+btnValider+btnAnnuler+btnSupprimer+'</td></tr>';
getAPIkeyboard();
}
}
......@@ -127,9 +128,11 @@ function modifEntry(cptEntr,entr) {
var thisBtnModifier = 'btnModifier'+cptEntr;
var thisBtnValider = 'btnValider'+cptEntr;
var thisBtnAnnuler = 'btnAnnuler'+cptEntr;
var thisBtnSupprimer = 'btnSupprimer'+cptEntr;
thisBtnModifier = document.getElementById(thisBtnModifier);
thisBtnValider = document.getElementById(thisBtnValider);
thisBtnAnnuler = document.getElementById(thisBtnAnnuler);
thisBtnSupprimer = document.getElementById(thisBtnSupprimer);
thisTr.style.backgroundColor = "lightgreen";
......@@ -140,6 +143,7 @@ function modifEntry(cptEntr,entr) {
thisBtnModifier.style.display = 'none';
thisBtnValider.style.display = '';
thisBtnAnnuler.style.display = '';
thisBtnSupprimer.style.display = '';
}
function validEntry(entr, cptEntr) {
......@@ -182,6 +186,40 @@ function validEntry(entr, cptEntr) {
});
}
function supprimer(entr, cptEntr) {
var conf = window.confirm("Êtes-vous sûr⋅e de vouloir supprimer cette entrée du dictionnaire ?");
if (conf) {
document.getElementById('actionBlock').style.display = '';
var thisMot = entr;
var thisTr = 'tr'+cptEntr;
var thisTr = document.getElementById(thisTr);
document.body.style.cursor = "wait";
$.ajax({
url: '/delEntry/',
data: {
mot: thisMot
},
dataType: 'json',
success: function(data) {
document.body.style.cursor = "default";
console.log(data.reponse);
window.alert(data.reponse);
document.getElementById('actionBlock').style.display = 'none';
annuler(cptEntr);
thisTr.style.display = 'none';
},
error: function(){
// document.getElementById('loader').style.display = 'none';
document.body.style.cursor = "default";
window.alert("La suppression n'a pas pu être effectuée !");
document.getElementById('actionBlock').style.display = 'none';
}
});
}
}
function annuler(cptEntr) {
var thisTr = 'tr'+cptEntr;
var thisTd = 'td'+cptEntr;
......@@ -191,9 +229,11 @@ function annuler(cptEntr) {
var thisBtnModifier = 'btnModifier'+cptEntr;
var thisBtnValider = 'btnValider'+cptEntr;
var thisBtnAnnuler = 'btnAnnuler'+cptEntr;
var thisBtnSupprimer = 'btnSupprimer'+cptEntr;
thisBtnModifier = document.getElementById(thisBtnModifier);
thisBtnValider = document.getElementById(thisBtnValider);
thisBtnAnnuler = document.getElementById(thisBtnAnnuler);
thisBtnSupprimer = document.getElementById(thisBtnSupprimer);
thisTr.style.backgroundColor = "";
......@@ -203,6 +243,7 @@ function annuler(cptEntr) {
thisBtnModifier.style.display = '';
thisBtnValider.style.display = 'none';
thisBtnAnnuler.style.display = 'none';
thisBtnSupprimer.style.display = 'none';
entrActif = 0;
}
......
......@@ -197,6 +197,7 @@ def modifEntry(user,mot,newTransList):
def addEntry(user,mot,trans):
trans = trans.replace('g','ɡ')
mot = mot.lower()
mot = mot.strip()
transList = trans.split(',')
for ind,i in enumerate(transList):
......@@ -208,6 +209,15 @@ def addEntry(user,mot,trans):
print("Modification du dictionnaire par",user,": ajout de mot =",mot,"; transList = ",transList)
return "Ajout effectué avec succès ! Merci pour votre participation !"
def delEntry(user,mot):
if mot in word2trans.keys():
word2trans.pop(mot)
rewriteDico()
writeLog(Type="DEL", user=user, mot=mot, oldTransList="", newTransList="")
print("Modification du dictionnaire par",user,": suppression de mot =",mot)
return "Suppression effectuée avec succès."
def rewriteDico():
print('Rewritting dictionary...')
with tempfile.NamedTemporaryFile(dir='.', delete=False, mode="w") as tmp:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment