1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.web.features;
35
36 import fr.paris.lutece.portal.business.right.Level;
37 import fr.paris.lutece.portal.business.right.LevelHome;
38 import fr.paris.lutece.portal.service.message.AdminMessage;
39 import fr.paris.lutece.portal.service.message.AdminMessageService;
40 import fr.paris.lutece.portal.service.template.AppTemplateService;
41 import fr.paris.lutece.portal.web.admin.AdminFeaturesPageJspBean;
42 import fr.paris.lutece.portal.web.constants.Messages;
43 import fr.paris.lutece.portal.web.constants.Parameters;
44 import fr.paris.lutece.util.html.HtmlTemplate;
45
46 import java.util.HashMap;
47
48 import javax.servlet.http.HttpServletRequest;
49
50
51
52
53
54
55 public class LevelsJspBean extends AdminFeaturesPageJspBean
56 {
57
58 public static final String RIGHT_MANAGE_LEVELS = "CORE_LEVEL_RIGHT_MANAGEMENT";
59
60
61 private static final String PROPERTY_PAGE_TITLE_LEVEL_LIST = "portal.features.manage_levels.pageTitle";
62 private static final String PROPERTY_PAGE_TITLE_CREATE_LEVEL = "portal.features.create_level.pageTitle";
63 private static final String PROPERTY_PAGE_TITLE_MODIFY_LEVEL = "portal.features.modify_level.pageTitle";
64
65
66 private static final String MARK_LEVELS_LIST = "levels_list";
67 private static final String MARK_LEVEL = "level";
68
69
70 private static final String TEMPLATE_MANAGE_LEVELS = "admin/features/manage_levels.html";
71 private static final String TEMPLATE_CREATE_LEVEL = "admin/features/create_level.html";
72 private static final String TEMPLATE_MODIFY_LEVEL = "admin/features/modify_level.html";
73
74
75 private static final String JSP_MANAGE_LEVEL = "ManageLevels.jsp";
76
77
78
79
80
81
82
83 public String getManageLevels( HttpServletRequest request )
84 {
85 setPageTitleProperty( PROPERTY_PAGE_TITLE_LEVEL_LIST );
86
87 HashMap<String, Object> model = new HashMap<String, Object>( );
88 model.put( MARK_LEVELS_LIST, LevelHome.getLevelsList( ) );
89
90 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_LEVELS, getLocale( ), model );
91
92 return getAdminPage( template.getHtml( ) );
93 }
94
95
96
97
98
99
100
101 public String getCreateLevel( HttpServletRequest request )
102 {
103 setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE_LEVEL );
104
105 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_LEVEL, getLocale( ) );
106
107 return getAdminPage( template.getHtml( ) );
108 }
109
110
111
112
113
114
115
116
117 public String doCreateLevel( HttpServletRequest request )
118 {
119 String strName = request.getParameter( Parameters.LEVEL_NAME );
120
121
122 if ( strName.equals( "" ) )
123 {
124 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
125 }
126
127 Level level = new Level( );
128 level.setName( strName );
129 LevelHome.create( level );
130
131
132 return JSP_MANAGE_LEVEL;
133 }
134
135
136
137
138
139
140
141 public String getModifyLevel( HttpServletRequest request )
142 {
143 setPageTitleProperty( PROPERTY_PAGE_TITLE_MODIFY_LEVEL );
144
145 String strId = request.getParameter( Parameters.LEVEL_ID );
146
147 Level level = LevelHome.findByPrimaryKey( Integer.parseInt( strId ) );
148
149 if ( level == null )
150 {
151 return getManageLevels( request );
152 }
153
154 HashMap<String, Object> model = new HashMap<String, Object>( );
155 model.put( MARK_LEVEL, level );
156
157 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_LEVEL, getLocale( ), model );
158
159 return getAdminPage( template.getHtml( ) );
160 }
161
162
163
164
165
166
167
168
169 public String doModifyLevel( HttpServletRequest request )
170 {
171 String strId = request.getParameter( Parameters.LEVEL_ID );
172 String strName = request.getParameter( Parameters.LEVEL_NAME );
173
174
175 if ( strName.equals( "" ) )
176 {
177 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
178 }
179
180 Level level = LevelHome.findByPrimaryKey( Integer.parseInt( strId ) );
181 level.setName( strName );
182 LevelHome.update( level );
183
184
185 return JSP_MANAGE_LEVEL;
186 }
187 }