1 | <%@ page import="com.ether.Context" %> |
---|
2 | |
---|
3 | <script type="text/javascript"> |
---|
4 | var InterfaceTemplate = Class.create( { |
---|
5 | |
---|
6 | initialize: function() |
---|
7 | { |
---|
8 | /** *********** CONTAINERS *********** **/ |
---|
9 | this.containerTools = $( "#tools" ); |
---|
10 | this.containerLogin = $( "#loginModule" ); |
---|
11 | this.containerMenuData = $( "#menuData" ); |
---|
12 | |
---|
13 | /** *********** VARIABLES *********** **/ |
---|
14 | this.isLanguageFr = <%=Context.getLangue(request).equals( "fr" )%>; |
---|
15 | this.path = "<%=request.getContextPath()%>"; |
---|
16 | setPath( this.path ); |
---|
17 | this.webmaster = "<%=Context.getWebmaster(request)%>"; |
---|
18 | this.relativePageUri = <%=request.getQueryString() != null%> ? "<%=Context.getRelativePath( request )%>?<%=request.getQueryString()%>" : "<%=Context.getRelativePageURI(request)%>"; |
---|
19 | <%--this.jSONUser = <%=Context.getJSONUser( request )%> ? <%=Context.getJSONUser( request )%> : false;--%> |
---|
20 | |
---|
21 | /** ************ CREATE ************ **/ |
---|
22 | // this.createLogin(); |
---|
23 | this.createTools(); |
---|
24 | this.createMenuData(); |
---|
25 | this.updateLoginOrLogout(); |
---|
26 | }, |
---|
27 | |
---|
28 | // CREATES ******************************************************** |
---|
29 | createTools: function() |
---|
30 | { |
---|
31 | var mailButton = new Button( {value:templateTexts["label.mail"], parent:this.containerTools, id:"button_mail", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickMail, this )} ); |
---|
32 | |
---|
33 | var valueLanguage = templateTexts["label.language.fr"]; |
---|
34 | if( this.isLanguageFr ) |
---|
35 | valueLanguage = templateTexts["label.language.en"]; |
---|
36 | |
---|
37 | var languageButton = new Button( {value:valueLanguage, parent:this.containerTools, id:"button_language", className: "red_button", classNameText:"red_button_text", onClick:jQuery.proxy( this.onClickLanguage, this )} ); |
---|
38 | var homeButton = new Button( {value:templateTexts["label.home"], parent:this.containerTools, id:"button_home", className: "red_button", classNameText:"red_button_text", onClick:this.onClickHome} ); |
---|
39 | }, |
---|
40 | |
---|
41 | createLogin: function() |
---|
42 | { |
---|
43 | this.loginModule = new LoginButton( {parent:this.containerLogin, urlLogin:"project?methodName=login", urlLogout:"project?methodName=logout", isNeededInscription:true, callbackInscription:jQuery.proxy( this.onClickInscription, this ), anotherOnClickLogin:this.updateLoginOrLogout, anotherOnClickLogout:this.updateLoginOrLogout } ); |
---|
44 | this.loginModule.setJSONUser( this.jSONUser ); |
---|
45 | this.loginModule.display(); |
---|
46 | setLoginModule( this.loginModule ); |
---|
47 | }, |
---|
48 | |
---|
49 | createMenuData: function() |
---|
50 | { |
---|
51 | this.containerMenuData.empty(); |
---|
52 | |
---|
53 | var ulData = $( document.createElement( "ul" ) ); |
---|
54 | this.containerMenuData.append( ulData ); |
---|
55 | |
---|
56 | var liExtract = $( document.createElement( "li" ) ); |
---|
57 | liExtract.append( '<a onclick=\'javascript:neededLogin("/DataAccess.do")\'><span>' + templateTexts["data.access.extract.short"] + '</span></a>' ); |
---|
58 | ulData.append( liExtract ); |
---|
59 | |
---|
60 | var liDownload = $( document.createElement( "li" ) ); |
---|
61 | liDownload.append( '<a onclick=\'javascript:neededLogin("/PrepareTree.do")\'><span>' + templateTexts["data.upload.short"] + '</span></a>' ); |
---|
62 | ulData.append( liDownload ); |
---|
63 | }, |
---|
64 | |
---|
65 | // REQUESTS ******************************************************** |
---|
66 | |
---|
67 | // EVENTS ******************************************************** |
---|
68 | onClickHome: function() |
---|
69 | { |
---|
70 | document.location.href = "index.jsp"; |
---|
71 | }, |
---|
72 | |
---|
73 | onClickLanguage: function() |
---|
74 | { |
---|
75 | if( this.isLanguageFr ) |
---|
76 | document.location.href = this.path + "/English.do?requestUri=" + this.relativePageUri; |
---|
77 | else |
---|
78 | document.location.href = this.path + "/French.do?requestUri=" + this.relativePageUri; |
---|
79 | }, |
---|
80 | |
---|
81 | onClickMail: function() |
---|
82 | { |
---|
83 | document.location.href = "mailto:" + this.webmaster + "?subject=[TAPAS]"; |
---|
84 | }, |
---|
85 | |
---|
86 | onClickInscription: function() |
---|
87 | { |
---|
88 | var dataProtocol = "resources/jsp/dataProtocol_fr.jsp"; |
---|
89 | if( !this.isLanguageFr ) |
---|
90 | dataProtocol = "resources/jsp/dataProtocol_en.jsp"; |
---|
91 | |
---|
92 | var $dialog = $( '<div></div>' ) |
---|
93 | .load( dataProtocol ) |
---|
94 | .dialog( { |
---|
95 | autoOpen: false, |
---|
96 | title: loginTexts["login.inscription"], |
---|
97 | height: 800, |
---|
98 | width: 750 |
---|
99 | } ); |
---|
100 | $dialog.dialog( 'open' ); |
---|
101 | |
---|
102 | // TODO : see with $dialog.ready() to manage buttons |
---|
103 | }, |
---|
104 | |
---|
105 | updateLoginOrLogout: function() |
---|
106 | { |
---|
107 | <%--if( "<%=UserRole.ADMINISTRATOR%>" == getJSONUserRole() )--%> |
---|
108 | <%--$( "#button_bo" ).show();--%> |
---|
109 | <%--else--%> |
---|
110 | <%--$( "#button_bo" ).hide();--%> |
---|
111 | } |
---|
112 | |
---|
113 | } ); |
---|
114 | |
---|
115 | /** ******************************* **/ |
---|
116 | /** *********** ACCOUNT *********** **/ |
---|
117 | /** ******************************* **/ |
---|
118 | function onClickAcceptDataProtocol() |
---|
119 | { |
---|
120 | if( '' == $( "#lastName" ).val() || '' == $( "#email" ).val() || '' == $( "#password" ).val() ) |
---|
121 | { |
---|
122 | showErrorAccount( null, templateTexts["login.dataProtocolFields"] ); |
---|
123 | return; |
---|
124 | } |
---|
125 | |
---|
126 | if( $( "#checkboxUser" ).attr( 'checked' ) ) |
---|
127 | createAccount(); |
---|
128 | else |
---|
129 | showErrorAccount( null, templateTexts["login.dataProtocolAccept"] ); |
---|
130 | } |
---|
131 | |
---|
132 | function createAccount() |
---|
133 | { |
---|
134 | var parametersUrl = "name=" + $( "#lastName" ).val() + "&firstName=" + $( "#firstName" ).val() + "&email=" + $( "#email" ).val() + "&pwd=" + $( "#password" ).val(); |
---|
135 | var request = $.ajax( { |
---|
136 | url: "project?methodName=createAccount&" + parametersUrl, |
---|
137 | success:handleCreateAccount, |
---|
138 | error: showErrorAccount |
---|
139 | } ); |
---|
140 | } |
---|
141 | |
---|
142 | function handleCreateAccount() |
---|
143 | { |
---|
144 | $( "#infosAccount" ).hide(); |
---|
145 | $( "#infosAccount" ).removeClass( "containerErrors" ); |
---|
146 | $( "#infosAccount" ).addClass( "containerInfos" ); |
---|
147 | $( "#infosAccount" ).html( templateTexts["login.dataProtocol.account"] ); |
---|
148 | $( "#infosAccount" ).show(); |
---|
149 | } |
---|
150 | |
---|
151 | function showErrorAccount( result, text ) |
---|
152 | { |
---|
153 | $( "#infosAccount" ).hide(); |
---|
154 | $( "#infosAccount" ).removeClass( "containerInfos" ); |
---|
155 | $( "#infosAccount" ).addClass( "containerErrors" ); |
---|
156 | if( null != result ) |
---|
157 | $( "#infosAccount" ).html( templateTexts[result.responseText] ); |
---|
158 | else |
---|
159 | $( "#infosAccount" ).html( text ); |
---|
160 | |
---|
161 | $( "#infosAccount" ).show(); |
---|
162 | } |
---|
163 | </script> |
---|