source: ether_megapoli/trunk/web/resources/jsp/megapoliHead.jsp @ 253

Last change on this file since 253 was 253, checked in by vmipsl, 13 years ago

login

File size: 13.4 KB
Line 
1<%@ page import="com.medias.Context" %>
2
3<script type="text/javascript">
4var InterfaceTemplate = Class.create( {
5
6    initialize: function()
7    {
8        /** *********** CONTAINERS *********** **/
9        this.containerTitle = $( "#title" );
10        this.containerTools = $( "#tools" );
11        this.containerMenuData = $( "#menuData" );
12
13        /** *********** VARIABLES *********** **/
14        this.isLanguageFr = <%=Context.getLangue(request).equals( "fr" )%>;
15        this.path = "<%=request.getContextPath()%>";
16        this.webmaster = "<%=Context.getWebmaster(request)%>";
17        this.relativePageUri = <%=request.getQueryString() != null%> ? "<%=Context.getRelativePath( request )%>?<%=request.getQueryString()%>" : "<%=Context.getRelativePageURI(request)%>";
18        this.jSONUser = <%=Context.getJSONUser( request )%> ? <%=Context.getJSONUser( request )%> : false;
19        setJSONUser( this.jSONUser );
20        this.screenWidthLimit = 1336;
21
22        /** ************ CREATE ************ **/
23        this.createTitle();
24        this.createTools();
25        this.createMenuData();
26        this.createLeftSlides();
27    },
28
29    // CREATES ********************************************************
30    createTitle: function()
31    {
32        this.containerTitle.addClass( "containerTitle" );
33        this.containerTitle.html( templateTexts["app.fulltitle"] );
34    },
35
36    createTools: function()
37    {
38        this.createLoginForm();
39        this.createLogin();
40        var mailButton = new Button( {value:templateTexts["data.upload.metadata.contact.mail"], parent:this.containerTools, id:"button_mail", className: "blue_button", classNameText:"blue_button_text", onClick:jQuery.proxy( this.onClickMail, this )} );
41
42        var valueLanguage = templateTexts["app.fr"];
43        if( this.isLanguageFr )
44            valueLanguage = templateTexts["app.en"];
45
46        var languageButton = new Button( {value:valueLanguage, parent:this.containerTools, id:"button_language", className: "blue_button", classNameText:"blue_button_text", onClick:jQuery.proxy( this.onClickLanguage, this )} );
47        var homeButton = new Button( {value:templateTexts["app.home"], parent:this.containerTools, id:"button_home", className: "blue_button", classNameText:"blue_button_text", onClick:this.onClickHome} );
48
49        var divSmallLogoEther = $( document.createElement( "div" ) );
50        divSmallLogoEther.attr( {id:"smallLogoEther", class:"containerSmallLogoEther"} );
51        divSmallLogoEther.append( '<a href="http://ether.ipsl.jussieu.fr" target="help"><img src="resources/images/logo_Ether.jpg" width="40px" height="40px"/></a>' );
52        this.containerTools.append( divSmallLogoEther );
53
54        this.updateLogoEther();
55    },
56
57    createLogin: function()
58    {
59        var containerLoginButton = $( "#button_login" );
60
61        if( getJSONUser() )
62        {
63            var textLogin = getJSONUser().name + " " + getJSONUser().firstName;
64            if( getJSONUser().role && "coordinateur" == getJSONUser().role )
65                textLogin += " (" + templateTexts["app.admin"] + ")";
66
67            var loginButton = new ComplexButton( {value:textLogin, parent:this.containerTools, id:"button_login"} );
68
69            $( "#button_login #button_middle #button_text" ).addClass( "containerUserLogout" );
70
71            var loginMiddle = $( "#button_login #button_middle" );
72            var divImgLogout = $( document.createElement( "div" ) );
73            divImgLogout.addClass( "containerImgLogout" );
74            divImgLogout.append( "<img src='resources/images/utils/logout.png' width='15px' height='15px/>" );
75            divImgLogout.bind( "click", jQuery.proxy( this.onClickLogout, this ) );
76            loginMiddle.append( divImgLogout );
77        }
78        else
79        {
80            var loginButton = new ComplexButton( {value:templateTexts["app.connexion"], parent:this.containerTools, id:"button_login"} );
81
82            var loginMiddle = $( "#button_login #button_middle" );
83            loginMiddle.empty();
84            loginMiddle.attr( {id:"topnav", class:"topnav complexButton_middle"} );
85            var aLogin = $( document.createElement( "a" ) );
86            aLogin.attr( {id:"button_login_a", href:"login", class:"signin"} );
87            aLogin.html( "<span>" + templateTexts["app.connexion"] + "</span>" );
88            loginMiddle.append( aLogin );
89
90            $( document ).ready( function()
91            {
92                $( ".signin" ).click( function( e )
93                {
94                    e.preventDefault();
95                    $( "fieldset#signin_menu" ).toggle();
96                    $( ".signin" ).toggleClass( "menu-open" );
97                } );
98
99                $( "fieldset#signin_menu" ).mouseup( function()
100                {
101                    return false
102                } );
103
104                $( document ).mouseup( function( e )
105                {
106                    if( $( e.target ).parent( "a.signin" ).length == 0 )
107                    {
108                        $( ".signin" ).removeClass( "menu-open" );
109                        $( "fieldset#signin_menu" ).hide();
110                    }
111                } );
112            } );
113
114            $( function()
115            {
116                $( '#forgot_username_link' ).tipsy( {gravity: 'w'} );
117            } );
118        }
119    },
120
121    createLoginForm: function()
122    {
123        var containerLoginForm = $( document.createElement( "fieldset" ) );
124        containerLoginForm.attr( {id:"signin_menu"} );
125        this.containerTools.append( containerLoginForm );
126
127        var labelLogin = $( document.createElement( "label" ) );
128        labelLogin.attr( {for:"login"} );
129        labelLogin.append( templateTexts["data.authentification.login"] );
130        var inputLogin = $( document.createElement( "input" ) );
131        inputLogin.attr( {id:"login", name:"login", tabIndex:"4", type:"text"} );
132        containerLoginForm.append( labelLogin );
133        containerLoginForm.append( inputLogin );
134
135        var labelPwd = $( document.createElement( "label" ) );
136        labelPwd.attr( {for:"pwd"} );
137        labelPwd.append( templateTexts["data.authentification.pwd"] );
138        var inputPwd = $( document.createElement( "input" ) );
139        inputPwd.attr( {id:"pwd", name:"pwd", tabIndex:"5", type:"password"} );
140        containerLoginForm.append( labelPwd );
141        containerLoginForm.append( inputPwd );
142
143        var inputSubmitP = $( document.createElement( "p" ) );
144        inputSubmitP.addClass( "remember" );
145        var inputSubmit = $( document.createElement( "input" ) );
146        inputSubmit.attr( {id:"signin_submit", value:templateTexts["data.authentification.sign"], tabIndex:"6", type:"submit"} );
147        inputSubmit.bind( "click", jQuery.proxy( this.onClickLogin, this ) );
148        inputSubmitP.append( inputSubmit );
149        containerLoginForm.append( inputSubmitP );
150
151        var inputForgotP = $( document.createElement( "p" ) );
152        inputForgotP.addClass( "forgot" );
153        var aForgot = $( document.createElement( "a" ) );
154        aForgot.attr( {id:"resend_password_link", href:"mailto:${webmaster}?subject=[MEGAPOLI] login"} );
155        aForgot.append( templateTexts["data.authentification.pwdForget"] );
156        inputForgotP.append( aForgot );
157        containerLoginForm.append( inputForgotP );
158
159        var inputForgotUNP = $( document.createElement( "p" ) );
160        inputForgotUNP.addClass( "username" );
161        var aForgot = $( document.createElement( "a" ) );
162        aForgot.attr( {id:"forgot_username_link", href:"mailto:${webmaster}?subject=[MEGAPOLI] password", title:templateTexts["data.authentification.loginForget.help"]} );
163        aForgot.append( templateTexts["data.authentification.loginForget"] );
164        inputForgotUNP.append( aForgot );
165        containerLoginForm.append( inputForgotUNP );
166
167        var divErrors = $( document.createElement( "div" ) );
168        divErrors.attr( {id:"errors", class:"containerErrors"} );
169        containerLoginForm.append( divErrors );
170    },
171
172    createMenuData: function()
173    {
174        this.containerMenuData.empty();
175
176        var ulData = $( document.createElement( "ul" ) );
177        this.containerMenuData.append( ulData );
178
179        var liExtract = $( document.createElement( "li" ) );
180        var aExtract = $( document.createElement( "a" ) );
181        aExtract.html( "<span>" + templateTexts["data.access.extract.short"] + "</span>" );
182        liExtract.append( aExtract );
183        ulData.append( liExtract );
184        var liDownload = $( document.createElement( "li" ) );
185        var aDownload = $( document.createElement( "a" ) );
186        aDownload.html( "<span>" + templateTexts["data.upload.short"] + "</span>" );
187        liDownload.append( aDownload );
188        ulData.append( liDownload );
189
190        if( getJSONUser() )
191        {
192            aExtract.attr( {href:"DataAccess.do"} );
193            aDownload.attr( {href:"PrepareTree.do"} );
194        }
195        else
196        {
197            aExtract.attr( {href:"project?methodName=viewLogin"} );
198            aDownload.attr( {href:"project?methodName=viewLogin"} );
199        }
200    },
201
202    createLeftSlides: function()
203    {
204        var divSlideCredits = new Slide( { contentId:"slideContentCredits", buttonId: "slideCredits", parent:$( "#creditSlide" ), isIndexToChange:true,
205            contentButton:"<img src='resources/icons/man_credits.gif' width='50px' height='50px'/><br/>" , contentSlide:"CREDDDDIIITS"} );
206
207        var divSlideMentions = new Slide( { contentId:"slideContentMentions", buttonId: "slideMentions", parent:$( "#mentionSlide" ),specificButtonClass:"containerSlideButtonMentions", isIndexToChange:true,
208            contentButton:"<img src='resources/icons/man_mentions_2.png' width='50px' height='50px'/><br/>", contentSlide:"MENTIIIOOONNSS"} );
209
210        var divSlideInfos = new Slide( { contentId:"slideContentInfos", buttonId: "slideInfos", parent:$( "#infoSlide" ), specificButtonClass:"containerSlideButtonInfos", isIndexToChange:true,
211            contentButton:"<img src='resources/icons/man_info.gif' width='50px' height='50px'/>", contentSlide:"IINNFFFOOOOSSS"} );
212    },
213
214    // REQUESTS ********************************************************
215    requestLogin: function()
216    {
217        // TODO : passer en crypter ces infos !!!!!
218        var login = $( "#login" ).val();
219        var pwd = $( "#pwd" ).val();
220        $.ajax( {
221            url: "project?methodName=login&login=" + login + "&pwd=" + pwd,
222            success:jQuery.proxy( this.onHandleLogin, this )
223        } );
224    },
225
226    requestLogout: function()
227    {
228        $.ajax( {
229            url: "project?methodName=logout",
230            success:jQuery.proxy( this.onHandleLogout, this )
231        } );
232    },
233
234    // HANDLES ********************************************************
235    onHandleLogin: function( result )
236    {
237        this.errors = jQuery.parseJSON( result ).errors;
238        setJSONUser( null != jQuery.parseJSON( result ).jSONPeople ? jQuery.parseJSON( result ).jSONPeople : false );
239        if( null == this.errors )
240            this.updateLogin();
241        else
242            displayLoginErrors( templateTexts[this.errors] );
243    },
244
245    onHandleLogout: function( result )
246    {
247        this.errors = jQuery.parseJSON( result ).errors;
248        if( null == this.errors )
249        {
250            setJSONUser( false );
251            this.updateLogin();
252        }
253        else
254            displayLoginErrors( templateTexts[this.errors] );
255    },
256
257    // EVENTS ********************************************************
258    onClickHome: function()
259    {
260        document.location.href = "index.jsp";
261    },
262
263    onClickLogin: function()
264    {
265        $( "#errors" ).hide();
266        this.requestLogin();
267    },
268
269    onClickLogout: function()
270    {
271        this.requestLogout();
272    },
273
274    onClickLanguage: function()
275    {
276        if( this.isLanguageFr )
277            document.location.href = this.path + "/English.do?requestUri=" + this.relativePageUri;
278        else
279            document.location.href = this.path + "/French.do?requestUri=" + this.relativePageUri;
280    },
281
282    onClickMail: function()
283    {
284        document.location.href = "mailto:" + this.webmaster + "?subject=[MEGAPOLI]";
285    },
286
287    /**
288     * This method display a small Ether logo if the screen is too small to contain the big one
289     */
290    updateLogoEther: function()
291    {
292        if( this.screenWidthLimit > innerWidth )
293        {
294            $( "#logoEther" ).hide();
295            $( "#linkLogoEther" ).hide();
296            $( "#smallLogoEther" ).show();
297        }
298        else
299        {
300            $( "#logoEther" ).show();
301            $( "#linkLogoEther" ).show();
302            $( "#smallLogoEther" ).hide();
303        }
304    },
305
306    updateLogin: function()
307    {
308        this.containerTools.empty();
309        this.createTools();
310        this.createMenuData();
311    }
312} );
313
314/** *********************************************** **/
315/** ******************** LOGIN ******************** **/
316/** *********************************************** **/
317function displayLoginErrors( text )
318{
319    $( "#errors" ).show();
320    $( "#errors" ).html( text );
321}
322
323function showLogin( text )
324{
325    if( $( "fieldset#signin_menu" ) && $( ".signin" ) )
326    {
327        $( "fieldset#signin_menu" ).toggle();
328        $( ".signin" ).toggleClass( "menu-open" );
329        if( text )
330            displayLoginErrors( text );
331    }
332    else
333        alert( templateTexts["data.authentification.text"] );
334}
335
336/** *********************************************** **/
337/** ******************** USER ********************* **/
338/** *********************************************** **/
339function getJSONUser()
340{
341    return InterfaceTemplate.jSONUser;
342}
343
344function setJSONUser( user )
345{
346    InterfaceTemplate.jSONUser = user;
347}
348</script>
Note: See TracBrowser for help on using the repository browser.