Subversion Repositories eFlore/Archives.cel-v2

Rev

Rev 28 | Rev 36 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 28 Rev 31
1
package org.tela_botanica.client.modeles;
1
package org.tela_botanica.client.modeles;
2
 
2
 
3
import java.util.Iterator;
3
import java.util.Iterator;
4
 
4
 
5
import org.tela_botanica.client.image.ImageMediateur;
5
import org.tela_botanica.client.image.ImageMediateur;
6
import org.tela_botanica.client.interfaces.Rafraichissable;
6
import org.tela_botanica.client.interfaces.Rafraichissable;
7
 
7
 
8
import com.google.gwt.json.client.JSONArray;
8
import com.google.gwt.json.client.JSONArray;
9
import com.google.gwt.json.client.JSONObject;
9
import com.google.gwt.json.client.JSONObject;
10
import com.google.gwt.json.client.JSONParser;
10
import com.google.gwt.json.client.JSONParser;
11
import com.google.gwt.json.client.JSONString;
11
import com.google.gwt.json.client.JSONString;
12
import com.google.gwt.json.client.JSONValue;
12
import com.google.gwt.json.client.JSONValue;
13
import com.google.gwt.user.client.HTTPRequest;
13
import com.google.gwt.user.client.HTTPRequest;
14
import com.google.gwt.user.client.ResponseTextHandler;
14
import com.google.gwt.user.client.ResponseTextHandler;
15
import com.google.gwt.user.client.Window;
15
import com.google.gwt.user.client.Window;
16
import com.gwtext.client.data.ArrayReader;
16
import com.gwtext.client.data.ArrayReader;
17
import com.gwtext.client.data.FieldDef;
17
import com.gwtext.client.data.FieldDef;
18
import com.gwtext.client.data.MemoryProxy;
18
import com.gwtext.client.data.MemoryProxy;
19
import com.gwtext.client.data.RecordDef;
19
import com.gwtext.client.data.RecordDef;
20
import com.gwtext.client.data.Store;
20
import com.gwtext.client.data.Store;
21
import com.gwtext.client.data.StringFieldDef;
21
import com.gwtext.client.data.StringFieldDef;
22
 
22
 
23
/**
23
/**
24
 * Data Object Access communiquant avec le serveur jrest fournissant la liste des images
24
 * Data Object Access communiquant avec le serveur jrest fournissant la liste des images
25
 * répondant à des critères donné
25
 * répondant à des critères donné
26
 * @author aurelien
26
 * @author aurelien
27
 *
27
 *
28
 */
28
 */
