Subversion Repositories eFlore/Archives.cel-v2

Rev

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

Rev 27 Rev 28
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)
39
	{
39
	{
40
		HTTPRequest.asyncGet("jrest/inventoryImageList/1/ci_publiable_eflore=0", new ResponseTextHandler() {
40
		HTTPRequest.asyncGet("jrest/inventoryImageList/1/ci_publiable_eflore=0", new ResponseTextHandler() {
41
			public void onCompletion(String responseText) {
41
			public void onCompletion(String responseText) {
42
				
42
				
43
				final ListeImageCarnet photoData ;
43
				final ListeImageCarnet photoData ;
44
 
44
 
45
				final JSONValue responseValue = JSONParser.parse(responseText);
45
				final JSONValue responseValue = JSONParser.parse(responseText);
46
				if (responseValue.isArray() != null) {
46
				if (responseValue.isArray() != null) {
47
					
47
					
48
					final JSONArray reponse = responseValue.isArray();
48
					final JSONArray reponse = responseValue.isArray();
49
 
49
 
50
					final int taillemax = reponse.size();
50
					final int taillemax = reponse.size();
51
					photoData = new ListeImageCarnet(taillemax);
51
					photoData = new ListeImageCarnet(taillemax);
52
					
52
					
53
					
53
					
54
					for (int j = 0; j < taillemax ; j++) {
54
					for (int j = 0; j < taillemax ; j++) {
55
						
55
						
56
						JSONObject image = (JSONObject)reponse.get(j) ;
56
						JSONObject image = (JSONObject)reponse.get(j) ;
57
						
57
						
58
						ImageCarnet im = new ImageCarnet(image) ;
58
						ImageCarnet im = new ImageCarnet(image) ;
59
						
59
						
60
						photoData.put(im.getOrdre(),im) ;
60
						photoData.put(im.getOrdre(),im) ;
61
						
61
						
62
					}
62
					}
63
				}
63
				}
64
				else
64
				else
65
				{
65
				{
66
					if(responseValue.isObject() != null)
66
					if(responseValue.isObject() != null)
67
					{
67
					{
68
						photoData = new ListeImageCarnet(1);
68
						photoData = new ListeImageCarnet(1);
69
						ImageCarnet im = new ImageCarnet(responseValue.isObject()) ;
69
						ImageCarnet im = new ImageCarnet(responseValue.isObject()) ;
70
						photoData.put(im.getOrdre(),im) ;
70
						photoData.put(im.getOrdre(),im) ;
71
					}
71
					}
72
					else
72
					else
73
					{
73
					{
74
						photoData = new ListeImageCarnet(0) ;
74
						photoData = new ListeImageCarnet(0) ;
75
					}
75
					}
76
				}
76
				}
77
				
77
				
78
				r.rafraichir(photoData,true);
78
				r.rafraichir(photoData,true);
79
			}
79
			}
80
		});
80
		});
81
	}
81
	}
82
	
82
	
83
	public void SynchroniserBaseDeDonnees(ListeImageCarnet li)
83
	public void SynchroniserBaseDeDonnees(ListeImageCarnet li)
84
	{
84
	{
85
		for(Iterator listIt = li.keySet().iterator() ; listIt.hasNext() ;)
85
		for(Iterator listIt = li.keySet().iterator() ; listIt.hasNext() ;)
86
		{
86
		{
87
			String postData = "" ;
87
			String postData = "" ;
88
			
88
			
89
			ImageCarnet enCours = (ImageCarnet)li.get(listIt.next()) ;
89
			ImageCarnet enCours = (ImageCarnet)li.get(listIt.next()) ;
90
			
90
			
91
			for(Iterator imgIt = enCours.keySet().iterator();imgIt.hasNext();)
91
			for(Iterator imgIt = enCours.keySet().iterator();imgIt.hasNext();)
92
			{
92
			{
93
				String key = (String)imgIt.next() ;
93
				String key = (String)imgIt.next() ;
94
				String valeur = enCours.renvoyerValeurCorrecte(key) ;
94
				String valeur = enCours.renvoyerValeurCorrecte(key) ;
95
				valeur.replaceAll("'", "\'") ;
95
				valeur.replaceAll("'", "\'") ;
96
					postData += "&"+key+"="+enCours.renvoyerValeurCorrecte(key) ;
96
					postData += "&"+key+"="+enCours.renvoyerValeurCorrecte(key) ;
97
			
97
			
98
			}
98
			}
99
			
99
			
100
					HTTPRequest.asyncPost("jrest/inventoryImage/0/", postData, new ResponseTextHandler() {
100
					HTTPRequest.asyncPost("jrest/inventoryImage/0/", postData, new ResponseTextHandler() {
101
						public void onCompletion(String responseText) {
101
						public void onCompletion(String responseText) {
102
							
102
							
103
							
103
							
104
						}
104
						}
105
						
105
						
106
					}) ;
106
					}) ;
107
		}
107
		}
108
	}
108
	}
109
	
109
	
110
	public void supprimerBaseDeDonnees(String[] ids)
110
	public void supprimerBaseDeDonnees(String[] ids)
111
	{
111
	{
112
		String postData = "" ;
112
		String postData = "" ;
113
		postData += "&action=DELETE" ;
113
		postData += "&action=DELETE" ;
114
		
114
		
115
		String uid = "" ;
115
		String uid = "" ;
116
		
116
		
117
		for (int i = 0; i < ids.length; i++) {
117
		for (int i = 0; i < ids.length; i++) {
118
			
118
			
119
			uid += ids[i]+"," ;
119
			uid += ids[i]+"," ;
120
		}
120
		}
121
		
121
		
122
		
122
		
123
		HTTPRequest.asyncPost("jrest/inventoryImageList/0/"+uid, postData, new ResponseTextHandler() {
123
		HTTPRequest.asyncPost("jrest/inventoryImageList/"+iMediateur.getIdentifiant()+"/"+uid, postData, new ResponseTextHandler() {
124
			public void onCompletion(String responseText) {
124
			public void onCompletion(String responseText) {
125
				
125
				
126
				iMediateur.rafraichirToutesVues() ;
126
				iMediateur.rafraichirToutesVues() ;
127
			}
127
			}
128
			
128
			
129
		}) ;
129
		}) ;
130
	}
130
	}
131
	
131
	
132
 
132
 
133
}
133
}