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