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.business.user.attribute;
35
36 import fr.paris.lutece.portal.business.user.AdminUser;
37 import fr.paris.lutece.portal.service.message.AdminMessage;
38 import fr.paris.lutece.portal.service.message.AdminMessageService;
39 import fr.paris.lutece.portal.service.user.attribute.AttributeFieldService;
40 import fr.paris.lutece.portal.web.constants.Messages;
41
42 import org.apache.commons.lang.StringUtils;
43
44 import java.util.ArrayList;
45 import java.util.List;
46 import java.util.Locale;
47
48 import javax.servlet.http.HttpServletRequest;
49
50
51
52
53
54
55
56 public class AttributeRadioButton extends AbstractAttribute implements ISimpleValuesAttributes
57 {
58
59 private static final String CONSTANT_UNDERSCORE = "_";
60
61
62 private static final String PARAMETER_TITLE = "title";
63 private static final String PARAMETER_HELP_MESSAGE = "help_message";
64 private static final String PARAMETER_MANDATORY = "mandatory";
65 private static final String PARAMETER_IS_SHOWN_IN_SEARCH = "is_shown_in_search";
66 private static final String PARAMETER_IS_SHOWN_IN_RESULT_LIST = "is_shown_in_result_list";
67 private static final String PARAMETER_ATTRIBUTE = "attribute";
68 private static final String PARAMETER_IS_FIELD_IN_LINE = "is_field_in_line";
69
70
71 private static final String PROPERTY_TYPE_RADIO_BUTTON = "portal.users.attribute.type.radioButton";
72 private static final String PROPERTY_CREATE_RADIO_BUTTON_PAGETITLE = "portal.users.create_attribute.pageTitleAttributeRadioButton";
73 private static final String PROPERTY_MODIFY_RADIO_BUTTON_PAGETITLE = "portal.users.modify_attribute.pageTitleAttributeRadioButton";
74
75
76 private static final String TEMPLATE_CREATE_ATTRIBUTE = "admin/user/attribute/radiobutton/create_attribute_radio_button.html";
77 private static final String TEMPLATE_MODIFY_ATTRIBUTE = "admin/user/attribute/radiobutton/modify_attribute_radio_button.html";
78 private static final String TEMPLATE_HTML_FORM_ATTRIBUTE = "admin/user/attribute/radiobutton/html_code_form_attribute_radio_button.html";
79 private static final String TEMPLATE_HTML_FORM_SEARCH_ATTRIBUTE = "admin/user/attribute/radiobutton/html_code_form_search_attribute_radio_button.html";
80 private static final String TEMPLATE_HTML_VALUE = "admin/user/attribute/radiobutton/html_code_value_attribute_radio_button.html";
81
82
83
84
85 public AttributeRadioButton( )
86 {
87 }
88
89
90
91
92
93 @Override
94 public String getTemplateCreateAttribute( )
95 {
96 return TEMPLATE_CREATE_ATTRIBUTE;
97 }
98
99
100
101
102
103 @Override
104 public String getTemplateModifyAttribute( )
105 {
106 return TEMPLATE_MODIFY_ATTRIBUTE;
107 }
108
109
110
111
112
113 @Override
114 public String getTemplateHtmlFormAttribute( )
115 {
116 return TEMPLATE_HTML_FORM_ATTRIBUTE;
117 }
118
119
120
121
122
123 @Override
124 public String getTemplateHtmlFormSearchAttribute( )
125 {
126 return TEMPLATE_HTML_FORM_SEARCH_ATTRIBUTE;
127 }
128
129
130
131
132
133 @Override
134 public String getTemplateHtmlValue( )
135 {
136 return TEMPLATE_HTML_VALUE;
137 }
138
139
140
141
142
143 @Override
144 public String getPropertyCreatePageTitle( )
145 {
146 return PROPERTY_CREATE_RADIO_BUTTON_PAGETITLE;
147 }
148
149
150
151
152
153 @Override
154 public String getPropertyModifyPageTitle( )
155 {
156 return PROPERTY_MODIFY_RADIO_BUTTON_PAGETITLE;
157 }
158
159
160
161
162
163
164 @Override
165 public String setAttributeData( HttpServletRequest request )
166 {
167 String strTitle = request.getParameter( PARAMETER_TITLE );
168 String strHelpMessage = ( request.getParameter( PARAMETER_HELP_MESSAGE ) != null )
169 ? request.getParameter( PARAMETER_HELP_MESSAGE ).trim( ) : null;
170 String strIsShownInSearch = request.getParameter( PARAMETER_IS_SHOWN_IN_SEARCH );
171 String strIsShownInResultList = request.getParameter( PARAMETER_IS_SHOWN_IN_RESULT_LIST );
172 String strMandatory = request.getParameter( PARAMETER_MANDATORY );
173 String strFieldInLine = request.getParameter( PARAMETER_IS_FIELD_IN_LINE );
174
175 if ( StringUtils.isNotBlank( strTitle ) )
176 {
177 setTitle( strTitle );
178 setHelpMessage( strHelpMessage );
179 setMandatory( strMandatory != null );
180 setShownInSearch( strIsShownInSearch != null );
181 setShownInResultList( strIsShownInResultList != null );
182 setFieldInLine( strFieldInLine != null );
183
184 return null;
185 }
186
187 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
188 }
189
190
191
192
193
194 @Override
195 public void setAttributeType( Locale locale )
196 {
197 AttributeType attributeType = new AttributeType( );
198 attributeType.setLocale( locale );
199 attributeType.setClassName( this.getClass( ).getName( ) );
200 attributeType.setLabelType( PROPERTY_TYPE_RADIO_BUTTON );
201 setAttributeType( attributeType );
202 }
203
204
205
206
207
208
209
210 @Override
211 public List<AdminUserField> getUserFieldsData( HttpServletRequest request, AdminUser user )
212 {
213 String[] strValues = request.getParameterValues( PARAMETER_ATTRIBUTE + CONSTANT_UNDERSCORE +
214 getIdAttribute( ) );
215
216 return getUserFieldsData( strValues, user );
217 }
218
219
220
221
222 @Override
223 public List<AdminUserField> getUserFieldsData( String[] strValues, AdminUser user )
224 {
225 List<AdminUserField> listUserFields = new ArrayList<AdminUserField>( );
226
227 if ( strValues != null )
228 {
229 for ( String strValue : strValues )
230 {
231 AdminUserField userField = new AdminUserField( );
232 AttributeField attributeField;
233
234 if ( StringUtils.isNotBlank( strValue ) && StringUtils.isNumeric( strValue ) )
235 {
236 int nIdField = Integer.parseInt( strValue );
237 attributeField = AttributeFieldService.getInstance( ).getAttributeField( nIdField );
238 }
239 else
240 {
241 attributeField = new AttributeField( );
242 attributeField.setAttribute( this );
243 attributeField.setTitle( strValue );
244 attributeField.setValue( strValue );
245 }
246
247 if ( attributeField != null )
248 {
249 userField.setUser( user );
250 userField.setAttribute( this );
251 userField.setAttributeField( attributeField );
252 userField.setValue( attributeField.getTitle( ) );
253 listUserFields.add( userField );
254 }
255 }
256 }
257
258 return listUserFields;
259 }
260
261
262
263
264
265 @Override
266 public boolean isAnonymizable( )
267 {
268 return false;
269 }
270 }