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

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

BO insertion données

File size: 12.4 KB
Line 
1<script type="text/javascript">
2var interfaceBOMco = Class.create( {
3
4    initialize: function( requestNumber, jSonRequests, jSonRequestStates, jSonRequestTypes )
5    {
6        // Values
7        this.jSonRequests = jSonRequests || null;
8        this.jSonRequestStates = jSonRequestStates || null;
9        this.jSonRequestTypes = jSonRequestTypes || null;
10        this.request = false;
11        this.nbRequests = requestNumber || false;
12
13        // Containers
14        this.generalContainerRequests = $( "#generalContainerRequests" );
15        this.containerRequests = $( "#containerRequests" );
16        this.containerAddOrModifyTitle = $( "#addOrModifyTitle" );
17        this.containerErrors = $( "#errors" );
18        this.containerRequestsNumber = $( "#nbResults" );
19
20        this.containerSorts = $( "#containerSorts" );
21        this.containerSortsStates = $( "#containerSorts_states" );
22        this.containerSortsTypes = $( "#containerSorts_types" );
23        this.containerSortsDisplay = $( "#containerSorts_display" );
24        this.containerPage = $( "#page" );
25        this.containerMaxPage = $( "#maxPages" );
26
27        /** *********** LOADING *********** **/
28        // Create loading object for users
29        var param = new Object();
30        param.id = "loadingForRequest";
31        param.parent = this.generalContainerRequests;
32        this.loadingRequest = new Loading( param );
33        this.loadingRequest.display();
34
35        this.containerErrors.hide();
36        this.updateAddRequestButtonAndTitle();
37        this.displaySorts();
38        this.managePartAddOrModify();
39        this.managePagination();
40        this.displayRequests();
41    },
42
43    // REQUESTS ********************************************************
44    requestAddRequest: function()
45    {
46        if( !this.verifyFields() )
47        {
48            var parametersUrl = "code=" + stripVowelAccent( $( "#code" ).val() ) + "&email=" + $( "#email" ).val() + "&state=" + this.selectStates.getValue() + "&type=" + this.selectTypes.getValue() +
49                    "&title=" + stripVowelAccent( $( "#titleRequest" ).val() ) + "&informations=" + stripVowelAccent( $( "#informations" ).val() );
50            var request = $.ajax( {
51                url: "backoffice?methodName=addRequest&" + parametersUrl,
52                success:jQuery.proxy( this.handleRequest, this ),
53                error: jQuery.proxy( this.showErrors, [this] )
54            } );
55        }
56    },
57
58    requestCloseRequest: function()
59    {
60        if( this.request )
61            $.ajax( {
62                url: "backoffice?methodName=closeRequest&id=" + this.request.id,
63                success:jQuery.proxy( this.handleRequest, this )
64            } );
65    },
66
67    requestRemoveRequest: function()
68    {
69        if( this.request )
70            $.ajax( {
71                url: "backoffice?methodName=removeRequest&id=" + this.request.id,
72                success:jQuery.proxy( this.handleRequest, this )
73            } );
74    },
75
76    requestModifyRequest: function()
77    {
78        if( this.request && !this.verifyFields() )
79        {
80            var parametersUrl = "id=" + this.request.id + "&code=" + stripVowelAccent( $( "#code" ).val() ) + "&email=" + $( "#email" ).val() +
81                    "&type=" + this.selectTypes.getValue() + "&state=" + this.selectStates.getValue() + "&title=" + stripVowelAccent( $( "#titleRequest" ).val() ) + "&informations=" + stripVowelAccent( $( "#informations" ).val() );
82            $.ajax( {
83                url: "backoffice?methodName=modifyRequest&" + parametersUrl,
84                success:jQuery.proxy( this.handleRequest, this ),
85                error: jQuery.proxy( this.showErrors, [this] )
86            } );
87        }
88    },
89
90    requestSortRequest: function()
91    {
92        var parametersUrl = "sort=" + this.selectSorts.getValue() + "&sortState=" + this.selectSortsStates.getValue() + "&sortType=" + this.selectSortsTypes.getValue() +
93                "&searchText=" + $( "#search_text" ).val() +
94                "&maxResults=" + this.selectSortsDisplay.getValue() + "&page=" + this.containerPage.html();
95        var request = $.ajax( {
96            url: "backoffice?methodName=sortRequest&" + parametersUrl,
97            success:jQuery.proxy( this.handleSortRequest, this ),
98            error: jQuery.proxy( this.showErrors, [this] )
99        } );
100    },
101
102    // HANDLES ********************************************************
103    handleRequest: function()
104    {
105        this.requestSortRequest();
106    },
107
108    handleSortRequest: function( result )
109    {
110        this.jSonRequests = jQuery.parseJSON( result ).jSonRequests;
111        this.nbRequests = jQuery.parseJSON( result ).requestNumber;
112        this.displayRequests();
113        this.clearAddOrModifyRequestFields();
114        this.updateAddRequestButtonAndTitle();
115    },
116
117    // DISPLAYS ********************************************************
118    displayTRForRequest: function( request )
119    {
120        var tr = $( document.createElement( "tr" ) );
121        var tdId = $( document.createElement( "td" ) );
122        tdId.html( request.id );
123        tr.append( tdId );
124        var tdType = $( document.createElement( "td" ) );
125        tdType.html( interfaceTexts[request.type] );
126        tr.append( tdType );
127        var tdCode = $( document.createElement( "td" ) );
128        tdCode.html( request.code );
129        tr.append( tdCode );
130        var tdCreationDate = $( document.createElement( "td" ) );
131        tdCreationDate.html( formatDate( new Date( request.creationDate.time ) ) );
132        tr.append( tdCreationDate );
133        var tdEmail = $( document.createElement( "td" ) );
134        tdEmail.html( request.emailUser );
135        tr.append( tdEmail );
136        var tdState = $( document.createElement( "td" ) );
137        tdState.html( interfaceTexts[request.state] );
138        tr.append( tdState );
139        var tdClosingDate = $( document.createElement( "td" ) );
140//        if( request.closingDate )
141//            tdClosingDate.html( formatDate( new Date( request.closingDate.time ) ) );
142//        tr.append( tdClosingDate );
143        return tr;
144    },
145
146    displayRequests: function()
147    {
148        this.containerRequests.empty();
149
150        if( this.jSonRequests && 0 < this.jSonRequests.length )
151        {
152            jQuery.each( this.jSonRequests, jQuery.proxy( function( i, request )
153            {
154                var tr = this.displayTRForRequest( request );
155
156                // Buttons
157                var tdModify = $( document.createElement( "td" ) );
158                new Button( {value:interfaceTexts["bo.modify"], parent:tdModify, id:"button_modify", className: "small positive action_button", contextToSave: request, onClick:jQuery.proxy( this.onClickModify, this )} );
159                tr.append( tdModify );
160
161                var tdClose = $( document.createElement( "td" ) );
162                new Button( {value:interfaceTexts["bo.close"], parent:tdClose, id:"button_close", className: "small action_button", contextToSave: request, onClick:jQuery.proxy( this.onClickClose, this )} );
163                tr.append( tdClose );
164
165                var tdRemove = $( document.createElement( "td" ) );
166                new Button( {value:interfaceTexts["bo.remove"], parent:tdRemove, id:"button_remove", className: "small negative action_button", contextToSave: request, onClick:jQuery.proxy( this.onClickRemove, this )} );
167                tr.append( tdRemove );
168
169                this.containerRequests.append( tr );
170
171            }, this ) );
172        }
173        else
174        {
175            var tr = $( document.createElement( "tr" ) );
176            var td = $( document.createElement( "td" ) );
177            td.attr( {colspan:"11"} );
178            td.html( "<center><BR/>" + interfaceTexts["bo.noRequest"] + "<BR/><BR/></center>" );
179            tr.append( td );
180            this.containerRequests.append( tr );
181        }
182
183        // Update number of users and max pages
184        this.containerRequestsNumber.html( this.nbRequests );
185        this.containerMaxPage.html( Math.ceil( this.nbRequests / this.selectSortsDisplay.getValue() ) );
186        this.loadingRequest.hide();
187    },
188
189    displaySorts: function()
190    {
191        // Sort by name, email, ...
192        var paramSelect = new Object();
193        paramSelect.id = "select_sorts";
194        paramSelect.parent = this.containerSorts;
195        this.selectSorts = new Select( paramSelect );
196        this.selectSorts.add( "jeuId", interfaceTexts["bo.id"] );
197        this.selectSorts.add( "jeuDateinser", interfaceTexts["bo.user.creationDate"] );
198        this.selectSorts.selectFirst( false );
199
200        // Sort by state
201        var paramSelect = new Object();
202        paramSelect.id = "select_sorts_states";
203        paramSelect.parent = this.containerSortsStates;
204        this.selectSortsStates = new Select( paramSelect );
205        this.selectSortsStates.add( "ALL", interfaceTexts["bo.all"] );
206        jQuery.each( this.jSonRequestStates, jQuery.proxy( function ( i, jSonRequestState )
207        {
208            this.selectSortsStates.add( jSonRequestState.value, interfaceTexts[jSonRequestState.text] );
209        }, this ) );
210        this.selectSortsStates.selectFirst( false );
211
212        // Sort by type
213        var paramSelect = new Object();
214        paramSelect.id = "select_sorts_types";
215        paramSelect.parent = this.containerSortsTypes;
216        this.selectSortsTypes = new Select( paramSelect );
217        this.selectSortsTypes.add( "ALL", interfaceTexts["bo.all"] );
218        jQuery.each( this.jSonRequestTypes, jQuery.proxy( function ( i, jSonRequestType )
219        {
220            this.selectSortsTypes.add( jSonRequestType.value, interfaceTexts[jSonRequestType.text] );
221        }, this ) );
222        this.selectSortsTypes.selectFirst( false );
223
224        // Number of displays
225        var paramSelect = new Object();
226        paramSelect.id = "select_sorts_display";
227        paramSelect.parent = this.containerSortsDisplay;
228        this.selectSortsDisplay = new Select( paramSelect );
229        this.selectSortsDisplay.add( "5", 5 );
230        this.selectSortsDisplay.add( "10", 10 );
231        this.selectSortsDisplay.add( "15", 15 );
232        this.selectSortsDisplay.add( "20", 20 );
233        this.selectSortsDisplay.selectFirst( false );
234
235        // Button sort
236        $( "#sortButton" ).bind( 'click', this, jQuery.proxy( this.onClickSort, this ) );
237    },
238
239    // EVENTS ********************************************************
240    onClickModify: function( request )
241    {
242        this.request = request;
243        $( "#code" ).val( request.code );
244        $( "#creationDate" ).val( formatDate( new Date( request.creationDate.time ) ) );
245        if( request.closingDate )
246            $( "#closingDate" ).val( formatDate( new Date( request.closingDate.time ) ) );
247        $( "#email" ).val( request.emailUser );
248        $( "#titleRequest" ).val( request.title );
249        $( "#informations" ).val( request.informations );
250        this.selectTypes.select( request.type, false );
251        this.selectStates.select( request.state, false );
252
253        this.updateModifyRequestButtonAndTitle( request.id );
254    },
255
256    onClickClose: function( request )
257    {
258        this.request = request;
259        jQuery.proxy( this.requestCloseRequest(), this );
260    },
261
262    onClickRemove: function( request )
263    {
264        this.request = request;
265        if( window.confirm( interfaceTexts["bo.mco.remove.confirm"] + " " + request.code + " ?" ) )
266            jQuery.proxy( this.requestRemoveRequest(), this );
267    },
268
269    onClickInit: function()
270    {
271        this.updateAddRequestButtonAndTitle();
272        this.clearAddOrModifyRequestFields();
273    },
274
275    onClickSort: function()
276    {
277        this.containerPage.html( 1 );
278        this.requestSortRequest();
279    },
280
281    onClickPrevious: function()
282    {
283        decrementPage( this.containerPage, this.containerMaxPage );
284        this.requestSortRequest();
285    },
286
287    onClickNext: function()
288    {
289        incrementPage( this.containerPage, this.containerMaxPage );
290        this.requestSortRequest();
291    },
292
293    // OTHERS ********************************************************
294    showErrors: function( result )
295    {
296        var context = this[0];
297        var text = this[1];
298        context.containerErrors.show();
299        if( text )
300            context.containerErrors.html( interfaceTexts[result.responseText] + " " + text );
301        else
302            context.containerErrors.html( interfaceTexts[result.responseText] );
303    },
304
305    managePagination: function()
306    {
307        $( "#previous" ).bind( 'click', this, jQuery.proxy( this.onClickPrevious, this ) );
308        $( "#next" ).bind( 'click', this, jQuery.proxy( this.onClickNext, this ) );
309    }
310
311} );
312
313
314</script>
Note: See TracBrowser for help on using the repository browser.