Rev 140 | Blame | Last modification | View Log | RSS feed
package org.tela_botanica.client.modeles;
import org.tela_botanica.client.image.ImageModele;
import com.gwtext.client.core.UrlParam;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.Window;
import com.gwtext.client.widgets.event.WindowListenerAdapter;
import com.gwtextux.client.widgets.upload.UploadDialog;
import com.gwtextux.client.widgets.upload.UploadDialogListenerAdapter;
/**
* DAO un peu particulier car il crée une fenetre d'upload différente suivant
* que le plugin Java est détecté ou non
*
*
*/
public class ImageUploaderAsynchroneDAO {
/**
* Modele associé au DAO
*/
private static ImageModele iModele;
public ImageUploaderAsynchroneDAO(ImageModele im) {
iModele = im;
}
/**
* Setteur pour le modele
*
* @param im
* le modèle à associer au DAO
*/
public void setIModele(ImageModele im) {
iModele = im;
}
/**
* Crée un panel d'upload simple aux fonctions réduites mais utilisant
* uniquement javascript (pour les utilisateurs qui n'ont pas java)
*/
@SuppressWarnings("unused")
public static void appelerUploadSimple() {
UploadDialog up = new UploadDialog("Upload simple de fichiers");
up.setUrl(Configuration.getServiceBaseUrl() + "/InventoryImage");
UrlParam id = new UrlParam("identifiant", iModele.getIdentifiant());
UrlParam[] params = { id };
up.setBaseParams(params);
up.setModal(true);
up.addListener(new UploadDialogListenerAdapter() {
public void onClose(Panel panel) {
iModele.requeteTerminee();
}
public void onUploadComplete(UploadDialog source) {
iModele.requeteTerminee();
}
});
up.show();
}
/**
* Crée une fenêtre contenant une applet java pour uploader plusieurs
* fichiers à la fois avec quelques fonctions avancées (nécessite le plugin
* java pour le navigateur)
*/
@SuppressWarnings("unused")
public static void appelerUploadMultiple() {
final Window nPan = new Window("Upload multiple");
nPan.setWidth(640);
final String warning = "<p class=\"warning_upload\"> A la fin de l'envoi, veuillez fermer la fenêtre pour accéder aux images. </p>";
final String applet = "<applet code=\"wjhk.jupload2.JUploadApplet\" archive=\"wjhk.jupload.jar\" alt=\"\" mayscript=\"\" height=\"350\" width=\"625\">";
final String paramPostTarget = "<param name=\"postURL\" value=\""
+ Configuration.getServiceBaseUrl()
+ "/InventoryImage/\">";
final String paramUploadPolicy = "<param name=\"uploadPolicy\" value=\"PictureUploadPolicy\">";
final String paramMaxChunkSize = "<param name=\"maxChunkSize\" value=\"0\">";
final String paramMaxFileSize = "<param name=\"maxFileSize\" value=\"10000000\">";
final String paramTransmitMetaData = "<param name=\"pictureTransmitMetadata\" value=\"true\">";
final String paramFilesPerRequest = "<param name=\"nbFilesPerRequest\" value=\"1\">";
final String paramAllowedExtensions = "<param name=\"allowedFileExtensions\" value=\"jpg/jpeg/\">";
final String paramUploadSuccess = "<param name=\"stringUploadSuccess\" value=\"OK\">";
final String paramShowLogWindow = "<param name=\"showLogWindow\" value=\"false\">";
final String paramFormdata = "<param name=\"formData\" value=\"postid\">";
final String finApplet = "</applet>";
final String appelApplet = applet + paramPostTarget + paramUploadPolicy
+ paramMaxChunkSize + paramMaxFileSize + paramTransmitMetaData
+ paramFilesPerRequest + paramAllowedExtensions
+ paramUploadSuccess + paramShowLogWindow + paramFormdata
+ finApplet;
final String htmlForm = "<form method=\"post\" name=\"postid\">"
+ "<input type=\"hidden\" name=\"identifiant\" value=\""
+ iModele.getIdentifiant() + "\">" + "</form>";
nPan.setHtml(warning + appelApplet + htmlForm);
nPan.setModal(true);
nPan.addListener(new WindowListenerAdapter() {
public void onClose(Panel panel) {
iModele.requeteTerminee();
}
});
nPan.show();
}
/**
* Fonction javascript native qui détecte la présence du plugin java pour le
* navigateur et appelle la méthode d'upload adaptée (appelerUploadSimple ou
* appelerUploadMultiple)
*/
public static native void choisirMethodeUpload() /*-{
var agt=navigator.userAgent.toLowerCase();
var ie = (agt.indexOf("msie") != -1);
var ns = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);
function detectIE(ClassID,name) { result = false; document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name+','; else return ''; }
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }
if (ie && win) { pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") + detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") + detectIE("PDF.PdfCtrl.5","Acrobat Reader"); }
if (ns || !win) {
nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader");
}
pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);
if(pluginlist.indexOf("Java")!=-1)
{
@org.tela_botanica.client.modeles.ImageUploaderAsynchroneDAO::appelerUploadMultiple()() ;
}
else
{
@org.tela_botanica.client.modeles.ImageUploaderAsynchroneDAO::appelerUploadSimple()() ;
}
}-*/;
}