1 | <%@ page import="java.io.File" %> |
---|
2 | <script type="text/javascript"> |
---|
3 | var interfaceBODataInsertion = Class.create( { |
---|
4 | |
---|
5 | initialize: function( simulationFiles, simulationDirectories ) |
---|
6 | { |
---|
7 | // Values |
---|
8 | this.files = simulationFiles || null; |
---|
9 | this.directories = simulationDirectories || null; |
---|
10 | |
---|
11 | // Containers |
---|
12 | this.containerFileList_left = $( "#fileList_left" ); |
---|
13 | this.containerFileList_right = $( "#fileList_right" ); |
---|
14 | this.generalContainerSimulations = $( "#generalContainerSimulations" ); |
---|
15 | // this.containerDatasetsNumber = $( "#nbResults" ); |
---|
16 | this.containerErrors = $( "#errors" ); |
---|
17 | // this.containerDatasets = $( "#containerDataSets" ); |
---|
18 | // this.containerResultRemove = $( "#containerResultRemove" ); |
---|
19 | // this.containerMove = $( "#containerMove" ); |
---|
20 | // this.containerResultMove = $( "#containerResultMove" ); |
---|
21 | // this.containerInsert = $( "#containerInsert" ); |
---|
22 | // this.containerResultInsert = $( "#containerResultInsert" ); |
---|
23 | // |
---|
24 | // this.containerSorts = $( "#containerSorts" ); |
---|
25 | // this.containerSortsDisplay = $( "#containerSorts_display" ); |
---|
26 | // this.containerPage = $( "#page" ); |
---|
27 | // this.containerMaxPage = $( "#maxPages" ); |
---|
28 | |
---|
29 | /** *********** LOADING *********** **/ |
---|
30 | // Create loading object for simulations |
---|
31 | var param = new Object(); |
---|
32 | param.id = "loadingForDataset"; |
---|
33 | param.parent = this.generalContainerSimulations; |
---|
34 | this.loadingDataset = new Loading( param ); |
---|
35 | this.loadingDataset.display(); |
---|
36 | |
---|
37 | this.containerErrors.hide(); |
---|
38 | this.displayFiles(); |
---|
39 | // this.displaySorts(); |
---|
40 | // this.managePagination(); |
---|
41 | // this.displayDatasets(); |
---|
42 | |
---|
43 | // Bind buttons |
---|
44 | $( "#ncdumpButton" ).bind( 'click', this, jQuery.proxy( this.onClickLaunchNcDump, this ) ); |
---|
45 | // $( "#cleanLocalisationAndFlagButton" ).bind( 'click', this, jQuery.proxy( this.onClickCleanLocalisationAndFlag, this ) ); |
---|
46 | }, |
---|
47 | |
---|
48 | // REQUESTS ******************************************************** |
---|
49 | requestSortDataset: function() |
---|
50 | { |
---|
51 | var parametersUrl = "sort=" + this.selectSorts.getValue() + |
---|
52 | "&searchText=" + $( "#search_text" ).val() + |
---|
53 | "&maxResults=" + this.selectSortsDisplay.getValue() + "&page=" + this.containerPage.html(); |
---|
54 | var request = $.ajax( { |
---|
55 | url: "backoffice?methodName=sortJeu&" + parametersUrl, |
---|
56 | success:jQuery.proxy( this.handleSortDataset, this ), |
---|
57 | error: jQuery.proxy( this.showErrors, [this] ) |
---|
58 | } ); |
---|
59 | }, |
---|
60 | |
---|
61 | requestLaunchNcDump: function() |
---|
62 | { |
---|
63 | $.ajax( { |
---|
64 | url: "backoffice?methodName=launchNCDumpInSimulationDirectory", |
---|
65 | success:jQuery.proxy( this.handleLaunchNcDump, this ), |
---|
66 | error: jQuery.proxy( this.showErrors, [this] ) |
---|
67 | } ); |
---|
68 | }, |
---|
69 | |
---|
70 | requestInsertHeader: function( directoryName ) |
---|
71 | { |
---|
72 | $.ajax( { |
---|
73 | url: "backoffice?methodName=insertHeader&directoryName=" + directoryName, |
---|
74 | success:jQuery.proxy( this.handleInsertHeader, this ), |
---|
75 | error: jQuery.proxy( this.showErrors, [this] ) |
---|
76 | } ); |
---|
77 | }, |
---|
78 | |
---|
79 | // HANDLES ******************************************************** |
---|
80 | handleSortDataset: function( result ) |
---|
81 | { |
---|
82 | this.jSonDatasets = jQuery.parseJSON( result ).jSonDatasets; |
---|
83 | this.nbDatasets = jQuery.parseJSON( result ).datasetNumber; |
---|
84 | this.displayDatasets(); |
---|
85 | }, |
---|
86 | |
---|
87 | handleLaunchNcDump: function( result ) |
---|
88 | { |
---|
89 | this.files = jQuery.parseJSON( result ).simulationFiles; |
---|
90 | this.directories = jQuery.parseJSON( result ).simulationDirectories; |
---|
91 | this.displayFiles(); |
---|
92 | }, |
---|
93 | |
---|
94 | handleInsertHeader: function( result ) |
---|
95 | { |
---|
96 | // this.files = jQuery.parseJSON( result ).simulationFiles; |
---|
97 | // this.directories = jQuery.parseJSON( result ).simulationDirectories; |
---|
98 | // this.displayFiles(); |
---|
99 | }, |
---|
100 | |
---|
101 | // DISPLAYS ******************************************************** |
---|
102 | displayFiles: function() |
---|
103 | { |
---|
104 | this.containerFileList_left.empty(); |
---|
105 | this.containerFileList_right.empty(); |
---|
106 | var number = this.files.length; |
---|
107 | jQuery.each( this.directories, jQuery.proxy( function( i, directory ) |
---|
108 | { |
---|
109 | var divDirectory = $( document.createElement( "div" ) ); |
---|
110 | var divDirectoryName = $( document.createElement( "div" ) ); |
---|
111 | divDirectoryName.attr( {style:"float:left"} ); |
---|
112 | divDirectoryName.html( "- " + directory + " " ); |
---|
113 | divDirectory.append( divDirectoryName ); |
---|
114 | |
---|
115 | var button = $( document.createElement( "button" ) ); |
---|
116 | button.addClass( "small negative" ); |
---|
117 | button.html( interfaceTexts["bo.simulation.save.header"] ); |
---|
118 | button.bind( 'click', [this, directory], jQuery.proxy( this.onClickInsertHeader, this ) ); |
---|
119 | divDirectory.append( button ); |
---|
120 | |
---|
121 | this.containerFileList_left.append( divDirectory ); |
---|
122 | }, this ) ); |
---|
123 | |
---|
124 | jQuery.each( this.files, jQuery.proxy( function( i, file ) |
---|
125 | { |
---|
126 | this.containerFileList_right.append( " - " + file + "<BR/>" ); |
---|
127 | }, this ) ); |
---|
128 | }, |
---|
129 | |
---|
130 | displayTRForDataset: function( dataset ) |
---|
131 | { |
---|
132 | var tr = $( document.createElement( "tr" ) ); |
---|
133 | var tdId = $( document.createElement( "td" ) ); |
---|
134 | tdId.html( dataset.id ); |
---|
135 | tr.append( tdId ); |
---|
136 | var tdCategory = $( document.createElement( "td" ) ); |
---|
137 | tdCategory.html( dataset.categoryName ); |
---|
138 | tr.append( tdCategory ); |
---|
139 | var tdName = $( document.createElement( "td" ) ); |
---|
140 | tdName.html( dataset.name ); |
---|
141 | tr.append( tdName ); |
---|
142 | var tdCreationDate = $( document.createElement( "td" ) ); |
---|
143 | tdCreationDate.html( formatDate( new Date( dataset.creationDate.time ) ) ); |
---|
144 | tr.append( tdCreationDate ); |
---|
145 | return tr; |
---|
146 | }, |
---|
147 | |
---|
148 | displayDatasets: function() |
---|
149 | { |
---|
150 | this.containerDatasets.empty(); |
---|
151 | |
---|
152 | if( this.jSonDatasets && 0 < this.jSonDatasets.length ) |
---|
153 | { |
---|
154 | jQuery.each( this.jSonDatasets, jQuery.proxy( function( i, dataset ) |
---|
155 | { |
---|
156 | var tr = this.displayTRForDataset( dataset ); |
---|
157 | |
---|
158 | // Buttons |
---|
159 | var tdRemove = $( document.createElement( "td" ) ); |
---|
160 | new Button( {value:interfaceTexts["bo.remove"], parent:tdRemove, id:"button_remove", className: "small negative action_button", contextToSave: dataset, onClick:jQuery.proxy( this.onClickRemove, this )} ); |
---|
161 | tr.append( tdRemove ); |
---|
162 | |
---|
163 | this.containerDatasets.append( tr ); |
---|
164 | |
---|
165 | }, this ) ); |
---|
166 | } |
---|
167 | else |
---|
168 | { |
---|
169 | var tr = $( document.createElement( "tr" ) ); |
---|
170 | var td = $( document.createElement( "td" ) ); |
---|
171 | td.attr( {colspan:"4"} ); |
---|
172 | td.html( "<center><BR/>" + interfaceTexts["bo.noDataset"] + "<BR/><BR/></center>" ); |
---|
173 | tr.append( td ); |
---|
174 | this.containerDatasets.append( tr ); |
---|
175 | } |
---|
176 | |
---|
177 | // Update number of users and max pages |
---|
178 | this.containerDatasetsNumber.html( this.nbDatasets ); |
---|
179 | this.containerMaxPage.html( Math.ceil( this.nbDatasets / this.selectSortsDisplay.getValue() ) ); |
---|
180 | this.loadingDataset.hide(); |
---|
181 | }, |
---|
182 | |
---|
183 | displaySorts: function() |
---|
184 | { |
---|
185 | // Sort by name, email, ... |
---|
186 | var paramSelect = new Object(); |
---|
187 | paramSelect.id = "select_sorts"; |
---|
188 | paramSelect.parent = this.containerSorts; |
---|
189 | this.selectSorts = new Select( paramSelect ); |
---|
190 | this.selectSorts.add( "jeuId", interfaceTexts["bo.id"] ); |
---|
191 | this.selectSorts.add( "categorieName", interfaceTexts["bo.category"] ); |
---|
192 | this.selectSorts.add( "jeuNom", interfaceTexts["bo.name"] ); |
---|
193 | this.selectSorts.add( "jeuDateinser", interfaceTexts["bo.user.creationDate"] ); |
---|
194 | this.selectSorts.selectFirst( false ); |
---|
195 | |
---|
196 | // Number of displays |
---|
197 | var paramSelect = new Object(); |
---|
198 | paramSelect.id = "select_sorts_display"; |
---|
199 | paramSelect.parent = this.containerSortsDisplay; |
---|
200 | this.selectSortsDisplay = new Select( paramSelect ); |
---|
201 | this.selectSortsDisplay.add( "5", 5 ); |
---|
202 | this.selectSortsDisplay.add( "10", 10 ); |
---|
203 | this.selectSortsDisplay.add( "15", 15 ); |
---|
204 | this.selectSortsDisplay.add( "20", 20 ); |
---|
205 | this.selectSortsDisplay.selectFirst( false ); |
---|
206 | |
---|
207 | // Button sort |
---|
208 | $( "#sortButton" ).bind( 'click', this, jQuery.proxy( this.onClickSort, this ) ); |
---|
209 | }, |
---|
210 | |
---|
211 | displayFilesMove: function() |
---|
212 | { |
---|
213 | if( this.dataset && this.dataset.categoryName ) |
---|
214 | { |
---|
215 | this.containerMove.html( "MOVE <span style='color:#FBE3E4'>" + this.downloadDirectory + "<%=File.separatorChar%>" + this.dataset.categoryName + "<%=File.separatorChar%>" + this.dataset.name + "<%=File.separatorChar%>* </span> <BR/>" + |
---|
216 | "TO <span style='color:#FBE3E4'>" + this.uploadDirectory + "<%=File.separatorChar%>" + this.dataset.categoryName + "<%=File.separatorChar%>" + this.dataset.name + "<%=File.separatorChar%>* </span>" ); |
---|
217 | |
---|
218 | new Button( {value:interfaceTexts["bo.move"], parent:this.containerMove, id:"button_move", className: "small negative action_button", onClick:jQuery.proxy( this.onClickMove, this )} ); |
---|
219 | this.containerMove.show(); |
---|
220 | } |
---|
221 | }, |
---|
222 | |
---|
223 | // EVENTS ******************************************************** |
---|
224 | onClickSort: function() |
---|
225 | { |
---|
226 | this.containerPage.html( 1 ); |
---|
227 | this.requestSortDataset(); |
---|
228 | }, |
---|
229 | |
---|
230 | onClickPrevious: function() |
---|
231 | { |
---|
232 | decrementPage( this.containerPage, this.containerMaxPage ); |
---|
233 | this.requestSortDataset(); |
---|
234 | }, |
---|
235 | |
---|
236 | onClickNext: function() |
---|
237 | { |
---|
238 | incrementPage( this.containerPage, this.containerMaxPage ); |
---|
239 | this.requestSortDataset(); |
---|
240 | }, |
---|
241 | |
---|
242 | onClickLaunchNcDump: function() |
---|
243 | { |
---|
244 | this.requestLaunchNcDump(); |
---|
245 | }, |
---|
246 | |
---|
247 | onClickInsertHeader: function( parameters ) |
---|
248 | { |
---|
249 | var context = parameters.data[0]; |
---|
250 | var directoryName = parameters.data[1]; |
---|
251 | this.requestInsertHeader( directoryName ); |
---|
252 | }, |
---|
253 | |
---|
254 | // OTHERS ******************************************************** |
---|
255 | showErrors: function( result ) |
---|
256 | { |
---|
257 | var context = this[0] ? this[0] : this; |
---|
258 | var text = this[1]; |
---|
259 | context.loadingDataset.hide(); |
---|
260 | context.loadingInsert.hide(); |
---|
261 | context.loadingRemove.hide(); |
---|
262 | context.containerErrors.show(); |
---|
263 | if( text ) |
---|
264 | context.containerErrors.html( interfaceTexts[result.responseText] + " " + text ); |
---|
265 | else if( interfaceTexts[result.responseText] ) |
---|
266 | context.containerErrors.html( interfaceTexts[result.responseText] ); |
---|
267 | else if( result.responseText ) |
---|
268 | context.containerErrors.html( result.responseText ); |
---|
269 | else |
---|
270 | context.containerErrors.html( result ); |
---|
271 | }, |
---|
272 | |
---|
273 | managePagination: function() |
---|
274 | { |
---|
275 | $( "#previous" ).bind( 'click', this, jQuery.proxy( this.onClickPrevious, this ) ); |
---|
276 | $( "#next" ).bind( 'click', this, jQuery.proxy( this.onClickNext, this ) ); |
---|
277 | }, |
---|
278 | |
---|
279 | hideRemove: function() |
---|
280 | { |
---|
281 | this.loadingRemove.hide(); |
---|
282 | this.containerResultRemove.hide(); |
---|
283 | }, |
---|
284 | |
---|
285 | hideMove: function() |
---|
286 | { |
---|
287 | this.containerResultMove.hide(); |
---|
288 | }, |
---|
289 | |
---|
290 | hideInsert: function() |
---|
291 | { |
---|
292 | this.loadingInsert.hide(); |
---|
293 | this.containerResultInsert.hide(); |
---|
294 | } |
---|
295 | |
---|
296 | } ); |
---|
297 | |
---|
298 | |
---|
299 | </script> |
---|