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