source: ether_megapoli/trunk/web/backoffice/dataInsertion-script.jsp @ 475

Last change on this file since 475 was 475, checked in by vmipsl, 12 years ago

BO insertion données _ move files

File size: 8.4 KB
Line 
1<%@ page import="com.medias.Context" %>
2<%@ page import="java.io.File" %>
3<script type="text/javascript">
4var interfaceBODataInsertion = Class.create( {
5
6    initialize: function( datasetNumber, jSonDatasets )
7    {
8        // Values
9        this.jSonDatasets = jSonDatasets || null;
10        this.dataset = false;
11        this.nbDatasets = datasetNumber || false;
12        this.downloadDirectory = '<%=Context.getProperty(request, "accessDir")%>';
13        this.uploadDirectory = '<%=Context.getProperty(request, "uploadDir")%>';
14
15        // Containers
16        this.generalContainerDatasets = $( "#generalContainerDatasets" );
17        this.containerDatasets = $( "#containerDataSets" );
18        this.containerErrors = $( "#errors" );
19        this.containerDatasetsNumber = $( "#nbResults" );
20        this.containerFilesMove = $( "#containerFilesMove" );
21        this.containerResultFilesMove = $( "#resultFilesMove" );
22
23        this.containerSorts = $( "#containerSorts" );
24        this.containerSortsDisplay = $( "#containerSorts_display" );
25        this.containerPage = $( "#page" );
26        this.containerMaxPage = $( "#maxPages" );
27
28        /** *********** LOADING *********** **/
29        // Create loading object for users
30        var param = new Object();
31        param.id = "loadingForDataset";
32        param.parent = this.generalContainerDatasets;
33        this.loadingDataset = new Loading( param );
34        this.loadingDataset.display();
35
36        this.containerErrors.hide();
37        this.displaySorts();
38        this.managePagination();
39        this.displayDatasets();
40    },
41
42    // REQUESTS ********************************************************
43    requestRemoveRequest: function()
44    {
45        if( this.dataset )
46            $.ajax( {
47                url: "backoffice?methodName=removeJeu&id=" + this.dataset.id,
48                success:jQuery.proxy( this.handleRequest, this )
49            } );
50    },
51
52    requestSortDataset: function()
53    {
54        var parametersUrl = "sort=" + this.selectSorts.getValue() +
55                "&searchText=" + $( "#search_text" ).val() +
56                "&maxResults=" + this.selectSortsDisplay.getValue() + "&page=" + this.containerPage.html();
57        var request = $.ajax( {
58            url: "backoffice?methodName=sortJeu&" + parametersUrl,
59            success:jQuery.proxy( this.handleSortRequest, this ),
60            error: jQuery.proxy( this.showErrors, [this] )
61        } );
62    },
63
64    requestFilesMove: function()
65    {
66        if( this.dataset )
67            $.ajax( {
68                url: "backoffice?methodName=moveJeu&id=" + this.dataset.id,
69                success:jQuery.proxy( this.handleFilesMove, this )
70            } );
71    },
72
73    // HANDLES ********************************************************
74    handleRequest: function()
75    {
76        this.requestSortDataset();
77    },
78
79    handleSortRequest: function( result )
80    {
81        this.jSonDatasets = jQuery.parseJSON( result ).jSonDatasets;
82        this.nbDatasets = jQuery.parseJSON( result ).datasetNumber;
83        this.displayDatasets();
84        this.displayFilesMove();
85    },
86
87    handleFilesMove: function( result )
88    {
89        this.containerResultFilesMove.html( "OK" );
90    },
91
92    // DISPLAYS ********************************************************
93    displayTRForDataset: function( dataset )
94    {
95        var tr = $( document.createElement( "tr" ) );
96        var tdId = $( document.createElement( "td" ) );
97        tdId.html( dataset.id );
98        tr.append( tdId );
99        var tdName = $( document.createElement( "td" ) );
100        tdName.html( dataset.name );
101        tr.append( tdName );
102        var tdCreationDate = $( document.createElement( "td" ) );
103        tdCreationDate.html( formatDate( new Date( dataset.creationDate.time ) ) );
104        tr.append( tdCreationDate );
105        return tr;
106    },
107
108    displayDatasets: function()
109    {
110        this.containerDatasets.empty();
111
112        if( this.jSonDatasets && 0 < this.jSonDatasets.length )
113        {
114            jQuery.each( this.jSonDatasets, jQuery.proxy( function( i, request )
115            {
116                var tr = this.displayTRForDataset( request );
117
118                // Buttons
119                var tdRemove = $( document.createElement( "td" ) );
120                new Button( {value:interfaceTexts["bo.remove"], parent:tdRemove, id:"button_remove", className: "small negative action_button", contextToSave: request, onClick:jQuery.proxy( this.onClickRemove, this )} );
121                tr.append( tdRemove );
122
123                this.containerDatasets.append( tr );
124
125            }, this ) );
126        }
127        else
128        {
129            var tr = $( document.createElement( "tr" ) );
130            var td = $( document.createElement( "td" ) );
131            td.attr( {colspan:"4"} );
132            td.html( "<center><BR/>" + interfaceTexts["bo.noDataset"] + "<BR/><BR/></center>" );
133            tr.append( td );
134            this.containerDatasets.append( tr );
135        }
136
137        // Update number of users and max pages
138        this.containerDatasetsNumber.html( this.nbDatasets );
139        this.containerMaxPage.html( Math.ceil( this.nbDatasets / this.selectSortsDisplay.getValue() ) );
140        this.loadingDataset.hide();
141    },
142
143    displaySorts: function()
144    {
145        // Sort by name, email, ...
146        var paramSelect = new Object();
147        paramSelect.id = "select_sorts";
148        paramSelect.parent = this.containerSorts;
149        this.selectSorts = new Select( paramSelect );
150        this.selectSorts.add( "jeuId", interfaceTexts["bo.id"] );
151        this.selectSorts.add( "jeuNom", interfaceTexts["bo.name"] );
152        this.selectSorts.add( "jeuDateinser", interfaceTexts["bo.user.creationDate"] );
153        this.selectSorts.selectFirst( false );
154
155        // Number of displays
156        var paramSelect = new Object();
157        paramSelect.id = "select_sorts_display";
158        paramSelect.parent = this.containerSortsDisplay;
159        this.selectSortsDisplay = new Select( paramSelect );
160        this.selectSortsDisplay.add( "5", 5 );
161        this.selectSortsDisplay.add( "10", 10 );
162        this.selectSortsDisplay.add( "15", 15 );
163        this.selectSortsDisplay.add( "20", 20 );
164        this.selectSortsDisplay.selectFirst( false );
165
166        // Button sort
167        $( "#sortButton" ).bind( 'click', this, jQuery.proxy( this.onClickSort, this ) );
168    },
169
170    displayFilesMove: function()
171    {
172        if( this.dataset && this.dataset.categoryName )
173        {
174            this.containerFilesMove.html( "MOVE <span style='color:#FBE3E4'>" + this.downloadDirectory + "<%=File.separatorChar%>" + this.dataset.categoryName + "<%=File.separatorChar%>" + this.dataset.name + "<%=File.separatorChar%>* </span> <BR/>" +
175                    "TO &nbsp;&nbsp;&nbsp;&nbsp; <span style='color:#FBE3E4'>" + this.uploadDirectory + "<%=File.separatorChar%>" + this.dataset.categoryName + "<%=File.separatorChar%>" + this.dataset.name + "<%=File.separatorChar%>* </span>" );
176
177            new Button( {value:interfaceTexts["bo.move"], parent:this.containerFilesMove, id:"button_move", className: "small negative action_button", onClick:jQuery.proxy( this.onClickMove, this )} );
178        }
179    },
180
181    // EVENTS ********************************************************
182    onClickRemove: function( dataset )
183    {
184        this.dataset = dataset;
185//        if( window.confirm( interfaceTexts["bo.dataset.remove.confirm"] + " " + dataset.name + " ?" ) )
186        jQuery.proxy( this.requestRemoveRequest(), this );
187    },
188
189    onClickSort: function()
190    {
191        this.containerPage.html( 1 );
192        this.requestSortDataset();
193    },
194
195    onClickPrevious: function()
196    {
197        decrementPage( this.containerPage, this.containerMaxPage );
198        this.requestSortDataset();
199    },
200
201    onClickNext: function()
202    {
203        incrementPage( this.containerPage, this.containerMaxPage );
204        this.requestSortDataset();
205    },
206
207    onClickMove: function()
208    {
209        this.requestFilesMove();
210    },
211
212    // OTHERS ********************************************************
213    showErrors: function( result )
214    {
215        var context = this[0];
216        var text = this[1];
217        context.containerErrors.show();
218        if( text )
219            context.containerErrors.html( interfaceTexts[result.responseText] + " " + text );
220        else
221            context.containerErrors.html( interfaceTexts[result.responseText] );
222    },
223
224    managePagination: function()
225    {
226        $( "#previous" ).bind( 'click', this, jQuery.proxy( this.onClickPrevious, this ) );
227        $( "#next" ).bind( 'click', this, jQuery.proxy( this.onClickNext, this ) );
228    }
229
230} );
231
232
233</script>
Note: See TracBrowser for help on using the repository browser.