1 | <%@ page import="com.ether.user.UserRole" %> |
---|
2 | <%@ page import="com.medias.Context" %> |
---|
3 | |
---|
4 | <script type="text/javascript"> |
---|
5 | var InterfaceTemplate = Class.create( { |
---|
6 | |
---|
7 | initialize: function() |
---|
8 | { |
---|
9 | /** *********** CONTAINERS *********** **/ |
---|
10 | this.containerTitle = $( "#title" ); |
---|
11 | this.containerTools = $( "#tools" ); |
---|
12 | this.containerLogin = $( "#loginModule" ); |
---|
13 | this.containerMenuData = $( "#menuData" ); |
---|
14 | |
---|
15 | /** *********** VARIABLES *********** **/ |
---|
16 | this.isLanguageFr = <%=Context.getLangue(request).equals( "fr" )%>; |
---|
17 | this.path = "<%=request.getContextPath()%>"; |
---|
18 | setPath( this.path ); |
---|
19 | this.webmaster = "<%=Context.getWebmaster(request)%>"; |
---|
20 | this.relativePageUri = <%=request.getQueryString() != null%> ? "<%=Context.getRelativePath( request )%>?<%=request.getQueryString()%>" : "<%=Context.getRelativePageURI(request)%>"; |
---|
21 | this.jSONUser = <%=Context.getJSONUser( request )%> ? <%=Context.getJSONUser( request )%> : false; |
---|
22 | this.screenWidthLimit = 1336; |
---|
23 | |
---|
24 | /** ************ CREATE ************ **/ |
---|
25 | this.createTitle(); |
---|
26 | this.createLogin(); |
---|
27 | this.createTools(); |
---|
28 | this.createMenuData(); |
---|
29 | jQuery.proxy( this.createLeftSlides(), this ); |
---|
30 | this.updateLoginOrLogout(); |
---|
31 | }, |
---|
32 | |
---|
33 | // CREATES ******************************************************** |
---|
34 | createTitle: function() |
---|
35 | { |
---|
36 | this.containerTitle.addClass( "containerTitle" ); |
---|
37 | this.containerTitle.html( templateTexts["app.fulltitle"] ); |
---|
38 | }, |
---|
39 | |
---|
40 | createTools: function() |
---|
41 | { |
---|
42 | var backofficeButton = new Button( {value:templateTexts["app.backoffice"], parent:this.containerTools, id:"button_bo", className: "blue_button", classNameText:"blue_button_text", title : templateTexts["app.backoffice.help"], onClick:jQuery.proxy( this.onClickBO, this )} ); |
---|
43 | backofficeButton.hide(); |
---|
44 | |
---|
45 | 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 )} ); |
---|
46 | |
---|
47 | var valueLanguage = templateTexts["app.fr"]; |
---|
48 | if( this.isLanguageFr ) |
---|
49 | valueLanguage = templateTexts["app.en"]; |
---|
50 | |
---|
51 | 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 )} ); |
---|
52 | var homeButton = new Button( {value:templateTexts["app.home"], parent:this.containerTools, id:"button_home", className: "blue_button", classNameText:"blue_button_text", onClick:this.onClickHome} ); |
---|
53 | |
---|
54 | var divSmallLogoEther = $( document.createElement( "div" ) ); |
---|
55 | divSmallLogoEther.attr( {id:"smallLogoEther", class:"containerSmallLogoEther"} ); |
---|
56 | divSmallLogoEther.append( '<a href="http://ether.ipsl.jussieu.fr" target="help"><img src="resources/images/logo_Ether.jpg" width="40px" height="40px"/></a>' ); |
---|
57 | this.containerTools.append( divSmallLogoEther ); |
---|
58 | |
---|
59 | this.updateLogoEther(); |
---|
60 | }, |
---|
61 | |
---|
62 | createLogin: function() |
---|
63 | { |
---|
64 | 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 } ); |
---|
65 | this.loginModule.setJSONUser( this.jSONUser ); |
---|
66 | this.loginModule.display(); |
---|
67 | setLoginModule( this.loginModule ); |
---|
68 | }, |
---|
69 | |
---|
70 | createMenuData: function() |
---|
71 | { |
---|
72 | this.containerMenuData.empty(); |
---|
73 | |
---|
74 | var ulData = $( document.createElement( "ul" ) ); |
---|
75 | this.containerMenuData.append( ulData ); |
---|
76 | |
---|
77 | var liExtract = $( document.createElement( "li" ) ); |
---|
78 | liExtract.append('<a onclick=\'javascript:neededLogin("/DataAccess.do")\'><span>' + templateTexts["data.access.extract.short"] + '</span></a>'); |
---|
79 | ulData.append( liExtract ); |
---|
80 | var liDownload = $( document.createElement( "li" ) ); |
---|
81 | var aDownload = $( document.createElement( "a" ) ); |
---|
82 | aDownload.attr( {onclick:'javascript:neededLogin("/PrepareTree.do")'} ); |
---|
83 | aDownload.html( "<span>" + templateTexts["data.upload.short"] + "</span>" ); |
---|
84 | liDownload.append( aDownload ); |
---|
85 | ulData.append( liDownload ); |
---|
86 | }, |
---|
87 | |
---|
88 | createLeftSlides: function() |
---|
89 | { |
---|
90 | var contentSlideCredits = "resources/jsp/credits_fr.jsp"; |
---|
91 | var contentSlideMentions = "resources/jsp/mentions_fr.jsp"; |
---|
92 | var contentSlideInfos = "resources/jsp/informations_fr.jsp"; |
---|
93 | |
---|
94 | var contentButtonCredits = "<button class='big_blue_button' title='" + templateTexts["app.credits"] + "'><div class='big_blue_button_text'>C</div></button>"; |
---|
95 | var contentButtonMentions = "<button class='big_blue_button' title='" + templateTexts["app.mentions"] + "'><div class='big_blue_button_text'>M</div></button>"; |
---|
96 | var contentButtonInfos = "<button class='big_blue_button' title='" + templateTexts["app.infos"] + "'><div class='big_blue_button_text'>I</div></button>"; |
---|
97 | |
---|
98 | if( !this.isLanguageFr ) |
---|
99 | { |
---|
100 | contentSlideCredits = "resources/jsp/credits_en.jsp"; |
---|
101 | contentSlideMentions = "resources/jsp/mentions_en.jsp"; |
---|
102 | contentSlideInfos = "resources/jsp/informations_en.jsp"; |
---|
103 | } |
---|
104 | var divSlideCredits = new Slide( { contentId:"slideContentCredits", buttonId: "slideCredits", parent:$( "#creditSlide" ), isIndexToChange:true, |
---|
105 | contentButton:contentButtonCredits , contentPageSlide:contentSlideCredits} ); |
---|
106 | |
---|
107 | var divSlideMentions = new Slide( { contentId:"slideContentMentions", buttonId: "slideMentions", parent:$( "#mentionSlide" ),specificButtonClass:"containerSlideButtonMentions", isIndexToChange:true, |
---|
108 | contentButton:contentButtonMentions, contentPageSlide:contentSlideMentions} ); |
---|
109 | |
---|
110 | var divSlideInfos = new Slide( { contentId:"slideContentInfos", buttonId: "slideInfos", parent:$( "#infoSlide" ), specificButtonClass:"containerSlideButtonInfos", isIndexToChange:true, |
---|
111 | contentButton:contentButtonInfos, contentPageSlide:contentSlideInfos} ); |
---|
112 | }, |
---|
113 | |
---|
114 | // REQUESTS ******************************************************** |
---|
115 | |
---|
116 | // EVENTS ******************************************************** |
---|
117 | onClickHome: function() |
---|
118 | { |
---|
119 | document.location.href = "index.jsp"; |
---|
120 | }, |
---|
121 | |
---|
122 | onClickLanguage: function() |
---|
123 | { |
---|
124 | if( this.isLanguageFr ) |
---|
125 | document.location.href = this.path + "/English.do?requestUri=" + this.relativePageUri; |
---|
126 | else |
---|
127 | document.location.href = this.path + "/French.do?requestUri=" + this.relativePageUri; |
---|
128 | }, |
---|
129 | |
---|
130 | onClickBO: function() |
---|
131 | { |
---|
132 | document.location.href = this.path + "/backoffice"; |
---|
133 | }, |
---|
134 | |
---|
135 | onClickMail: function() |
---|
136 | { |
---|
137 | document.location.href = "mailto:" + this.webmaster + "?subject=[MEGAPOLI]"; |
---|
138 | }, |
---|
139 | |
---|
140 | onClickInscription: function() |
---|
141 | { |
---|
142 | var dataProtocol = "resources/jsp/dataProtocol_fr.jsp"; |
---|
143 | if( !this.isLanguageFr ) |
---|
144 | dataProtocol = "resources/jsp/dataProtocol_en.jsp"; |
---|
145 | |
---|
146 | var $dialog = $( '<div></div>' ) |
---|
147 | .load( dataProtocol ) |
---|
148 | .dialog( { |
---|
149 | autoOpen: false, |
---|
150 | title: loginTexts["login.inscription"], |
---|
151 | height: 700, |
---|
152 | width: 600 |
---|
153 | } ); |
---|
154 | $dialog.dialog( 'open' ); |
---|
155 | |
---|
156 | // TODO : see with $dialog.ready() to manage buttons |
---|
157 | }, |
---|
158 | |
---|
159 | /** |
---|
160 | * This method display a small Ether logo if the screen is too small to contain the big one |
---|
161 | */ |
---|
162 | updateLogoEther: function() |
---|
163 | { |
---|
164 | if( this.screenWidthLimit > innerWidth ) |
---|
165 | { |
---|
166 | $( "#logoEther" ).hide(); |
---|
167 | $( "#linkLogoEther" ).hide(); |
---|
168 | $( "#smallLogoEther" ).show(); |
---|
169 | } |
---|
170 | else |
---|
171 | { |
---|
172 | $( "#logoEther" ).show(); |
---|
173 | $( "#linkLogoEther" ).show(); |
---|
174 | $( "#smallLogoEther" ).hide(); |
---|
175 | } |
---|
176 | }, |
---|
177 | |
---|
178 | updateLoginOrLogout: function() |
---|
179 | { |
---|
180 | if( "<%=UserRole.ADMINISTRATOR%>" == getJSONUserRole() ) |
---|
181 | $( "#button_bo" ).show(); |
---|
182 | else |
---|
183 | $( "#button_bo" ).hide(); |
---|
184 | } |
---|
185 | |
---|
186 | } ); |
---|
187 | |
---|
188 | /** ******************************* **/ |
---|
189 | /** *********** ACCOUNT *********** **/ |
---|
190 | /** ******************************* **/ |
---|
191 | function onClickAcceptDataProtocol() |
---|
192 | { |
---|
193 | if( '' == $( "#lastName" ).val() || '' == $( "#email" ).val() || '' == $( "#password" ).val() ) |
---|
194 | { |
---|
195 | showErrorAccount( null, templateTexts["login.dataProtocolFields"] ); |
---|
196 | return; |
---|
197 | } |
---|
198 | |
---|
199 | if( $( "#checkboxUser" ).attr( 'checked' ) ) |
---|
200 | createAccount(); |
---|
201 | else |
---|
202 | showErrorAccount( null, templateTexts["login.dataProtocolAccept"] ); |
---|
203 | } |
---|
204 | |
---|
205 | function createAccount() |
---|
206 | { |
---|
207 | var parametersUrl = "name=" + $( "#lastName" ).val() + "&firstName=" + $( "#firstName" ).val() + "&email=" + $( "#email" ).val() + "&pwd=" + $( "#password" ).val(); |
---|
208 | var request = $.ajax( { |
---|
209 | url: "project?methodName=createAccount&" + parametersUrl, |
---|
210 | success:handleCreateAccount, |
---|
211 | error: showErrorAccount |
---|
212 | } ); |
---|
213 | } |
---|
214 | |
---|
215 | function handleCreateAccount() |
---|
216 | { |
---|
217 | $( "#infosAccount" ).hide(); |
---|
218 | $( "#infosAccount" ).removeClass( "containerErrors" ); |
---|
219 | $( "#infosAccount" ).addClass( "containerInfos" ); |
---|
220 | $( "#infosAccount" ).html( templateTexts["login.dataProtocol.account"] ); |
---|
221 | $( "#infosAccount" ).show(); |
---|
222 | } |
---|
223 | |
---|
224 | function showErrorAccount( result, text ) |
---|
225 | { |
---|
226 | $( "#infosAccount" ).hide(); |
---|
227 | $( "#infosAccount" ).removeClass( "containerInfos" ); |
---|
228 | $( "#infosAccount" ).addClass( "containerErrors" ); |
---|
229 | if( null != result ) |
---|
230 | $( "#infosAccount" ).html( templateTexts[result.responseText] ); |
---|
231 | else |
---|
232 | $( "#infosAccount" ).html( text ); |
---|
233 | |
---|
234 | $( "#infosAccount" ).show(); |
---|
235 | } |
---|
236 | </script> |
---|