2 |
aperonnet |
1 |
package org.tela_botanica.client.modeles;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.client.image.ImageModele;
|
|
|
4 |
|
|
|
5 |
import com.gwtext.client.core.UrlParam;
|
|
|
6 |
import com.gwtext.client.widgets.Panel;
|
|
|
7 |
import com.gwtext.client.widgets.Window;
|
|
|
8 |
import com.gwtext.client.widgets.event.WindowListenerAdapter;
|
|
|
9 |
import com.gwtextux.client.widgets.upload.UploadDialog;
|
|
|
10 |
import com.gwtextux.client.widgets.upload.UploadDialogListenerAdapter;
|
|
|
11 |
|
|
|
12 |
/**
|
5 |
aperonnet |
13 |
* DAO un peu particulier car il crée une fenetre d'upload différente suivant
|
|
|
14 |
* que le plugin Java est détecté ou non
|
2 |
aperonnet |
15 |
*
|
|
|
16 |
*
|
|
|
17 |
*/
|
|
|
18 |
public class ImageUploaderAsynchroneDAO {
|
5 |
aperonnet |
19 |
|
2 |
aperonnet |
20 |
/**
|
|
|
21 |
* Modele associé au DAO
|
|
|
22 |
*/
|
5 |
aperonnet |
23 |
private static ImageModele iModele;
|
|
|
24 |
|
|
|
25 |
public ImageUploaderAsynchroneDAO(ImageModele im) {
|
|
|
26 |
iModele = im;
|
2 |
aperonnet |
27 |
}
|
5 |
aperonnet |
28 |
|
2 |
aperonnet |
29 |
/**
|
5 |
aperonnet |
30 |
* Setteur pour le modele
|
|
|
31 |
*
|
|
|
32 |
* @param im
|
|
|
33 |
* le modèle à associer au DAO
|
2 |
aperonnet |
34 |
*/
|
5 |
aperonnet |
35 |
public void setIModele(ImageModele im) {
|
|
|
36 |
iModele = im;
|
2 |
aperonnet |
37 |
}
|
5 |
aperonnet |
38 |
|
2 |
aperonnet |
39 |
/**
|
5 |
aperonnet |
40 |
* Crée un panel d'upload simple aux fonctions réduites mais utilisant
|
|
|
41 |
* uniquement javascript (pour les utilisateurs qui n'ont pas java)
|
2 |
aperonnet |
42 |
*/
|
|
|
43 |
@SuppressWarnings("unused")
|
148 |
aurelien |
44 |
public static void appelerUploadSimple() {
|
5 |
aperonnet |
45 |
|
|
|
46 |
UploadDialog up = new UploadDialog("Upload simple de fichiers");
|
140 |
aurelien |
47 |
up.setUrl(Configuration.getServiceBaseUrl() + "/InventoryImage");
|
971 |
aurelien |
48 |
UrlParam id = new UrlParam("ce_utilisateur",Utilisateur.getInstance().getIdentifiantUtilisateurConsulte());
|
5 |
aperonnet |
49 |
UrlParam[] params = { id };
|
|
|
50 |
up.setBaseParams(params);
|
|
|
51 |
up.setModal(true);
|
|
|
52 |
|
|
|
53 |
up.addListener(new UploadDialogListenerAdapter() {
|
|
|
54 |
|
2 |
aperonnet |
55 |
public void onClose(Panel panel) {
|
690 |
aurelien |
56 |
iModele.setDernierePage();
|
5 |
aperonnet |
57 |
iModele.requeteTerminee();
|
2 |
aperonnet |
58 |
}
|
|
|
59 |
|
|
|
60 |
public void onUploadComplete(UploadDialog source) {
|
690 |
aurelien |
61 |
iModele.setDernierePage();
|
5 |
aperonnet |
62 |
iModele.requeteTerminee();
|
|
|
63 |
|
2 |
aperonnet |
64 |
}
|
|
|
65 |
|
5 |
aperonnet |
66 |
});
|
|
|
67 |
|
|
|
68 |
up.show();
|
|
|
69 |
|
2 |
aperonnet |
70 |
}
|
5 |
aperonnet |
71 |
|
2 |
aperonnet |
72 |
/**
|
5 |
aperonnet |
73 |
* Crée une fenêtre contenant une applet java pour uploader plusieurs
|
|
|
74 |
* fichiers à la fois avec quelques fonctions avancées (nécessite le plugin
|
|
|
75 |
* java pour le navigateur)
|
2 |
aperonnet |
76 |
*/
|
|
|
77 |
@SuppressWarnings("unused")
|
148 |
aurelien |
78 |
public static void appelerUploadMultiple() {
|
5 |
aperonnet |
79 |
|
2 |
aperonnet |
80 |
final Window nPan = new Window("Upload multiple");
|
5 |
aperonnet |
81 |
nPan.setWidth(640);
|
2 |
aperonnet |
82 |
|
5 |
aperonnet |
83 |
final String warning = "<p class=\"warning_upload\"> A la fin de l'envoi, veuillez fermer la fenêtre pour accéder aux images. </p>";
|
|
|
84 |
|
2 |
aperonnet |
85 |
final String applet = "<applet code=\"wjhk.jupload2.JUploadApplet\" archive=\"wjhk.jupload.jar\" alt=\"\" mayscript=\"\" height=\"350\" width=\"625\">";
|
5 |
aperonnet |
86 |
final String paramPostTarget = "<param name=\"postURL\" value=\""
|
140 |
aurelien |
87 |
+ Configuration.getServiceBaseUrl()
|
5 |
aperonnet |
88 |
+ "/InventoryImage/\">";
|
2 |
aperonnet |
89 |
final String paramUploadPolicy = "<param name=\"uploadPolicy\" value=\"PictureUploadPolicy\">";
|
|
|
90 |
final String paramMaxChunkSize = "<param name=\"maxChunkSize\" value=\"0\">";
|
|
|
91 |
final String paramMaxFileSize = "<param name=\"maxFileSize\" value=\"10000000\">";
|
|
|
92 |
final String paramTransmitMetaData = "<param name=\"pictureTransmitMetadata\" value=\"true\">";
|
|
|
93 |
final String paramFilesPerRequest = "<param name=\"nbFilesPerRequest\" value=\"1\">";
|
|
|
94 |
final String paramAllowedExtensions = "<param name=\"allowedFileExtensions\" value=\"jpg/jpeg/\">";
|
5 |
aperonnet |
95 |
final String paramUploadSuccess = "<param name=\"stringUploadSuccess\" value=\"OK\">";
|
2 |
aperonnet |
96 |
final String paramShowLogWindow = "<param name=\"showLogWindow\" value=\"false\">";
|
5 |
aperonnet |
97 |
final String paramFormdata = "<param name=\"formData\" value=\"postid\">";
|
2 |
aperonnet |
98 |
final String finApplet = "</applet>";
|
|
|
99 |
|
5 |
aperonnet |
100 |
final String appelApplet = applet + paramPostTarget + paramUploadPolicy
|
|
|
101 |
+ paramMaxChunkSize + paramMaxFileSize + paramTransmitMetaData
|
|
|
102 |
+ paramFilesPerRequest + paramAllowedExtensions
|
|
|
103 |
+ paramUploadSuccess + paramShowLogWindow + paramFormdata
|
2 |
aperonnet |
104 |
+ finApplet;
|
|
|
105 |
|
5 |
aperonnet |
106 |
final String htmlForm = "<form method=\"post\" name=\"postid\">"
|
971 |
aurelien |
107 |
+ "<input type=\"hidden\" name=\"ce_utilisateur\" value=\""
|
|
|
108 |
+ Utilisateur.getInstance().getIdentifiantUtilisateurConsulte() + "\">" + "</form>";
|
5 |
aperonnet |
109 |
|
|
|
110 |
nPan.setHtml(warning + appelApplet + htmlForm);
|
|
|
111 |
|
|
|
112 |
nPan.setModal(true);
|
|
|
113 |
|
2 |
aperonnet |
114 |
nPan.addListener(new WindowListenerAdapter() {
|
|
|
115 |
|
5 |
aperonnet |
116 |
public void onClose(Panel panel) {
|
690 |
aurelien |
117 |
iModele.setDernierePage();
|
5 |
aperonnet |
118 |
iModele.requeteTerminee();
|
2 |
aperonnet |
119 |
}
|
5 |
aperonnet |
120 |
|
2 |
aperonnet |
121 |
});
|
5 |
aperonnet |
122 |
|
2 |
aperonnet |
123 |
nPan.show();
|
|
|
124 |
}
|
5 |
aperonnet |
125 |
|
2 |
aperonnet |
126 |
/**
|
5 |
aperonnet |
127 |
* Fonction javascript native qui détecte la présence du plugin java pour le
|
|
|
128 |
* navigateur et appelle la méthode d'upload adaptée (appelerUploadSimple ou
|
|
|
129 |
* appelerUploadMultiple)
|
2 |
aperonnet |
130 |
*/
|
|
|
131 |
public static native void choisirMethodeUpload() /*-{
|
|
|
132 |
|
|
|
133 |
var agt=navigator.userAgent.toLowerCase();
|
|
|
134 |
var ie = (agt.indexOf("msie") != -1);
|
|
|
135 |
var ns = (navigator.appName.indexOf("Netscape") != -1);
|
|
|
136 |
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
|
|
|
137 |
var mac = (agt.indexOf("mac")!=-1);
|
|
|
138 |
|
|
|
139 |
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 ''; }
|
|
|
140 |
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }
|
|
|
141 |
|
|
|
142 |
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"); }
|
|
|
143 |
if (ns || !win) {
|
|
|
144 |
nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
|
|
|
145 |
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");
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
pluginlist += navigator.javaEnabled() ? "Java," : "";
|
|
|
149 |
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);
|
|
|
150 |
|
|
|
151 |
if(pluginlist.indexOf("Java")!=-1)
|
|
|
152 |
{
|
|
|
153 |
@org.tela_botanica.client.modeles.ImageUploaderAsynchroneDAO::appelerUploadMultiple()() ;
|
|
|
154 |
}
|
|
|
155 |
else
|
|
|
156 |
{
|
|
|
157 |
@org.tela_botanica.client.modeles.ImageUploaderAsynchroneDAO::appelerUploadSimple()() ;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
}-*/;
|
|
|
161 |
|
|
|
162 |
}
|