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");
|
5 |
aperonnet |
48 |
UrlParam id = new UrlParam("identifiant", iModele.getIdentifiant());
|
|
|
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) {
|
5 |
aperonnet |
56 |
|
|
|
57 |
iModele.requeteTerminee();
|
2 |
aperonnet |
58 |
}
|
|
|
59 |
|
|
|
60 |
public void onUploadComplete(UploadDialog source) {
|
5 |
aperonnet |
61 |
|
|
|
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\">"
|
|
|
107 |
+ "<input type=\"hidden\" name=\"identifiant\" value=\""
|
|
|
108 |
+ iModele.getIdentifiant() + "\">" + "</form>";
|
|
|
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) {
|
2 |
aperonnet |
117 |
|
5 |
aperonnet |
118 |
iModele.requeteTerminee();
|
|
|
119 |
|
2 |
aperonnet |
120 |
}
|
5 |
aperonnet |
121 |
|
2 |
aperonnet |
122 |
});
|
5 |
aperonnet |
123 |
|
2 |
aperonnet |
124 |
nPan.show();
|
|
|
125 |
}
|
5 |
aperonnet |
126 |
|
2 |
aperonnet |
127 |
/**
|
5 |
aperonnet |
128 |
* Fonction javascript native qui détecte la présence du plugin java pour le
|
|
|
129 |
* navigateur et appelle la méthode d'upload adaptée (appelerUploadSimple ou
|
|
|
130 |
* appelerUploadMultiple)
|
2 |
aperonnet |
131 |
*/
|
|
|
132 |
public static native void choisirMethodeUpload() /*-{
|
|
|
133 |
|
|
|
134 |
var agt=navigator.userAgent.toLowerCase();
|
|
|
135 |
var ie = (agt.indexOf("msie") != -1);
|
|
|
136 |
var ns = (navigator.appName.indexOf("Netscape") != -1);
|
|
|
137 |
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
|
|
|
138 |
var mac = (agt.indexOf("mac")!=-1);
|
|
|
139 |
|
|
|
140 |
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 ''; }
|
|
|
141 |
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }
|
|
|
142 |
|
|
|
143 |
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"); }
|
|
|
144 |
if (ns || !win) {
|
|
|
145 |
nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
|
|
|
146 |
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");
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
pluginlist += navigator.javaEnabled() ? "Java," : "";
|
|
|
150 |
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);
|
|
|
151 |
|
|
|
152 |
if(pluginlist.indexOf("Java")!=-1)
|
|
|
153 |
{
|
|
|
154 |
@org.tela_botanica.client.modeles.ImageUploaderAsynchroneDAO::appelerUploadMultiple()() ;
|
|
|
155 |
}
|
|
|
156 |
else
|
|
|
157 |
{
|
|
|
158 |
@org.tela_botanica.client.modeles.ImageUploaderAsynchroneDAO::appelerUploadSimple()() ;
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
}-*/;
|
|
|
162 |
|
|
|
163 |
}
|