12,6 → 12,7 |
} |
return false; |
} |
|
// TODO : voir si cette fonction est bien utile. Résoud le pb d'un warning sous chrome. |
(function(){ |
// remove layerX and layerY |
33,33 → 34,73 |
supprimerMiniature(); |
}); |
|
if (window.File && window.FileReader) { |
if (DEBUG) { |
console.log("L'API File est supporté."); |
} |
$('#fichier').bind('change', function(e) { |
afficherMiniatureHtml5(e); |
}); |
} else { |
$("#fichier").bind('change', function (e) { |
arreter(e); |
$("#form-upload").ajaxSubmit(options); |
return false; |
}); |
|
//prepare the form when the DOM is ready |
//create service object(proxy) using SMD (generated by the json result) |
var options = { |
success: afficherMiniature, // post-submit callback |
dataType: 'xml', // 'xml', 'script', or 'json' (expected server response type) |
resetForm: true // reset the form after successful submit |
}; |
$("#form-upload").ajaxSubmit(options); |
return false; |
}); |
} |
}); |
|
function afficherMiniatureHtml5(evt) { |
supprimerMiniature(); |
var selectedfiles = evt.target.files; // FileList object |
var f = selectedfiles[0];// Nous récupérons seulement le premier fichier. |
// Only process image files. |
if (f.type.match('image.*') == false) { |
var message = "Seule les images JPEG sont supportées."; |
$("#miniature-msg").append(message); |
} else { |
var reader = new FileReader(); |
// Lit le fichier image commune url de données |
reader.readAsDataURL(f); |
var imgNom = f.name; |
|
// Closure pour capturer les infos du fichier |
reader.onload = (function(theFile) { |
return function(e) { |
// Rendre la miniature |
var imageBase64 = e.target.result; |
$("#miniature").append('<img id="miniature-img" class="miniature b64" src="'+imageBase64+'" alt="'+imgNom+'"/>'); |
}; |
})(f); |
} |
$("#effacer-miniature").show(); |
} |
|
function afficherMiniature(reponse) { |
// 'responseXML' is the XML document returned by the server; we use |
// jQuery to extract the content of the message node from the XML doc |
supprimerMiniature(); |
if (DEBUG) { |
var debogage = $("debogage", reponse).text(); |
console.log("Débogage upload : "+debogage); |
} |
var message = $("message", reponse).text(); |
if (message != '') { |
$("#miniature-msg").append(message); |
} else { |
var miniatureUrl = $("miniature-url", reponse).text(); |
var imgNom = $("image-nom", reponse).text(); |
$("#miniature").empty(); |
$("#miniature").append('<img id="miniature-img" class="miniature" alt="'+imgNom+'" src="'+miniatureUrl+'"/>'); |
} |
$("#effacer-miniature").show(); |
} |
|
function supprimerMiniature() { |
$("#miniature").empty(); |
$("#miniature-msg").empty(); |
$("#effacer-miniature").hide(); |
} |
|
347,12 → 388,12 |
'<tr id="obs'+obsNumero+'" class="obs">'+ |
'<td>'+obsNumero+'</td>'+ |
'<td>'+$("#date").val()+'</td>'+ |
'<td>'+$("#adresse").val()+'</td>'+ |
'<td>'+$("#rue").val()+'</td>'+ |
'<td>'+$("#taxon option:selected").text()+'</td>'+ |
'<td>'+$('input[name=milieu]:checked').val()+'</td>'+ |
'<td>'+$("#latitude").val()+' / '+$("#longitude").val()+'</td>'+ |
//Ajout du champ photo |
'<td class="obs-miniature">'+ajouterImgMiniature()+'</td>'+ |
'<td class="obs-miniature">'+ajouterImgMiniatureAuTransfert()+'</td>'+ |
'<td>'+$("#notes").val()+'</td>'+ |
'<td><button class="supprimer-obs" value="'+obsNumero+'" title="Supprimer l\'observation '+obsNumero+'">'+ |
'<img src="'+SUPPRIMER_ICONE_URL+'"/></button></td>'+ |
378,8 → 419,9 |
'notes' : $("#notes").val(), |
//Ajout des champs images |
'image_nom' : $("#miniature-img").attr('alt'), |
'image_b64' : ''// TODO : ajoute le support HTML5 |
'image_b64' : $("#miniature-img").hasClass('b64') ? $("#miniature-img").attr('src') : '' |
}); |
console.log("B64 : "+$("#miniature-img").hasClass('b64') ? $("#miniature-img").attr('src') : ''); |
} |
}); |
|
431,13 → 473,8 |
}, |
statusCode : { |
500 : function(jqXHR, textStatus, errorThrown) { |
$("#chargement").hide(); |
erreurMsg += "Erreur 500 :\ntype : "+textStatus+' '+errorThrown+"\n"; |
reponse = jQuery.parseJSON(jqXHR.responseText); |
if (reponse != null) { |
$.each(reponse, function (cle, valeur) { |
erreurMsg += valeur + "\n"; |
}); |
} |
if (DEBUG) { |
$("#dialogue-obs-transaction").append('<pre class="msg-erreur">'+erreurMsg+'</pre>'); |
} |
445,6 → 482,7 |
}, |
error : function(jqXHR, textStatus, errorThrown) { |
erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n"; |
try { |
reponse = jQuery.parseJSON(jqXHR.responseText); |
if (reponse != null) { |
$.each(reponse, function (cle, valeur) { |
451,6 → 489,9 |
erreurMsg += valeur + "\n"; |
}); |
} |
} catch(e) { |
erreurMsg += "L'erreur n'était pas en JSON."; |
} |
|
if (DEBUG) { |
$("#dialogue-obs-transaction").append('<pre class="msg-erreur">'+erreurMsg+'</pre>'); |
457,6 → 498,7 |
} |
}, |
complete : function(jqXHR, textStatus) { |
$("#chargement").hide(); |
var debugMsg = ''; |
if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') { |
debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data")); |
479,7 → 521,7 |
if (DEBUG) { |
$("#dialogue-obs-transaction").append('<pre class="msg-debug">Débogage : '+debugMsg+'</pre>'); |
} |
$("#chargement").hide(); |
|
$("#dialogue-obs-transaction").dialog(); |
$("#liste-obs").removeData(); |
$('.obs').remove(); |
491,47 → 533,13 |
}); |
}); |
|
function ajouterImgMiniature() { |
function ajouterImgMiniatureAuTransfert() { |
var miniature = ''; |
if ($("#miniature img").length == 1) { |
var css = $("#miniature-img").hasClass('b64') ? 'miniature b64' : 'miniature'; |
var src = $("#miniature-img").attr("src"); |
var alt = $("#miniature-img").attr("alt"); |
miniature = '<img class="miniature" alt="'+alt+'"src="'+src+'" />'; |
miniature = '<img class="'+css+'" alt="'+alt+'"src="'+src+'" />'; |
} |
return miniature; |
} |
|
function handleFileSelect(evt) { |
// Check for the various File API support. |
if (window.File && window.FileReader && window.FileList && window.Blob) { |
// Great success! All the File APIs are supported. |
var selectedfiles = evt.target.files; // FileList object |
|
// Loop through the FileList and render image files as thumbnails. |
for (var i = 0, f; f = selectedfiles[i]; i++) { |
|
// Only process image files. |
if (!f.type.match('image.*')) { |
continue; |
} |
|
var reader = new FileReader(); |
|
// Read in the image file as a data URL. |
reader.readAsDataURL(f); |
|
// Closure to capture the file information. |
reader.onload = (function(theFile) { |
return function(e) { |
// Render thumbnail. |
document.getElementById('image').src = e.target.result; |
//document.getElementById('list').insertBefore(img, null); |
}; |
})(f); |
} |
|
} |
else { |
alert('The File APIs are not fully supported in this browser.'); |
} |
} |