29
public class ListeImageAsynchroneDAO {
29
public class ListeImageAsynchroneDAO {
30
	
30
	
31
	ImageMediateur iMediateur = null ;
31
	ImageMediateur iMediateur = null ;
32
	
32
	
33
	public void setIMediateur(ImageMediateur im)
33
	public void setIMediateur(ImageMediateur im)
34
	{
34
	{
35
		iMediateur = im ;
35
		iMediateur = im ;
36
	}
36
	}
37
	
37
	
38
	public void ObtenirListeImages(final Rafraichissable r)
38
	public void ObtenirListeImages(final Rafraichissable r, String[][] criteres)
-
 
39
	{
-
 
40
		
-
 
41
		String requete = "" ;
-
 
42
		
-
 
43
		if(criteres != null)
-
 
44
		{
-
 
45
			for (int i = 0; i < criteres.length; i++) {
-
 
46
				
-
 
47
				requete += criteres[i][0]+"="+criteres[i][1] ;
-
 
48
				if(i != criteres.length - 1)
-
 
49
				{
-
 
50
					requete += "&" ;
-
 
51
				}
-
 
52
			}
-
 
53
		}
39
	{
54
		
40
		HTTPRequest.asyncGet("jrest/inventoryImageList/1/ci_publiable_eflore=0", new ResponseTextHandler() {
55
		HTTPRequest.asyncGet("jrest/InventoryImageList/0/"+requete, new ResponseTextHandler() {
41
			public void onCompletion(String responseText) {
56
			public void onCompletion(String responseText) {
42
				
57
				
43
				final ListeImageCarnet photoData ;
58
				final ListeImageCarnet photoData ;
44
 
59
 
45
				final JSONValue responseValue = JSONParser.parse(responseText);
60
				final JSONValue responseValue = JSONParser.parse(responseText);
46
				if (responseValue.isArray() != null) {
61
				if (responseValue.isArray() != null) {
47
					
62
					
48
					final JSONArray reponse = responseValue.isArray();
63
					final JSONArray reponse = responseValue.isArray();
49
 
64
 
50
					final int taillemax = reponse.size();
65
					final int taillemax = reponse.size();
51
					photoData = new ListeImageCarnet(taillemax);
66
					photoData = new ListeImageCarnet(taillemax);
52
					
67
					
53
					
68
					
54
					for (int j = 0; j < taillemax ; j++) {
69
					for (int j = 0; j < taillemax ; j++) {
55
						
70
						
56
						JSONObject image = (JSONObject)reponse.get(j) ;
71
						JSONObject image = (JSONObject)reponse.get(j) ;
57
						
72
						
58
						ImageCarnet im = new ImageCarnet(image) ;
73
						ImageCarnet im = new ImageCarnet(image) ;
59
						
74
						
60
						photoData.put(im.getOrdre(),im) ;
75
						photoData.put(im.getOrdre(),im) ;
61
						
76
						
62
					}
77
					}
63
				}
78
				}
64
				else
79
				else
65
				{
80
				{
66
					if(responseValue.isObject() != null)
81
					if(responseValue.isObject() != null)
67
					{
82
					{
68
						photoData = new ListeImageCarnet(1);
83
						photoData = new ListeImageCarnet(1);
69
						ImageCarnet im = new ImageCarnet(responseValue.isObject()) ;
84
						ImageCarnet im = new ImageCarnet(responseValue.isObject()) ;
70
						photoData.put(im.getOrdre(),im) ;
85
						photoData.put(im.getOrdre(),im) ;
71
					}
86
					}
72
					else
87
					else
73
					{
88
					{
74
						photoData = new ListeImageCarnet(0) ;
89
						photoData = new ListeImageCarnet(0) ;
75
					}
90
					}
76
				}
91
				}
77
				
92
				
78
				r.rafraichir(photoData,true);
93
				r.rafraichir(photoData,true);
79
			}
94
			}
80
		});
95
		});
81
	}
96
	}
82
	
97
	
83
	public void SynchroniserBaseDeDonnees(ListeImageCarnet li)
98
	public void SynchroniserBaseDeDonnees(ListeImageCarnet li)
84
	{
99
	{
85
		for(Iterator listIt = li.keySet().iterator() ; listIt.hasNext() ;)
100
		for(Iterator listIt = li.keySet().iterator() ; listIt.hasNext() ;)
86
		{
101
		{
87
			String postData = "" ;
102
			String postData = "" ;
88
			
103
			
89
			ImageCarnet enCours = (ImageCarnet)li.get(listIt.next()) ;
104
			ImageCarnet enCours = (ImageCarnet)li.get(listIt.next()) ;
90
			
105
			
91
			for(Iterator imgIt = enCours.keySet().iterator();imgIt.hasNext();)
106
			for(Iterator imgIt = enCours.keySet().iterator();imgIt.hasNext();)
92
			{
107
			{
93
				String key = (String)imgIt.next() ;
108
				String key = (String)imgIt.next() ;
94
				String valeur = enCours.renvoyerValeurCorrecte(key) ;
109
				String valeur = enCours.renvoyerValeurCorrecte(key) ;
95
				valeur.replaceAll("'", "\'") ;
110
				valeur.replaceAll("'", "\'") ;
96
					postData += "&"+key+"="+enCours.renvoyerValeurCorrecte(key) ;
111
					postData += "&"+key+"="+enCours.renvoyerValeurCorrecte(key) ;
97
			
112
			
98
			}
113
			}
99
			
114
			
100
					HTTPRequest.asyncPost("jrest/inventoryImage/0/", postData, new ResponseTextHandler() {
115
					HTTPRequest.asyncPost("jrest/inventoryImage/0/", postData, new ResponseTextHandler() {
101
						public void onCompletion(String responseText) {
116
						public void onCompletion(String responseText) {
102
							
117
							
103
							
118
							
104
						}
119
						}
105
						
120
						
106
					}) ;
121
					}) ;
107
		}
122
		}
108
	}
123
	}
109
	
124
	
110
	public void supprimerBaseDeDonnees(String[] ids)
125
	public void supprimerBaseDeDonnees(String[] ids)
111
	{
126
	{
112
		String postData = "" ;
127
		String postData = "" ;
113
		postData += "&action=DELETE" ;
128
		postData += "&action=DELETE" ;
114
		
129
		
115
		String uid = "" ;
130
		String uid = "" ;
116
		
131
		
117
		for (int i = 0; i < ids.length; i++) {
132
		for (int i = 0; i < ids.length; i++) {
118
			
133
			
119
			uid += ids[i]+"," ;
134
			uid += ids[i]+"," ;
120
		}
135
		}
121
		
136
		
122
		
137
		
123
		HTTPRequest.asyncPost("jrest/inventoryImageList/"+iMediateur.getIdentifiant()+"/"+uid, postData, new ResponseTextHandler() {
138
		HTTPRequest.asyncPost("jrest/inventoryImageList/"+iMediateur.getIdentifiant()+"/"+uid, postData, new ResponseTextHandler() {
124
			public void onCompletion(String responseText) {
139
			public void onCompletion(String responseText) {
125
				
140
				
126
				iMediateur.rafraichirToutesVues() ;
141
				iMediateur.rafraichirToutesVues() ;
127
			}
142
			}
128
			
143
			
129
		}) ;
144
		}) ;
130
	}
145
	}
131
	
146
	
132
 
147
 
133
}
148
}