par
nats » 09 janv. 2010, 18:06
J'avance petit à petit.
AU niveau de l'input type text la syntaxe n'etait pas correct
Il ne faut pas faire ça
Code : Tout sélectionner
var txtarea = new Element('input', {type: "text", "name": "art_name", "rows": "0"}).update(modifArtist.aEffectuer.art_name);
Mais
Code : Tout sélectionner
var txt = new Element('input', {type: "text", "name": "art_name"});
txt.value = modifArtist.aEffectuer.art_name;
Par contre je n'arrive toujours pas à poster au script php l'artiste que je récupère
Voilà mon js avec la partie de modification qui pose problème en rouge
Code : Tout sélectionner
var artists = {
// tous les artistes
lastAddedArtist: null,
// le div conteneur
container: null,
// fonction d'init
init: function() {
var sbmButton = $("go");
var frm = $("monForm");
if(sbmButton && frm) {
sbmButton.observe("click", artists.postArtist);
}
},
// pst un artiste en ajax au script php. l'url est l'action du formulaire
postArtist: function(e) {
// on stop l'événement
e.stop();
// nouvelle requete ajax
new Ajax.Request($("monForm").action, {
method: "post",
parameters : $("monForm").serialize(true),
// on externalise le call back pour plus de lisibilité
onSuccess:artists.artist_callBack
});
},
// call back retour ajax
artist_callBack: function(response) {
// on evalue le JSON
var lastArtist = response.responseText.evalJSON();
// si le resultat est de type string, c'est un message d'erreur
if(Object.isString(lastArtist)) {
//on affiche une erreur
artists.writeError(lastArtist);
}
else {
// reinit du formulaire
$("monForm").reset();
// on ajoute l'artiste à la liste de ceux déjà créés
// note : le json retourné est de la forme : {arts:[{art_id: "id", art_name: "name"}]}
// il pourait etre plus simple : {art_id: "id", art_name: "name"}
// la ligne suivante serait alors simplement :
artists.lastAddedArtist = lastArtist.arts[0];
// on dessine les artistes
artists.drawArtists();
}
},
// ecriture d'un message d'erreur
writeError: function(message) {
// on obtient le conteneur et on l'update avec le message
artists.getContainer().update(message);
},
// dessine les artistes du tableau artists.allArtists
drawArtists : function() {
// on construit la table
var table = new Element('table');
// header
var tr0 = new Element('tr');
var th0 = new Element('th').update("ID");
var th1 = new Element('th').update("Artiste");
var th2 = new Element('th', {colspan: '2'}).update("Action");
tr0.insert(th0).insert(th1).insert(th2);
table.insert(tr0);
// ... toujours donner les noms les plus significatifs possibles, ca aide toujours 6 mois après
var artist = artists.lastAddedArtist;
var tr1 = new Element('tr');
var td1 = new Element('td').update(artist.art_id);
var td2 = new Element('td').update(artist.art_name);
var td3 = new Element('td');
var imgModif = new Element('img', {src: 'modifier.png', alt: 'modifier', title: 'modifier'});
var imgModifLink = new Element('a',{"class":'imgModif',id: 'modif', href:''});
imgModifLink.observe("click", modifArtist.drawArtModifier);
td3.insert(imgModifLink);
imgModifLink.insert(imgModif);
var td4 = new Element('td');
var imgSuppr = new Element('img', {src: 'supprimer.png', alt: 'supprimer', title: 'supprimer'});
var imgSupprLink = new Element('a',{"class":'imgSuppr', id: 'suppr', href:''});
imgSupprLink.observe("click", supprArtist.drawArtSupprimer);
td4.insert(imgSupprLink);
imgSupprLink.insert(imgSuppr);
tr1.insert(td1).insert(td2).insert(td3).insert(td4);
table.insert(tr1);
// on obtient le conteneur
var container = artists.getContainer();
// on enleve tout ce qu'il contient
container.childElements().invoke("remove");
// on update à vide et on insere la table
$('arts').innerHTML = "";
container.update("").insert(table);
},
// renvoie le conteneur
getContainer : function() {
// si'il est null
if(! artists.container) {
// on le crée en deux fois
var block = new Element("div", {"class": "block"});
$("Content").insert(block);
artists.container = new Element("div", {"id": "arts"});
block.insert(artists.container);
}
// on le renvoie
return artists.container;
}
};
[color=#FF0000]var modifArtist = {
// artiste à modifier
art_modif: null,
// le div conteneur
container: null,
// on dessine l'artiste à modifier
drawArtModifier : function(e){
// on stop l'évènement
e.stop();
// on construit le formulaire
var form = new Element('form', {"action": "modifArtist.php", "name": "frm_modification", "id": "frm_modification", "enctype": "multipart/form-data"});
// on récupère la valeur de l'artiste
modifArtist.aEffectuer = artists.lastAddedArtist;
// on construit la table
var table = new Element('table');
var tr0 = new Element('tr');
var th0 = new Element('th').update("Modifier Artiste");
var td0 = new Element('td');
var txt = new Element('input', {type: "text", "name": "art_name"});
txt.value = modifArtist.aEffectuer.art_name;
td0.insert(txt);
tr0.insert(th0).insert(td0);
table.insert(tr0);
var tr1 = new Element('tr');
var th1 = new Element('th');
var td1 = new Element('td');
var sbt = new Element('input', {type: "submit", "value": "Modifier", "id": "do"});
sbt.observe("click", modifArtist.postArtistModif);
td1.insert(sbt);
var btn = new Element('input', {type: "button", "value": "Annuler"});
btn.observe("click", function(){
document.location.href="art_nat2.php";
});
td1.insert(btn);
tr1.insert(th1).insert(td1);
table.insert(tr1);
form.insert(table);
// on obtient le conteneur
var container = modifArtist.getContainer();
// on enleve tout ce qu'il contient
container.childElements().invoke("remove");
// on update à vide et on insere la table
$('arts').innerHTML = "";
container.update("").insert(table);
},
// renvoie le conteneur
getContainer : function() {
// si'il est null
if(! modifArtist.container) {
// on le crée en deux fois
var block = new Element("div", {"class": "blockmodif"});
$("Content").insert(block);
modifArtist.container = new Element("div", {"id": "arts"});
block.insert(modifArtist.container);
}
// on le renvoie
return modifArtist.container;
}
// fonction d'init
init: function(){
var sbmModifButton = $("do");
var frmModif = $("frm_modification");
if(sbmModifButton && frmModif) {
sbmModifButton.observe("click", modifArtist.postArtistModif);
}
},
// poste un artiste en ajax au script php. L'url est l'action du formulaire
postArtistModif: function(e) {
// on stoppe l'évènement
e.stop();
// nouvelle requête ajax
new Ajax.Request($("frm_modification").action, {
method: "post",
parameters: $("frm_modification").serialize(true),
// on externalise le call back pour plus de lisibilité
onSuccess: modifArtist.artModif_callBack
});
},
// call back retour ajax
artModif_callBack: function(response) {
// on evalue le JSON
var artModif = response.responseText.evalJSON();
// si le résultat est de type de string, c'est un message d'erreur
if(Object.isString(artModif)) {
// on affiche une erreur
modifArtist.writeError(artModif);
}
else {
// reinit du formulaire
$("frm_modification").reset();
//on récupère l'artiste à modifier
modifArtist.art_modif = artists.lastArtist.arts[0];
// on dessine l'artiste à modifier
modifArtist.drawArtistModif();
}
},
// ecriture d'un message d'erreur
writeError: function(message) {
// on obtient le conteneur et on l'update avec le message
modifArtist.getContainer().update(message);
},
// On dessine le tableau de l'artiste à modifier
drawArtistModif: function() {
// on construit la table
var table = new Element('table');
// header
var tr0 = new Element('tr');
var th0 = new Element('th').update("ID");
var th1 = new Element('th').update("Artiste");
var th2 = new Element('th', {colspan:'2'}).update("Action");
tr0.insert(th0).insert(th1).insert(th2);
table.insert(tr0);
var artModification = modifArtist.art_modif;
var tr1 = new Element('tr');
var td1 = new Element('td').update(artModification.art_id);
var td2 = new Element('td').update(artModification.art_name);
var td3 = new Element('td');
var imgModif = new Element('img', {src: 'modifier.png', alt: 'modifier', title: 'modifier'});
var imgModifLink = new Element('a',{"class":'imgModif',id: 'modif', href:''});
imgModifLink.observe("click", modifArtist.drawArtModifier);
td3.insert(imgModifLink);
imgModifLink.insert(imgModif);
var td4 = new Element('td');
var imgSuppr = new Element('img', {src: 'supprimer.png', alt: 'supprimer', title: 'supprimer'});
var imgSupprLink = new Element('a',{"class":'imgSuppr', id: 'suppr', href:''});
imgSupprLink.observe("click", supprArtist.drawArtSupprimer);
td4.insert(imgSupprLink);
imgSupprLink.insert(imgSuppr);
tr1.insert(td1).insert(td2).insert(td3).insert(td4);
table.insert(tr1);
// on obtient le conteneur
var container = modifArtist.getContainer();
// on enleve tout ce qu'il contient
container.childElements().invoke("remove");
// on update à vide et on insère la table
$('arts').innerHTML = "";
container.update("").insert(table);
},
// renvoie le conteneur
getContainer: function() {
// s'il est null
if(! modifArtist.container) {
// on le créé en deux fois
var block = new Element("div", {"class": "blockmodif"});
$("Content").insert(block);
modifArtist.container = new Element("div", {"id": "arts"});
block.insert(modifArtist.container);
}
// on le renvoie
return modifArtist.container;
}
};[/color]
var supprArtist = {
// le div conteneur
container: null,
url: null,
// fonction d'init
init: function(){
supprArtist.url = "supprArtist.php";
},
// on dessine l'artiste à supprimer
drawArtSupprimer : function(e){
// on stop l'évènement
e.stop();
// on récupère la valeur de l'artiste à modifier
supprArtist.aEffectuer = artists.lastAddedArtist;
// on construit le span de modification
message = "Vous êtes sur le point de supprimer: ";
var spn = new Element('span',{"style":"font-weight: bold"}).update(message + supprArtist.aEffectuer.art_name);
// on construit le formulaire de suppression
var frm_suppr = new Element('form', {"action": supprArtist.url, "name": "monForm", "id": "monForm", "enctype": "multipart/form-data"});
var sbt_suppr = new Element('input', {type: "submit", "value": "Supprimer", "id": "go"});
sbt_suppr.observe("click", function(){
document.location.href="supprArtist.php";
});
frm_suppr.insert(sbt_suppr);
var btn_suppr = new Element('input', {type: "button", "value": "Annuler"});
btn_suppr.observe("click", function(){
document.location.href="art_nat2.php";
});
frm_suppr.insert(btn_suppr);
// on obtient le conteneur
var container = supprArtist.getContainer();
// on enleve tout ce qu'il contient
container.childElements().invoke("remove");
// on update à vide et on insere la table
$('arts').innerHTML = "";
container.update("").insert(spn).insert(frm_suppr);
},
// renvoie le conteneur
getContainer : function() {
// si'il est null
if(! modifArtist.container) {
// on le crée en deux fois
var block_suppr = new Element("div", {"class": "blocksuppr"});
$("Content").insert(block_suppr);
supprArtist.container = new Element("div", {"id": "arts"});
block_suppr.insert(supprArtist.container);
}
// on le renvoie
return supprArtist.container;
}
};
document.observe('dom:loaded', function() {
artists.init();
modifArtist.init();
supprArtist.init();
});
J'avance petit à petit.
AU niveau de l'input type text la syntaxe n'etait pas correct
Il ne faut pas faire ça
[code]var txtarea = new Element('input', {type: "text", "name": "art_name", "rows": "0"}).update(modifArtist.aEffectuer.art_name);[/code]
Mais
[code]var txt = new Element('input', {type: "text", "name": "art_name"});
txt.value = modifArtist.aEffectuer.art_name;[/code]
Par contre je n'arrive toujours pas à poster au script php l'artiste que je récupère
Voilà mon js avec la partie de modification qui pose problème en rouge
[code]var artists = {
// tous les artistes
lastAddedArtist: null,
// le div conteneur
container: null,
// fonction d'init
init: function() {
var sbmButton = $("go");
var frm = $("monForm");
if(sbmButton && frm) {
sbmButton.observe("click", artists.postArtist);
}
},
// pst un artiste en ajax au script php. l'url est l'action du formulaire
postArtist: function(e) {
// on stop l'événement
e.stop();
// nouvelle requete ajax
new Ajax.Request($("monForm").action, {
method: "post",
parameters : $("monForm").serialize(true),
// on externalise le call back pour plus de lisibilité
onSuccess:artists.artist_callBack
});
},
// call back retour ajax
artist_callBack: function(response) {
// on evalue le JSON
var lastArtist = response.responseText.evalJSON();
// si le resultat est de type string, c'est un message d'erreur
if(Object.isString(lastArtist)) {
//on affiche une erreur
artists.writeError(lastArtist);
}
else {
// reinit du formulaire
$("monForm").reset();
// on ajoute l'artiste à la liste de ceux déjà créés
// note : le json retourné est de la forme : {arts:[{art_id: "id", art_name: "name"}]}
// il pourait etre plus simple : {art_id: "id", art_name: "name"}
// la ligne suivante serait alors simplement :
artists.lastAddedArtist = lastArtist.arts[0];
// on dessine les artistes
artists.drawArtists();
}
},
// ecriture d'un message d'erreur
writeError: function(message) {
// on obtient le conteneur et on l'update avec le message
artists.getContainer().update(message);
},
// dessine les artistes du tableau artists.allArtists
drawArtists : function() {
// on construit la table
var table = new Element('table');
// header
var tr0 = new Element('tr');
var th0 = new Element('th').update("ID");
var th1 = new Element('th').update("Artiste");
var th2 = new Element('th', {colspan: '2'}).update("Action");
tr0.insert(th0).insert(th1).insert(th2);
table.insert(tr0);
// ... toujours donner les noms les plus significatifs possibles, ca aide toujours 6 mois après
var artist = artists.lastAddedArtist;
var tr1 = new Element('tr');
var td1 = new Element('td').update(artist.art_id);
var td2 = new Element('td').update(artist.art_name);
var td3 = new Element('td');
var imgModif = new Element('img', {src: 'modifier.png', alt: 'modifier', title: 'modifier'});
var imgModifLink = new Element('a',{"class":'imgModif',id: 'modif', href:''});
imgModifLink.observe("click", modifArtist.drawArtModifier);
td3.insert(imgModifLink);
imgModifLink.insert(imgModif);
var td4 = new Element('td');
var imgSuppr = new Element('img', {src: 'supprimer.png', alt: 'supprimer', title: 'supprimer'});
var imgSupprLink = new Element('a',{"class":'imgSuppr', id: 'suppr', href:''});
imgSupprLink.observe("click", supprArtist.drawArtSupprimer);
td4.insert(imgSupprLink);
imgSupprLink.insert(imgSuppr);
tr1.insert(td1).insert(td2).insert(td3).insert(td4);
table.insert(tr1);
// on obtient le conteneur
var container = artists.getContainer();
// on enleve tout ce qu'il contient
container.childElements().invoke("remove");
// on update à vide et on insere la table
$('arts').innerHTML = "";
container.update("").insert(table);
},
// renvoie le conteneur
getContainer : function() {
// si'il est null
if(! artists.container) {
// on le crée en deux fois
var block = new Element("div", {"class": "block"});
$("Content").insert(block);
artists.container = new Element("div", {"id": "arts"});
block.insert(artists.container);
}
// on le renvoie
return artists.container;
}
};
[color=#FF0000]var modifArtist = {
// artiste à modifier
art_modif: null,
// le div conteneur
container: null,
// on dessine l'artiste à modifier
drawArtModifier : function(e){
// on stop l'évènement
e.stop();
// on construit le formulaire
var form = new Element('form', {"action": "modifArtist.php", "name": "frm_modification", "id": "frm_modification", "enctype": "multipart/form-data"});
// on récupère la valeur de l'artiste
modifArtist.aEffectuer = artists.lastAddedArtist;
// on construit la table
var table = new Element('table');
var tr0 = new Element('tr');
var th0 = new Element('th').update("Modifier Artiste");
var td0 = new Element('td');
var txt = new Element('input', {type: "text", "name": "art_name"});
txt.value = modifArtist.aEffectuer.art_name;
td0.insert(txt);
tr0.insert(th0).insert(td0);
table.insert(tr0);
var tr1 = new Element('tr');
var th1 = new Element('th');
var td1 = new Element('td');
var sbt = new Element('input', {type: "submit", "value": "Modifier", "id": "do"});
sbt.observe("click", modifArtist.postArtistModif);
td1.insert(sbt);
var btn = new Element('input', {type: "button", "value": "Annuler"});
btn.observe("click", function(){
document.location.href="art_nat2.php";
});
td1.insert(btn);
tr1.insert(th1).insert(td1);
table.insert(tr1);
form.insert(table);
// on obtient le conteneur
var container = modifArtist.getContainer();
// on enleve tout ce qu'il contient
container.childElements().invoke("remove");
// on update à vide et on insere la table
$('arts').innerHTML = "";
container.update("").insert(table);
},
// renvoie le conteneur
getContainer : function() {
// si'il est null
if(! modifArtist.container) {
// on le crée en deux fois
var block = new Element("div", {"class": "blockmodif"});
$("Content").insert(block);
modifArtist.container = new Element("div", {"id": "arts"});
block.insert(modifArtist.container);
}
// on le renvoie
return modifArtist.container;
}
// fonction d'init
init: function(){
var sbmModifButton = $("do");
var frmModif = $("frm_modification");
if(sbmModifButton && frmModif) {
sbmModifButton.observe("click", modifArtist.postArtistModif);
}
},
// poste un artiste en ajax au script php. L'url est l'action du formulaire
postArtistModif: function(e) {
// on stoppe l'évènement
e.stop();
// nouvelle requête ajax
new Ajax.Request($("frm_modification").action, {
method: "post",
parameters: $("frm_modification").serialize(true),
// on externalise le call back pour plus de lisibilité
onSuccess: modifArtist.artModif_callBack
});
},
// call back retour ajax
artModif_callBack: function(response) {
// on evalue le JSON
var artModif = response.responseText.evalJSON();
// si le résultat est de type de string, c'est un message d'erreur
if(Object.isString(artModif)) {
// on affiche une erreur
modifArtist.writeError(artModif);
}
else {
// reinit du formulaire
$("frm_modification").reset();
//on récupère l'artiste à modifier
modifArtist.art_modif = artists.lastArtist.arts[0];
// on dessine l'artiste à modifier
modifArtist.drawArtistModif();
}
},
// ecriture d'un message d'erreur
writeError: function(message) {
// on obtient le conteneur et on l'update avec le message
modifArtist.getContainer().update(message);
},
// On dessine le tableau de l'artiste à modifier
drawArtistModif: function() {
// on construit la table
var table = new Element('table');
// header
var tr0 = new Element('tr');
var th0 = new Element('th').update("ID");
var th1 = new Element('th').update("Artiste");
var th2 = new Element('th', {colspan:'2'}).update("Action");
tr0.insert(th0).insert(th1).insert(th2);
table.insert(tr0);
var artModification = modifArtist.art_modif;
var tr1 = new Element('tr');
var td1 = new Element('td').update(artModification.art_id);
var td2 = new Element('td').update(artModification.art_name);
var td3 = new Element('td');
var imgModif = new Element('img', {src: 'modifier.png', alt: 'modifier', title: 'modifier'});
var imgModifLink = new Element('a',{"class":'imgModif',id: 'modif', href:''});
imgModifLink.observe("click", modifArtist.drawArtModifier);
td3.insert(imgModifLink);
imgModifLink.insert(imgModif);
var td4 = new Element('td');
var imgSuppr = new Element('img', {src: 'supprimer.png', alt: 'supprimer', title: 'supprimer'});
var imgSupprLink = new Element('a',{"class":'imgSuppr', id: 'suppr', href:''});
imgSupprLink.observe("click", supprArtist.drawArtSupprimer);
td4.insert(imgSupprLink);
imgSupprLink.insert(imgSuppr);
tr1.insert(td1).insert(td2).insert(td3).insert(td4);
table.insert(tr1);
// on obtient le conteneur
var container = modifArtist.getContainer();
// on enleve tout ce qu'il contient
container.childElements().invoke("remove");
// on update à vide et on insère la table
$('arts').innerHTML = "";
container.update("").insert(table);
},
// renvoie le conteneur
getContainer: function() {
// s'il est null
if(! modifArtist.container) {
// on le créé en deux fois
var block = new Element("div", {"class": "blockmodif"});
$("Content").insert(block);
modifArtist.container = new Element("div", {"id": "arts"});
block.insert(modifArtist.container);
}
// on le renvoie
return modifArtist.container;
}
};[/color]
var supprArtist = {
// le div conteneur
container: null,
url: null,
// fonction d'init
init: function(){
supprArtist.url = "supprArtist.php";
},
// on dessine l'artiste à supprimer
drawArtSupprimer : function(e){
// on stop l'évènement
e.stop();
// on récupère la valeur de l'artiste à modifier
supprArtist.aEffectuer = artists.lastAddedArtist;
// on construit le span de modification
message = "Vous êtes sur le point de supprimer: ";
var spn = new Element('span',{"style":"font-weight: bold"}).update(message + supprArtist.aEffectuer.art_name);
// on construit le formulaire de suppression
var frm_suppr = new Element('form', {"action": supprArtist.url, "name": "monForm", "id": "monForm", "enctype": "multipart/form-data"});
var sbt_suppr = new Element('input', {type: "submit", "value": "Supprimer", "id": "go"});
sbt_suppr.observe("click", function(){
document.location.href="supprArtist.php";
});
frm_suppr.insert(sbt_suppr);
var btn_suppr = new Element('input', {type: "button", "value": "Annuler"});
btn_suppr.observe("click", function(){
document.location.href="art_nat2.php";
});
frm_suppr.insert(btn_suppr);
// on obtient le conteneur
var container = supprArtist.getContainer();
// on enleve tout ce qu'il contient
container.childElements().invoke("remove");
// on update à vide et on insere la table
$('arts').innerHTML = "";
container.update("").insert(spn).insert(frm_suppr);
},
// renvoie le conteneur
getContainer : function() {
// si'il est null
if(! modifArtist.container) {
// on le crée en deux fois
var block_suppr = new Element("div", {"class": "blocksuppr"});
$("Content").insert(block_suppr);
supprArtist.container = new Element("div", {"id": "arts"});
block_suppr.insert(supprArtist.container);
}
// on le renvoie
return supprArtist.container;
}
};
document.observe('dom:loaded', function() {
artists.init();
modifArtist.init();
supprArtist.init();
});[/code]