View Javadoc
1   package fr.ifremer.quadrige3.synchro.server.pages.home;
2   
3   /*-
4    * #%L
5    * Quadrige3 Core :: Quadrige3 Synchro server
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import fr.ifremer.quadrige3.synchro.server.application.Application;
27  import fr.ifremer.quadrige3.synchro.server.application.WebSession;
28  import fr.ifremer.quadrige3.synchro.server.pages.BasePage;
29  import fr.ifremer.quadrige3.synchro.server.pages.admin.ConfigPage;
30  import fr.ifremer.quadrige3.synchro.server.pages.admin.JobManagerPage;
31  import fr.ifremer.quadrige3.synchro.server.pages.admin.ToolsPage;
32  import fr.ifremer.quadrige3.synchro.server.pages.doc.DocPage;
33  import org.apache.wicket.ajax.AjaxRequestTarget;
34  import org.apache.wicket.ajax.markup.html.form.AjaxButton;
35  import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
36  import org.apache.wicket.markup.html.form.Form;
37  import org.apache.wicket.model.CompoundPropertyModel;
38  import org.apache.wicket.model.IModel;
39  import org.apache.wicket.request.mapper.parameter.PageParameters;
40  
41  @AuthorizeInstantiation("ROLE_USER")
42  public class HomePage extends BasePage {
43      
44      /**
45       * 
46       */
47      private static final long serialVersionUID = 1L;
48  
49      public HomePage(final PageParameters parameters) {
50          super(parameters);
51          
52          IModel<HomePage> model = new CompoundPropertyModel<>(this);
53  
54          setVersioned(false);
55  
56          final boolean isUserAdmin = getWebSession().isUserAdmin();
57  
58          Form<HomePage> form = new Form<>("form", model);
59          form.setOutputMarkupId(true);
60          add(form);
61  
62          // job manager button
63          AjaxButton jobManagerButton = new AjaxButton("jobManagerLink", form) {
64              private static final long serialVersionUID = 1L;
65              @Override
66              protected void onConfigure() {
67                  super.onConfigure();
68                  setVisibilityAllowed(isUserAdmin);
69              }
70              @Override
71              protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
72                  setResponsePage(JobManagerPage.class);
73              }
74          };
75          form.add(jobManagerButton);
76  
77          // tools button
78          AjaxButton configButton = new AjaxButton("configLink", form) {
79              private static final long serialVersionUID = 1L;
80              @Override
81              protected void onConfigure() {
82                  super.onConfigure();
83                  setVisibilityAllowed(isUserAdmin);
84              }
85              @Override
86              protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
87                  setResponsePage(ConfigPage.class);
88              }
89          };
90          form.add(configButton);
91  
92          // tools button
93          AjaxButton toolsButton = new AjaxButton("toolsLink", form) {
94              private static final long serialVersionUID = 1L;
95              @Override
96              protected void onConfigure() {
97                  super.onConfigure();
98                  setVisibilityAllowed(isUserAdmin);
99              }
100             @Override
101             protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
102                 setResponsePage(ToolsPage.class);
103             }
104         };
105         form.add(toolsButton);
106 
107         // docLink button
108         AjaxButton docButton = new AjaxButton("docLink", form) {
109             @Override
110             protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
111                 setResponsePage(DocPage.class);
112             }
113         };
114         form.add(docButton);
115 
116         // logout button
117         AjaxButton logoutButton = new AjaxButton("logoutLink", form) {
118             private static final long serialVersionUID = 1L;
119             @Override
120             protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
121                 WebSession session = (WebSession)getWebSession();
122                 session.invalidate();
123                 session.signOut();
124                 setResponsePage(Application.get().getHomePage());
125             }
126         };
127         form.add(logoutButton);
128 
129     }
130 }