source: ether_statistics/web/project/statistics-script.jsp @ 685

Last change on this file since 685 was 685, checked in by *, 12 years ago

statistiques, clean, log4j

File size: 20.6 KB
Line 
1<%@ page import="com.ether.WebHelper" %>
2<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
3
4<script type="text/javascript">
5
6var InterfaceStatistics = Class.create( {
7    initialize: function()
8    {
9        /** *********** CONTAINERS *********** **/
10        this.parent = $( "#containerMiddle" );
11        this.containerMenu = $( "#menuLogo" );
12        this.containerErrors = $( "#errors" );
13
14        /** *********** VARIABLES *********** **/
15        this.language = '<spring:message code="language"/>';
16        this.webmaster = "<%=WebHelper.getProperty(request, "mail.webmaster")%>";
17        this.jSONUser = <%=WebHelper.getJSONUser( request )%> ? <%=WebHelper.getJSONUser( request )%> : false;
18        this.logoSizeSmall = 30;
19        this.logoSizeBig = 50;
20
21        this.projectsArray = [
22            {id:"ETHER", img:"logo_Ether_50.jpg", top:"-16px", left:"125px"},
23            {id:"NDACC", img:"logo_Ndacc_50.jpg", top:"1.66667px", left:"46.3334px"},
24            {id:"ECCAD", img:"logo_ECCAD_50.gif", top:"39.3333px", left:"109.333px"},
25            {id:"IASI", img:"logo_iasi_50.jpg", top:"-78.6667px", left:"77.6666px"},
26            {id:"GOSAT", img:"logo_gosat_50.jpg", top:"-0.333328px", left:"200.667px"},
27            {id:"IAGOS", img:"logo_Iagos_50.jpg", top:"36px", left:"138px"},
28            {id:"TROPICO", img:"logo_tropico_50.jpg", top:"-74px", left:"45px"},
29            {id:"MEGAPOLI", img:"logo_Megapoli_50.png", top:"-74.3333px", left:"15.3333px"},
30            {id:"MIMOSA", img:"logo_mimosa_50.png", top:"-45.6667px", left:"76.3334px"},
31            {id:"REPROBUS", img:"logo_reprobus_50.png", top:"-48px", left:"161.667px"},
32            {id:"GEISA", img:"logo_geisa_50.jpg", top:"22px", left:"167.667px"},
33            {id:"TAPAS", img:"logo_tapas_50.png", top:"58.3333px", left:"125px"},
34            {id:"OUTREACH", img:"logo_acomida_50.jpg", top:"-77.3333px", left:"225px"},
35            {id:"OMER7A", img:"logo_omer7A_50.jpg", top:"22.6667px", left:"76.3334px"},
36            {id:"GIRAFE", img:"logo_girafe_50.JPG", top:"-79.6667px", left:"192.333px"},
37            {id:"ARLETTY", img:"logo_arletty_50.jpg", top:"-79px", left:"161.667px"}
38        ];
39        this.widthInitMentionsOrCredits = $( "#mentions" ).width();
40
41        this.xArray = ["2010-10", "2010-11", "2010-12", "2011-01", "2011-02"];
42        this.yArray = [0, 10, 30, 50, 100];
43
44        this.bindButtons();
45        this.createMenuLogo();
46
47        $( document ).ready( jQuery.proxy( function()
48        {
49            $( ".containerToDrag" ).draggable();
50            // Menu
51            this.animateMenuLogos();
52            this.bindMenuLogos();
53            this.createRightSlide();
54
55            if( !this.jSONUser )
56                this.onClickHelp();
57            else
58                this.handleLogin();
59        }, this ) );
60    },
61
62
63    // CREATES AND BINDS ********************************************************
64    bindButtons: function()
65    {
66        $( "#home_button" ).bind( "dblclick", this.onClickHome );
67        $( "#language_button" ).bind( "dblclick", jQuery.proxy( this.onClickLanguage, this ) );
68        $( "#mail_button" ).bind( "dblclick", jQuery.proxy( this.onClickMail, this ) );
69        $( "#help" ).bind( "click", jQuery.proxy( this.onClickHelp, this ) );
70        $( "#credits" ).bind( "dblclick", jQuery.proxy( this.onClickCredits, this ) );
71        $( "#mentions" ).bind( "dblclick", jQuery.proxy( this.onClickMentions, this ) );
72        $( "#login_button" ).bind( "click", jQuery.proxy( this.onClickLogin, this ) );
73        $( "#logout_button" ).bind( "dblclick", jQuery.proxy( this.onClickLogout, this ) );
74    },
75
76    createMenuLogo: function()
77    {
78        var initTop = this.projectsArray[0].top;
79        var initLeft = this.projectsArray[0].left;
80
81        jQuery.each( this.projectsArray, jQuery.proxy( function( i, logo )
82        {
83            var divLogo = $( document.createElement( "div" ) );
84            divLogo.addClass( "divLogo containerToDrag" );
85            divLogo.attr( {id:logo.id, style:"position:absolute; top:" + initTop + "; left:" + initLeft} );
86            divLogo.html( '<img id="img_' + logo.id + '"src="resources/images/' + logo.img + '" width="' + this.logoSizeSmall + 'px" height="' + this.logoSizeSmall + 'px"/>' );
87            this.containerMenu.append( divLogo );
88        }, this ) );
89    },
90
91    createAllSlides: function()
92    {
93        this.middleSlide = new DragSlide( {id:"middle", parent:this.parent, width:"700", height:"480", top:"150px", left:"38px",
94            specificClass:"containerStatistics", specificTitleClass:"containerStatisticsTitle", specificContentClass:"containerStatisticsContent"} );
95
96        this.rightSlide = new DragSlide( {id:"right", parent:this.parent, width:"180", height:"320", top:"175px", left:"750px",
97            specificClass:"containerStatistics", specificTitleClass:"containerStatisticsTitle", specificContentClass:"containerStatisticsContent"} );
98
99        this.loginSlide = new DragSlide( {id:"loginMiddle", parent:this.parent, width:"150", height:"25", top:"115px", left:"39px",
100            specificClass:"containerStatistics", specificTitleClass:"containerStatisticsTitle", specificContentClass:"containerStatisticsContent", activeDbClick:"None"} );
101    },
102
103    createRightSlide: function()
104    {
105//        this.rightSlide = new DragSlide( {id:"right", parent:this.parent, width:"200", height:"270", top:"210px", left:"698px",
106//            specificClass:"containerStatistics", specificTitleClass:"containerStatisticsTitle", specificContentClass:"containerStatisticsContent"} );
107        this.rightSlide = new DragSlide( {id:"right", parent:this.parent, width:"180", height:"320", top:"175px", left:"750px",
108            specificClass:"containerStatistics", specificTitleClass:"containerStatisticsTitle", specificContentClass:"containerStatisticsContent"} );
109    },
110
111    // REQUESTS ********************************************************
112    requestChangeLocale: function()
113    {
114        $.ajax( {
115            url: "project?methodName=setLocale&language=<spring:message code="label.language.value.to.switch"/>",
116            success:function()
117            {
118                location.reload();
119            },
120            error: jQuery.proxy( this.showErrors, [this] )
121        } );
122    },
123
124    requestLogin: function()
125    {
126        var login = $( "#loginValue" ).val();
127        var pwd = $( "#pwdValue" ).val();
128        $.ajax( {
129            url: "project?methodName=login&login=" + login + "&pwd=" + pwd,
130            dataType: 'json', // Info needed since jquery.1.7 !!
131            success:jQuery.proxy( this.handleLogin, this ),
132            error: jQuery.proxy( this.showErrors, [this, "489px", "566px"] )
133        } );
134    },
135
136    requestLogout: function()
137    {
138        $.ajax( {
139            url: "project?methodName=logout",
140            dataType: 'json', // Info needed since jquery.1.7 !!
141            success:jQuery.proxy( this.handleLogout, this ),
142            error: jQuery.proxy( this.showErrors, [this] )
143        } );
144    },
145
146    requestDataByLogo: function()
147    {
148        if( !this.selectedLogo && !this.selectedLogo.id )
149            return;
150
151        $.ajax( {
152            url: "statistic?methodName=searchMainStatisticsByProject&name=" + this.selectedLogo.id,
153            success:jQuery.proxy( this.handleDataByLogo, this ),
154            error: jQuery.proxy( this.showLoginError, this )
155        } );
156    },
157
158    // HANDLES ********************************************************
159    handleDataByLogo: function( result )
160    {
161        this.displaySummary();
162    },
163
164    handleLogin: function( result )
165    {
166        this.containerErrors.empty();
167        this.containerErrors.css( "visibility", "hidden" );
168
169        if( result )
170            this.jSONUser = result.jSONUser;
171
172        $( "#loginValue" ).val( "" );
173        $( "#pwdValue" ).val( "" );
174        $( "#login_text" ).css( "visibility", "hidden" );
175        $( "#login" ).animate( {
176            top:'47px',
177            left:'577px'
178        }, 2000, function()
179        {
180        } );
181
182        $( "#login_bg" ).animate( {
183            opacity: 1,
184            height:'60px',
185            width:'67px'
186        }, 2000, function()
187        {
188        } );
189
190        $( "#login_img" ).animate( {
191            top:'25px',
192            left: '16px',
193            width: '0',
194            height: '0'
195        }, 2000, jQuery.proxy( function()
196        {
197            // Slides
198            this.parent.empty();
199            this.createAllSlides();
200            this.changeRightSlide();
201
202            // User
203            if( this.jSONUser.name )
204                this.loginSlide.setTitle( this.jSONUser.name );
205            else
206                this.loginSlide.setTitle( '<spring:message code="label.unknown"/>' );
207            $( "#logout_button" ).css( "visibility", "visible" );
208
209            // Awstats button
210            if( "ADMINISTRATOR" == this.jSONUser.role )
211            {
212                this.awstatsSlide = new DragSlide( {id:"awstats", parent:this.parent, width:"120", height:"25", top:"114px", left:"197px",
213                    specificTitleClass:"containerStatisticsTitle", specificContentClass:"containerStatisticsContent",
214                    title:'<spring:message code="label.awstats"/>&nbsp;&nbsp;', activeDbClick:"None"} );
215                this.awstatsSlide.getDivContainer().dblclick( jQuery.proxy( this.displayAwstatsStatistics, this ) );
216            }
217
218            // Logo
219            this.selectedLogo = $( "#ETHER" )[0];
220            this.isSelectedLogoEther = true;
221            this.onClickLogo();
222        }, this ) );
223    },
224
225    handleLogout: function()
226    {
227        this.jSONUser = false;
228        this.parent.empty();
229        this.createRightSlide();
230        this.onClickHelp();
231
232        $( "#logout_button" ).css( "visibility", "hidden" );
233        $( "#login" ).css( { zIndex:1 } ).animate( {
234            top:'79px',
235            left:'88px'
236        }, 2000, function()
237        {
238        } );
239
240        $( "#login_bg" ).animate( {
241            opacity: 0.85,
242            height:'500px',
243            width:'500px'
244        }, 2000, function()
245        {
246            $( "#login_text" ).css( "visibility", "visible" );
247        } );
248
249        $( "#login_img" ).animate( {
250            top:'103px',
251            left: '148px',
252            width: '30px',
253            height: '30px'
254        }, 2000, function()
255        {
256        } );
257    },
258
259    // EVENTS ********************************************************
260    onClickHome: function()
261    {
262        location.reload();
263    },
264
265    onClickLanguage: function()
266    {
267        this.requestChangeLocale();
268    },
269
270    onClickMail: function()
271    {
272        document.location.href = "mailto:" + this.webmaster + "?subject=[STATISTICS]";
273    },
274
275    onClickMentions: function()
276    {
277        if( this.widthInitMentionsOrCredits == $( "#mentions" ).width() )
278            this.enlargeCreditsOrMentions( $( "#mentions" ), $( "#mentions_bg" ), $( "#mentions_text" ), $( "#mentions_title" ), "project/mentions_" + this.language + ".jsp" );
279        else
280            this.reduceCreditsOrMentions( $( "#mentions" ), $( "#mentions_bg" ), $( "#mentions_text" ), $( "#mentions_title" ), "project/mentions_" + this.language + ".jsp" );
281    },
282
283    onClickCredits: function()
284    {
285        if( this.widthInitMentionsOrCredits == $( "#credits" ).width() )
286            this.enlargeCreditsOrMentions( $( "#credits" ), $( "#credits_bg" ), $( "#credits_text" ), $( "#credits_title" ), "project/credits_" + this.language + ".jsp" );
287        else
288            this.reduceCreditsOrMentions( $( "#credits" ), $( "#credits_bg" ), $( "#credits_text" ), $( "#credits_title" ), "project/credits_" + this.language + ".jsp" );
289    },
290
291    onClickHelp: function()
292    {
293        this.rightSlide.setTitle( '<spring:message code="label.help"/>' );
294        this.rightSlide.setContent( "<spring:message code='label.help.content'/>" );
295        if( this.jSONUser )
296            var backHelpButton = new Button( {value:"<spring:message code="label.display.actions"/>", parent:this.rightSlide.getDivContent(), className: "small positive back_button", onClick:jQuery.proxy( this.changeRightSlide, this )} );
297    },
298
299    onClickLogin: function()
300    {
301        this.containerErrors.empty();
302        this.containerErrors.css( "visibility", "hidden" );
303        this.requestLogin();
304    },
305
306    onClickLogout: function()
307    {
308        this.requestLogout();
309    },
310
311    onClickLogo: function()
312    {
313        this.isSelectedLogoEther = (this.selectedLogo == $( "#ETHER" )[0]);
314
315        if( this.jSONUser )
316            this.requestDataByLogo();
317        else
318        {
319            this.showErrors( "<spring:message code="error.connection.need"/>" );
320            this.containerErrors.css( {top:"489px", left:"566px"} );
321            this.containerErrors.css( "visibility", "visible" );
322        }
323    },
324
325    onClickPrint: function()
326    {
327        var printContent = new PrintContent();
328        printContent.addContent( $( "#title" ).clone() );
329        printContent.addContent( this.middleSlide.getDivContainer().clone().animate( {'marginLeft' : "+=120px"} ) );
330        printContent.displayPrintPreview();
331    },
332
333    // OTHERS ********************************************************
334    showErrors: function( result )
335    {
336        var context = this[0] ? this[0] : this;
337        var topValue = this[1] ? this[1] : false;
338        var leftValue = this[2] ? this[2] : false;
339        context.containerErrors.show();
340        if( result.responseText && interfaceTexts[result.responseText] )
341            context.containerErrors.html( interfaceTexts[result.responseText] );
342        else if( result.responseText )
343            context.containerErrors.html( result.responseText );
344        else
345            context.containerErrors.html( result );
346        if( topValue && leftValue )
347            context.containerErrors.css( {top: topValue, left: leftValue} );
348        context.containerErrors.css( "visibility", "visible" );
349    },
350
351    showLoginError: function( result )
352    {
353        this.onClickLogout();
354        this.onClickLogo();
355    },
356
357    reduceCreditsOrMentions: function( div, div_bg, div_text, div_title )
358    {
359        div.css( { zIndex:0 } );
360        div_text.css( "visibility", "hidden" );
361        div.animate( {
362            left: '+=500',
363            top: '+=500'
364        }, 2000, function()
365        {
366        } );
367        div_bg.animate( {
368            opacity: 1,
369            height:'42px',
370            width:this.widthInitMentionsOrCredits + 'px',
371            zIndex:'0'
372        }, 2000, function()
373        {
374            div_title.css( "visibility", "visible" );
375        } );
376    },
377
378    enlargeCreditsOrMentions: function( div, div_bg, div_text, div_title, pageToLoad )
379    {
380        div_title.css( "visibility", "hidden" );
381        div.css( { zIndex:1 } );
382        div.animate( {
383            left: '-=500',
384            top: '-=500'
385        }, 2000, function()
386        {
387        } );
388
389        div_bg.animate( {
390            opacity: 0.95,
391            height:'500px',
392            width:'500px'
393        }, 2000, function()
394        {
395            div_text.css( "visibility", "visible" );
396            div_text.load( pageToLoad );
397        } );
398    },
399
400    animateMenuLogos: function()
401    {
402        jQuery.each( this.projectsArray, jQuery.proxy( function( i, logo )
403        {
404            $( "#" + logo.id ).animate( {
405                top:logo.top,
406                left:logo.left
407            }, 5000, function()
408            {
409            } );
410        }, this ) );
411    },
412
413    bindMenuLogos: function()
414    {
415        var gap = (this.logoSizeBig - this.logoSizeSmall) / 2;
416        var logoSizeBig = this.logoSizeBig + "px";
417        var logoSizeSmall = this.logoSizeSmall + "px";
418        var gridimage;
419
420        $( '.divLogo' ).mouseover( function( element )
421        {
422            gridimage = $( this ).find( 'img' ); //Define target as a variable
423            gridimage.stop().animate( {
424                width: logoSizeBig,
425                height: logoSizeBig
426            }, 150 );
427            $( this ).animate( {
428                top: "-=10px",
429                left: "-=10px"
430            }, 150 );
431        } );
432
433        $( '.divLogo' ).mouseout( function( element )
434        {
435            $( this ).animate( {
436                top: "+=10px",
437                left: "+=10px"
438            }, 150 );
439            gridimage.stop().animate( {
440                width: logoSizeSmall,
441                height:logoSizeSmall
442            }, 150 );
443        } );
444
445        $( '.divLogo' ).dblclick( jQuery.proxy( function( element )
446        {
447            this.selectedLogo = element.currentTarget;
448            this.onClickLogo();
449        }, this ) );
450    },
451
452    changeRightSlide: function()
453    {
454        this.rightSlide.setTitle( '<spring:message code="label.actions"/>' );
455        this.rightSlide.getDivContent().empty();
456        new Button( {value:"<spring:message code="statistics.summary"/>", parent:this.rightSlide.getDivContent(), className: "positive action_button", onClick:jQuery.proxy( this.displaySummary, this )} );
457        new Button( {value:"<spring:message code="statistics.monthly"/>", parent:this.rightSlide.getDivContent(), className: "positive action_button", onClick:jQuery.proxy( this.displayMonthly, this )} );
458        new Button( {value:"<spring:message code="statistics.daily"/>", parent:this.rightSlide.getDivContent(), className: "positive action_button", onClick:jQuery.proxy( this.displayDaily, this )} );
459        new Button( {value:"<spring:message code="statistics.daysofweek"/>", parent:this.rightSlide.getDivContent(), className: "positive action_button", onClick:jQuery.proxy( this.displayDaysOfWeek, this )} );
460        new Button( {value:"<spring:message code="statistics.hours"/>", parent:this.rightSlide.getDivContent(), className: "positive action_button", onClick:jQuery.proxy( this.displayHours, this )} );
461        new Button( {value:"<spring:message code="statistics.visit.duration"/>", parent:this.rightSlide.getDivContent(), className: "positive action_button", onClick:jQuery.proxy( this.displayVisitDuration, this )} );
462
463        new Button( {value:"<spring:message code="statistics.visit"/>", parent:this.rightSlide.getDivContent(), className: "positive action_button", onClick:jQuery.proxy( this.displayVisit, this )} );
464        new Button( {value:"<spring:message code="statistics.domain"/>", parent:this.rightSlide.getDivContent(), className: "positive action_button", onClick:jQuery.proxy( this.displayDomainCountry, this )} );
465        new Button( {value:"<spring:message code="statistics.data.download"/>", parent:this.rightSlide.getDivContent(), className: "positive action_button", onClick:jQuery.proxy( this.displayDownload, this )} );
466
467        new Button( {value:"<spring:message code="label.print"/>", parent:this.rightSlide.getDivContent(), className: "blue export_button print-preview", onClick:jQuery.proxy( this.onClickPrint, this )} );
468    },
469
470    changeMiddleSlide: function( title, url )
471    {
472        this.middleSlide.setTitle( this.selectedLogo.id + ' : ' + title );
473        this.middleSlide.getDivContent().empty();
474
475        this.middleSlide.getDivContent().load( url + this.selectedLogo.id );
476    },
477
478
479    // STATISTICS ********************************************************
480    displaySummary: function()
481    {
482        this.changeMiddleSlide( '<spring:message code="statistics.summary"/>', <%=WebHelper.getProperty(request, "url.summary")%> );
483    },
484
485    displayMonthly: function()
486    {
487        this.changeMiddleSlide( '<spring:message code="statistics.monthly"/>', <%=WebHelper.getProperty(request, "url.monthly")%> );
488    },
489
490    displayDaily: function()
491    {
492        this.changeMiddleSlide( '<spring:message code="statistics.daily"/>', <%=WebHelper.getProperty(request, "url.daily")%> );
493    },
494
495    displayDaysOfWeek: function()
496    {
497        this.changeMiddleSlide( '<spring:message code="statistics.daysofweek"/>', <%=WebHelper.getProperty(request, "url.daysofweek")%> );
498    },
499
500    displayHours: function()
501    {
502        this.changeMiddleSlide( '<spring:message code="statistics.hours"/>', <%=WebHelper.getProperty(request, "url.hours")%> );
503    },
504
505    displayVisitDuration: function()
506    {
507        this.changeMiddleSlide( '<spring:message code="statistics.visit.duration"/>', <%=WebHelper.getProperty(request, "url.sessions")%> );
508    },
509
510    displayVisit: function()
511    {
512        this.changeMiddleSlide( '<spring:message code="statistics.visit"/>', <%=WebHelper.getProperty(request, "url.visited.pages")%> );
513    },
514
515    displayDomainCountry: function()
516    {
517        this.changeMiddleSlide( '<spring:message code="statistics.domain"/>', <%=WebHelper.getProperty(request, "url.domains")%> );
518    },
519
520    displayDownload: function()
521    {
522        this.changeMiddleSlide( '<spring:message code="statistics.data.download"/>', <%=WebHelper.getProperty(request, "url.downloads")%> );
523    },
524
525    displayAwstatsStatistics: function()
526    {
527        window.open( "http://www.pole-ether.fr/cgi-bin/awstats/awstats.pl?config=" + this.selectedLogo.id );
528    }
529
530} );
531
532</script>
Note: See TracBrowser for help on using the repository browser.