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() {
|
5 |
aperonnet |
47 |
|
2621 |
aurelien |
48 |
UploadDialog up = new UploadDialog(Msg.get("upload-simple-fichiers"));
|
140 |
aurelien |
49 |
up.setUrl(Configuration.getServiceBaseUrl() + "/InventoryImage");
|
971 |
aurelien |
50 |
UrlParam id = new UrlParam("ce_utilisateur",Utilisateur.getInstance().getIdentifiantUtilisateurConsulte());
|
5 |
aperonnet |
51 |
UrlParam[] params = { id };
|
|
|
52 |
up.setBaseParams(params);
|
|
|
53 |
up.setModal(true);
|
|
|
54 |
|
|
|
55 |
up.addListener(new UploadDialogListenerAdapter() {
|
|
|
56 |
|
1293 |
aurelien |
57 |
@Override
|
2 |
aperonnet |
58 |
public void onClose(Panel panel) {
|
690 |
aurelien |
59 |
iModele.setDernierePage();
|
5 |
aperonnet |
60 |
iModele.requeteTerminee();
|
2 |
aperonnet |
61 |
}
|
|
|
62 |
|
1293 |
aurelien |
63 |
@Override
|
2 |
aperonnet |
64 |
public void onUploadComplete(UploadDialog source) {
|
690 |
aurelien |
65 |
iModele.setDernierePage();
|
5 |
aperonnet |
66 |
iModele.requeteTerminee();
|
|
|
67 |
|
2 |
aperonnet |
68 |
}
|
|
|
69 |
|
5 |
aperonnet |
70 |
});
|
|
|
71 |
|
|
|
72 |
up.show();
|
|
|
73 |
|
2 |
aperonnet |
74 |
}
|
5 |
aperonnet |
75 |
|
2 |
aperonnet |
76 |
/**
|
5 |
aperonnet |
77 |
* Crée une fenêtre contenant une applet java pour uploader plusieurs
|
|
|
78 |
* fichiers à la fois avec quelques fonctions avancées (nécessite le plugin
|
|
|
79 |
* java pour le navigateur)
|
2 |
aperonnet |
80 |
*/
|
148 |
aurelien |
81 |
public static void appelerUploadMultiple() {
|
5 |
aperonnet |
82 |
|
2621 |
aurelien |
83 |
final Window nPan = new Window(Msg.get("upload-multiple-fichiers"));
|
5 |
aperonnet |
84 |
nPan.setWidth(640);
|
2621 |
aurelien |
85 |
|
|
|
86 |
final String warning = "<p class=\"warning_upload\"> "+Msg.get("indication-fin-upload-multiple-fermer")+". </p>";
|
2 |
aperonnet |
87 |
|
1332 |
aurelien |
88 |
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 |
89 |
final String paramPostTarget = "<param name=\"postURL\" value=\""
|
140 |
aurelien |
90 |
+ Configuration.getServiceBaseUrl()
|
5 |
aperonnet |
91 |
+ "/InventoryImage/\">";
|
2 |
aperonnet |
92 |
final String paramUploadPolicy = "<param name=\"uploadPolicy\" value=\"PictureUploadPolicy\">";
|
|
|
93 |
final String paramMaxChunkSize = "<param name=\"maxChunkSize\" value=\"0\">";
|
1284 |
aurelien |
94 |
final String paramMaxFileSize = "<param name=\"maxFileSize\" value=\""+Configuration.getTailleMaxUpload()+"\">";
|
2 |
aperonnet |
95 |
final String paramTransmitMetaData = "<param name=\"pictureTransmitMetadata\" value=\"true\">";
|
|
|
96 |
final String paramFilesPerRequest = "<param name=\"nbFilesPerRequest\" value=\"1\">";
|
|
|
97 |
final String paramAllowedExtensions = "<param name=\"allowedFileExtensions\" value=\"jpg/jpeg/\">";
|
5 |
aperonnet |
98 |
final String paramUploadSuccess = "<param name=\"stringUploadSuccess\" value=\"OK\">";
|
2 |
aperonnet |
99 |
final String paramShowLogWindow = "<param name=\"showLogWindow\" value=\"false\">";
|
5 |
aperonnet |
100 |
final String paramFormdata = "<param name=\"formData\" value=\"postid\">";
|
2 |
aperonnet |
101 |
final String finApplet = "</applet>";
|
|
|
102 |
|
5 |
aperonnet |
103 |
final String appelApplet = applet + paramPostTarget + paramUploadPolicy
|
|
|
104 |
+ paramMaxChunkSize + paramMaxFileSize + paramTransmitMetaData
|
|
|
105 |
+ paramFilesPerRequest + paramAllowedExtensions
|
|
|
106 |
+ paramUploadSuccess + paramShowLogWindow + paramFormdata
|
2 |
aperonnet |
107 |
+ finApplet;
|
|
|
108 |
|
5 |
aperonnet |
109 |
final String htmlForm = "<form method=\"post\" name=\"postid\">"
|
971 |
aurelien |
110 |
+ "<input type=\"hidden\" name=\"ce_utilisateur\" value=\""
|
|
|
111 |
+ Utilisateur.getInstance().getIdentifiantUtilisateurConsulte() + "\">" + "</form>";
|
5 |
aperonnet |
112 |
|
|
|
113 |
nPan.setHtml(warning + appelApplet + htmlForm);
|
|
|
114 |
|
|
|
115 |
nPan.setModal(true);
|
|
|
116 |
|
2 |
aperonnet |
117 |
nPan.addListener(new WindowListenerAdapter() {
|
|
|
118 |
|
1293 |
aurelien |
119 |
@Override
|
5 |
aperonnet |
120 |
public void onClose(Panel panel) {
|
690 |
aurelien |
121 |
iModele.setDernierePage();
|
5 |
aperonnet |
122 |
iModele.requeteTerminee();
|
2 |
aperonnet |
123 |
}
|
5 |
aperonnet |
124 |
|
2 |
aperonnet |
125 |
});
|
5 |
aperonnet |
126 |
|
2 |
aperonnet |
127 |
nPan.show();
|
|
|
128 |
}
|
5 |
aperonnet |
129 |
|
2 |
aperonnet |
130 |
/**
|
5 |
aperonnet |
131 |
* Fonction javascript native qui détecte la présence du plugin java pour le
|
|
|
132 |
* navigateur et appelle la méthode d'upload adaptée (appelerUploadSimple ou
|
|
|
133 |
* appelerUploadMultiple)
|
2 |
aperonnet |
134 |
*/
|
|
|
135 |
public static native void choisirMethodeUpload() /*-{
|
|
|
136 |
|
|
|
137 |
var agt=navigator.userAgent.toLowerCase();
|
|
|
138 |
var ie = (agt.indexOf("msie") != -1);
|
|
|
139 |
var ns = (navigator.appName.indexOf("Netscape") != -1);
|
|
|
140 |
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
|
|
|
141 |
var mac = (agt.indexOf("mac")!=-1);
|
|
|
142 |
|
|
|
143 |
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 ''; }
|
|
|
144 |
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }
|
|
|
145 |
|
|
|
146 |
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"); }
|
|
|
147 |
if (ns || !win) {
|
|
|
148 |
nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
|
|
|
149 |
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");
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
pluginlist += navigator.javaEnabled() ? "Java," : "";
|
|
|
153 |
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);
|
|
|
154 |
|
|
|
155 |
if(pluginlist.indexOf("Java")!=-1)
|
|
|
156 |
{
|
989 |
aurelien |
157 |
@org.tela_botanica.client.modeles.dao.ImageUploaderAsynchroneDAO::appelerUploadMultiple()() ;
|
2 |
aperonnet |
158 |
}
|
|
|
159 |
else
|
|
|
160 |
{
|
989 |
aurelien |
161 |
@org.tela_botanica.client.modeles.dao.ImageUploaderAsynchroneDAO::appelerUploadSimple()() ;
|
2 |
aperonnet |
162 |
}
|
|
|
163 |
|
|
|
164 |
}-*/;
|
|
|
165 |
|
|
|
166 |
}
|