Subversion Repositories eFlore/Applications.coel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
121 jpm 1
package org.tela_botanica.client.modeles;
2
 
3
import org.tela_botanica.client.RegistreId;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
5
 
6
import com.extjs.gxt.ui.client.Registry;
7
import com.google.gwt.http.client.Request;
8
import com.google.gwt.http.client.RequestBuilder;
9
import com.google.gwt.http.client.RequestCallback;
10
import com.google.gwt.http.client.RequestException;
11
import com.google.gwt.http.client.Response;
12
import com.google.gwt.http.client.URL;
13
import com.google.gwt.json.client.JSONArray;
14
import com.google.gwt.json.client.JSONParser;
15
import com.google.gwt.json.client.JSONValue;
16
 
17
public class StructureAsyncDao {
18
 
19
	public void ajouter(final Rafraichissable r, String utilisateurId, final Structure str) {
20
		String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
21
		RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, url+"CoelStructureListe/");
22
 
23
		String postDonnees = 	"identifiant=" + utilisateurId +
24
			"&ce_projet =" + URL.encodeComponent(str.getIdProjet()) +
25
			"&ce_mere =" + URL.encodeComponent(str.getIdMere()) +
26
			"&guid =" + URL.encodeComponent(str.getGuid()) +
27
			"&truk_identifiant_alternatif =" + URL.encodeComponent(str.getIdAlternatif()) +
28
			"&nom=" + URL.encodeComponent(str.getNom()) +
29
			"&truk_nom_alternatif =" + URL.encodeComponent(str.getNomAlternatif()) +
30
			"&ce_type =" + URL.encodeComponent(str.getType()) +
31
			"&ce_truk_type_prive =" + URL.encodeComponent(str.getTypePrive()) +
32
			"&ce_truk_type_public =" + URL.encodeComponent(str.getTypePublic()) +
33
			"&adresse_01 =" + URL.encodeComponent(str.getAdresse()) +
34
			"&adresse_02 =" + URL.encodeComponent(str.getAdresseComplement()) +
35
			"&date_fondation =" + URL.encodeComponent(str.getDateFondation()) +
36
			"&code_postal =" + URL.encodeComponent(str.getCodePostal()) +
37
			"&ville =" + URL.encodeComponent(str.getVille()) +
38
			"&region =" + URL.encodeComponent(str.getRegion()) +
39
			"&pays =" + URL.encodeComponent(str.getPays()) +
40
			"&telephone =" + URL.encodeComponent(str.getTelephone()) +
41
			"&fax =" + URL.encodeComponent(str.getFax()) +
42
			"&truk_url =" + URL.encodeComponent(str.getUrl()) +
43
			"&nbre_personne =" + URL.encodeComponent(str.getNbrePersonne()) +
44
			"";
45
 
46
		try {
47
			rb.sendRequest(postDonnees, new RequestCallback() {
48
 
49
				public void onError(Request request, Throwable exception) {
50
					// TODO Auto-generated method stub
51
 
52
				}
53
 
54
				public void onResponseReceived(Request request, Response response) {
55
					if (response.getText().length() != 0 && response.getText() != null) {
56
						final JSONValue responseValue = JSONParser.parse(response.getText());
57
 
58
						// Si la requête est un succès, reception d'un tableau
59
						if (responseValue.isString() != null) {
60
							str.set("messages", responseValue.isString().stringValue());
61
							r.rafraichir(str);
62
						}
63
					}
64
				}
65
 
66
			}) ;
67
		} catch (RequestException e) {
68
 
69
		}
70
	}
71
}