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