Subversion Repositories eFlore/Archives.cel-v2

Rev

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

Rev 18 Rev 22
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.gwtext.client.data.ArrayReader;
16
import com.gwtext.client.data.ArrayReader;
16
import com.gwtext.client.data.FieldDef;
17
import com.gwtext.client.data.FieldDef;
17
import com.gwtext.client.data.MemoryProxy;
18
import com.gwtext.client.data.MemoryProxy;
18
import com.gwtext.client.data.RecordDef;
19
import com.gwtext.client.data.RecordDef;
19
import com.gwtext.client.data.Store;
20
import com.gwtext.client.data.Store;
20
import com.gwtext.client.data.StringFieldDef;
21
import com.gwtext.client.data.StringFieldDef;
21
 
22
 
22
/**
23
/**
23
 * 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
24
 * répondant à des critères donné
25
 * répondant à des critères donné
25
 * @author aurelien
26
 * @author aurelien
26
 *
27
 *
27
 */
28
 */
28
public class ListeImageAsynchroneDAO {
29
public class ListeImageAsynchroneDAO {
29
	
30
	
30
	ImageMediateur iMediateur = null ;
31
	ImageMediateur iMediateur = null ;
31
	
32
	
32
	public void setIMediateur(ImageMediateur im)
33
	public void setIMediateur(ImageMediateur im)
33
	{
34
	{
34
		iMediateur = im ;
35
		iMediateur = im ;
35
	}
36
	}
36
	
37
	
37
	public void ObtenirListeImages(final Rafraichissable r)
38
	public void ObtenirListeImages(final Rafraichissable r)
38
	{
39
	{
39
		HTTPRequest.asyncGet("jrest/inventoryImageList/1/ci_publiable_eflore=0", new ResponseTextHandler() {
40
		HTTPRequest.asyncGet("jrest/inventoryImageList/1/ci_publiable_eflore=0", new ResponseTextHandler() {
40
			public void onCompletion(String responseText) {
41
			public void onCompletion(String responseText) {
41
				
42
				
42
				final ListeImage photoData ;
43
				final ListeImageCarnet photoData ;
43
 
44
 
44
				final JSONValue responseValue = JSONParser.parse(responseText);
45
				final JSONValue responseValue = JSONParser.parse(responseText);
45
				if (responseValue.isArray() != null) {
46
				if (responseValue.isArray() != null) {
46
					
47
					
47
					final JSONArray reponse = responseValue.isArray();
48
					final JSONArray reponse = responseValue.isArray();
48
 
49
 
49
					final int taillemax = reponse.size();
50
					final int taillemax = reponse.size();
50
					photoData = new ListeImage(taillemax);
51
					photoData = new ListeImageCarnet(taillemax);
51
					
52
					
52
					
53
					
53
					for (int j = 0; j < taillemax ; j++) {
54
					for (int j = 0; j < taillemax ; j++) {
54
						
55
						
55
						JSONObject image = (JSONObject)reponse.get(j) ;
56
						JSONObject image = (JSONObject)reponse.get(j) ;
56
						
57
						
57
						ImageCarnet im = new ImageCarnet(image) ;
58
						ImageCarnet im = new ImageCarnet(image) ;
58
						
59
						
59
						photoData.put(im.getOrdre(),im) ;
60
						photoData.put(im.getOrdre(),im) ;
60
						
61
						
61
					}
62
					}
62
				}
63
				}
63
				else
64
				else
64
				{
65
				{
65
					if(responseValue.isObject() != null)
66
					if(responseValue.isObject() != null)
66
					{
67
					{
67
						photoData = new ListeImage(1);
68
						photoData = new ListeImageCarnet(1);
68
						ImageCarnet im = new ImageCarnet(responseValue.isObject()) ;
69
						ImageCarnet im = new ImageCarnet(responseValue.isObject()) ;
69
						photoData.put(im.getOrdre(),im) ;
70
						photoData.put(im.getOrdre(),im) ;
70
					}
71
					}
71
					else
72
					else
72
					{
73
					{
73
						photoData = null ;
74
						photoData = new ListeImageCarnet(0) ;
74
					}
75
					}
75
				}
76
				}
76
				
77
				
77
				r.rafraichir(photoData,true);
78
				r.rafraichir(photoData,true);
78
			}
79
			}
79
		});
80
		});
80
	}
81
	}
81
	
82
	
82
	public void SynchroniserBaseDeDonnees(ListeImage li)
83
	public void SynchroniserBaseDeDonnees(ListeImageCarnet li)
83
	{
84
	{
84
		for(Iterator it = li.keySet().iterator() ; it.hasNext() ;)
85
		for(Iterator listIt = li.keySet().iterator() ; listIt.hasNext() ;)
-
 
86
		{
85
		{
87
			String postData = "" ;
-
 
88
			
-
 
89
			ImageCarnet enCours = (ImageCarnet)li.get(listIt.next()) ;
-
 
90
			
-
 
91
			System.out.println(enCours.toString()+"\n");
-
 
92
			
-
 
93
			for(Iterator imgIt = enCours.keySet().iterator();imgIt.hasNext();)
-
 
94
			{
-
 
95
				String key = (String)imgIt.next() ;
-
 
96
				String valeur = enCours.renvoyerValeurCorrecte(key) ;
-
 
97
				valeur.replaceAll("'", "\'") ;
-
 
98
					postData += "&"+key+"="+enCours.renvoyerValeurCorrecte(key) ;
-
 
99
			
-
 
100
			}
-
 
101
			
86
					
102
			//System.out.println(postData);
-
 
103
					HTTPRequest.asyncPost("jrest/inventoryImage/0/", postData, new ResponseTextHandler() {
-
 
104
						public void onCompletion(String responseText) {
-
 
105
							
-
 
106
							
-
 
107
						}
-
 
108
						
-
 
109
					}) ;
-
 
110
		}
-
 
111
	}
-
 
112
	
-
 
113
	public void supprimerBaseDeDonnees(String[] ids)
-
 
114
	{
-
 
115
		String postData = "" ;
-
 
116
		postData += "&action=DELETE" ;
-
 
117
		
-
 
118
		String uid = "" ;
-
 
119
		
-
 
120
		for (int i = 0; i < ids.length; i++) {
-
 
121
			
87
		//	HTTPRequest.asyncPost("jrest/inventoryImageList/1/", postData, handler)
122
			uid += ids[i]+"," ;
-
 
123
		}
-
 
124
		
-
 
125
		
-
 
126
		HTTPRequest.asyncPost("jrest/inventoryImageList/0/"+uid, postData, new ResponseTextHandler() {
-
 
127
			public void onCompletion(String responseText) {
-
 
128
				
-
 
129
				iMediateur.rafraichirToutesVues() ;
-
 
130
			}
-
 
131
			
88
		}
132
		}) ;
89
	}
133
	}
90
	
134
	
91
 
135
 
92
}
136
}