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 |
|
2 |
aperonnet |
56 |
public void onClose(Panel panel) {
|
690 |
aurelien |
57 |
iModele.setDernierePage();
|
5 |
aperonnet |
58 |
iModele.requeteTerminee();
|
2 |
aperonnet |
59 |
}
|
|
|
60 |
|
|
|
61 |
public void onUploadComplete(UploadDialog source) {
|
690 |
aurelien |
62 |
iModele.setDernierePage();
|
5 |
aperonnet |
63 |
iModele.requeteTerminee();
|
|
|
64 |
|
2 |
aperonnet |
65 |
}
|
|
|
66 |
|
5 |
aperonnet |
67 |
});
|
|
|
68 |
|
|
|
69 |
up.show();
|
|
|
70 |
|
2 |
aperonnet |
71 |
}
|
5 |
aperonnet |
72 |
|
2 |
aperonnet |
73 |
/**
|
5 |
aperonnet |
74 |
* Crée une fenêtre contenant une applet java pour uploader plusieurs
|
|
|
75 |
* fichiers à la fois avec quelques fonctions avancées (nécessite le plugin
|
|
|
76 |
* java pour le navigateur)
|
2 |
aperonnet |
77 |
*/
|
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 |
|
1284 |
aurelien |
85 |
final String applet = "<applet code=\"wjhk.jupload2.JUploadApplet\" name=\"JUpload\" archive=\"jupload.jar\" alt=\"\" mayscript=\"true\" 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\">";
|
1284 |
aurelien |
91 |
final String paramMaxFileSize = "<param name=\"maxFileSize\" value=\""+Configuration.getTailleMaxUpload()+"\">";
|
2 |
aperonnet |
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\">"
|
971 |
aurelien |
107 |
+ "<input type=\"hidden\" name=\"ce_utilisateur\" value=\""
|
|
|
108 |
+ Utilisateur.getInstance().getIdentifiantUtilisateurConsulte() + "\">" + "</form>";
|
5 |
aperonnet |
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) {
|
690 |
aurelien |
117 |
iModele.setDernierePage();
|
5 |
aperonnet |
118 |
iModele.requeteTerminee();
|
2 |
aperonnet |
119 |
}
|
5 |
aperonnet |
120 |
|
2 |
aperonnet |
121 |
});
|
5 |
aperonnet |
122 |
|
2 |
aperonnet |
123 |
nPan.show();
|
|
|
124 |
}
|
5 |
aperonnet |
125 |
|
2 |
aperonnet |
126 |
/**
|
5 |
aperonnet |
127 |
* Fonction javascript native qui détecte la présence du plugin java pour le
|
|
|
128 |
* navigateur et appelle la méthode d'upload adaptée (appelerUploadSimple ou
|
|
|
129 |
* appelerUploadMultiple)
|
2 |
aperonnet |
130 |
*/
|
|
|
131 |
public static native void choisirMethodeUpload() /*-{
|
|
|
132 |
|
|
|
133 |
var agt=navigator.userAgent.toLowerCase();
|
|
|
134 |
var ie = (agt.indexOf("msie") != -1);
|
|
|
135 |
var ns = (navigator.appName.indexOf("Netscape") != -1);
|
|
|
136 |
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
|
|
|
137 |
var mac = (agt.indexOf("mac")!=-1);
|
|
|
138 |
|
|
|
139 |
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 ''; }
|
|
|
140 |
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }
|
|
|
141 |
|
|
|
142 |
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"); }
|
|
|
143 |
if (ns || !win) {
|
|
|
144 |
nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
|
|
|
145 |
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");
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
pluginlist += navigator.javaEnabled() ? "Java," : "";
|
|
|
149 |
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);
|
|
|
150 |
|
|
|
151 |
if(pluginlist.indexOf("Java")!=-1)
|
|
|
152 |
{
|
989 |
aurelien |
153 |
@org.tela_botanica.client.modeles.dao.ImageUploaderAsynchroneDAO::appelerUploadMultiple()() ;
|
2 |
aperonnet |
154 |
}
|
|
|
155 |
else
|
|
|
156 |
{
|
989 |
aurelien |
157 |
@org.tela_botanica.client.modeles.dao.ImageUploaderAsynchroneDAO::appelerUploadSimple()() ;
|
2 |
aperonnet |
158 |
}
|
|
|
159 |
|
|
|
160 |
}-*/;
|
|
|
161 |
|
|
|
162 |
}
|