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