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.plugins.directory.business;
35
36 import fr.paris.lutece.plugins.directory.service.directorysearch.DirectorySearchItem;
37 import fr.paris.lutece.plugins.directory.utils.DirectoryErrorException;
38 import fr.paris.lutece.plugins.directory.utils.DirectoryUtils;
39 import fr.paris.lutece.portal.service.i18n.I18nService;
40 import fr.paris.lutece.portal.service.message.AdminMessage;
41 import fr.paris.lutece.portal.service.message.AdminMessageService;
42 import fr.paris.lutece.portal.web.util.LocalizedPaginator;
43 import fr.paris.lutece.util.html.Paginator;
44
45 import java.util.ArrayList;
46 import java.util.HashMap;
47 import java.util.List;
48 import java.util.Locale;
49
50 import javax.servlet.http.HttpServletRequest;
51
52
53
54
55
56
57 public class EntryTypeRadioButton extends Entry
58 {
59 private final String _template_create = "admin/plugins/directory/entrytyperadiobutton/create_entry_type_radio_button.html";
60 private final String _template_modify = "admin/plugins/directory/entrytyperadiobutton/modify_entry_type_radio_button.html";
61 private final String _template_html_code_form_entry = "admin/plugins/directory/entrytyperadiobutton/html_code_form_entry_type_radio_button.html";
62 private final String _template_html_code_form_search_entry = "admin/plugins/directory/entrytyperadiobutton/html_code_form_search_entry_type_radio_button.html";
63 private final String _template_html_code_entry_value = "admin/plugins/directory/entrytyperadiobutton/html_code_entry_value_type_radio_button.html";
64 private final String _template_html_front_code_form_entry = "skin/plugins/directory/entrytyperadiobutton/html_code_form_entry_type_radio_button.html";
65 private final String _template_html_front_code_form_search_entry = "skin/plugins/directory/entrytyperadiobutton/html_code_form_search_entry_type_radio_button.html";
66 private final String _template_html_front_code_entry_value = "skin/plugins/directory/entrytyperadiobutton/html_code_entry_value_type_radio_button.html";
67
68
69
70
71 @Override
72 public String getTemplateHtmlFormEntry( boolean isDisplayFront )
73 {
74 if ( isDisplayFront )
75 {
76 return _template_html_front_code_form_entry;
77 }
78
79 return _template_html_code_form_entry;
80 }
81
82
83
84
85 @Override
86 public String getTemplateHtmlFormSearchEntry( boolean isDisplayFront )
87 {
88 if ( isDisplayFront )
89 {
90 return _template_html_front_code_form_search_entry;
91 }
92
93 return _template_html_code_form_search_entry;
94 }
95
96
97
98
99 @Override
100 public String getTemplateHtmlRecordFieldValue( boolean isDisplayFront )
101 {
102 if ( isDisplayFront )
103 {
104 return _template_html_front_code_entry_value;
105 }
106
107 return _template_html_code_entry_value;
108 }
109
110
111
112
113 @Override
114 public String getEntryData( HttpServletRequest request, Locale locale )
115 {
116 String strTitle = request.getParameter( PARAMETER_TITLE );
117 String strHelpMessage = ( request.getParameter( PARAMETER_HELP_MESSAGE ) != null ) ? request.getParameter( PARAMETER_HELP_MESSAGE ).trim( ) : null;
118 String strHelpMessageSearch = ( request.getParameter( PARAMETER_HELP_MESSAGE_SEARCH ) != null ) ? request.getParameter( PARAMETER_HELP_MESSAGE_SEARCH )
119 .trim( ) : null;
120 String strComment = request.getParameter( PARAMETER_COMMENT );
121 String strMandatory = request.getParameter( PARAMETER_MANDATORY );
122 String strIndexed = request.getParameter( PARAMETER_INDEXED );
123 String strIndexedAsTitle = request.getParameter( PARAMETER_INDEXED_AS_TITLE );
124 String strIndexedAsSummary = request.getParameter( PARAMETER_INDEXED_AS_SUMMARY );
125 String strShowInAdvancedSearch = request.getParameter( PARAMETER_SHOWN_IN_ADVANCED_SEARCH );
126 String strShowInResultList = request.getParameter( PARAMETER_SHOWN_IN_RESULT_LIST );
127 String strShowInResultRecord = request.getParameter( PARAMETER_SHOWN_IN_RESULT_RECORD );
128 String strFieldInLine = request.getParameter( PARAMETER_FIELD_IN_LINE );
129 int nFieldInLine = DirectoryUtils.convertStringToInt( strFieldInLine );
130 String strWorkgroupAssociated = request.getParameter( PARAMETER_WORKGROUP_ASSOCIATED );
131 String strRoleAssociated = request.getParameter( PARAMETER_ROLE_ASSOCIATED );
132 String strShowInHistory = request.getParameter( PARAMETER_SHOWN_IN_HISTORY );
133 String strShowInExport = request.getParameter( PARAMETER_SHOWN_IN_EXPORT );
134 String strShowInCompleteness = request.getParameter( PARAMETER_SHOWN_IN_COMPLETENESS );
135 String strFieldError = DirectoryUtils.EMPTY_STRING;
136
137 if ( ( strTitle == null ) || strTitle.trim( ).equals( DirectoryUtils.EMPTY_STRING ) )
138 {
139 strFieldError = FIELD_TITLE;
140 }
141
142 if ( !strFieldError.equals( DirectoryUtils.EMPTY_STRING ) )
143 {
144 Object [ ] tabRequiredFields = {
145 I18nService.getLocalizedString( strFieldError, locale )
146 };
147
148 return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP );
149 }
150
151
152 this.setFields( null );
153
154 this.setTitle( strTitle );
155 this.setHelpMessage( strHelpMessage );
156 this.setHelpMessageSearch( strHelpMessageSearch );
157 this.setComment( strComment );
158 this.setMandatory( strMandatory != null );
159 this.setIndexed( strIndexed != null );
160 this.setIndexedAsTitle( strIndexedAsTitle != null );
161 this.setIndexedAsSummary( strIndexedAsSummary != null );
162 this.setShownInAdvancedSearch( strShowInAdvancedSearch != null );
163 this.setShownInResultList( strShowInResultList != null );
164 this.setShownInResultRecord( strShowInResultRecord != null );
165 this.setFieldInLine( nFieldInLine == 1 );
166 this.setWorkgroupAssociated( strWorkgroupAssociated != null );
167 this.setRoleAssociated( strRoleAssociated != null );
168 this.setShownInHistory( strShowInHistory != null );
169 this.setShownInExport( strShowInExport != null );
170 this.setShownInCompleteness( strShowInCompleteness != null );
171
172 return null;
173 }
174
175
176
177
178 @Override
179 public String getTemplateCreate( )
180 {
181 return _template_create;
182 }
183
184
185
186
187 @Override
188 public String getTemplateModify( )
189 {
190 return _template_modify;
191 }
192
193
194
195
196 @Override
197 public Paginator getPaginator( int nItemPerPage, String strBaseUrl, String strPageIndexParameterName, String strPageIndex )
198 {
199 return new Paginator( this.getFields( ), nItemPerPage, strBaseUrl, strPageIndexParameterName, strPageIndex );
200 }
201
202
203
204
205 @Override
206 public void getImportRecordFieldData( Record record, String strImportValue, boolean bTestDirectoryError, List<RecordField> listRecordField, Locale locale )
207 throws DirectoryErrorException
208 {
209 List<String> lstValue = new ArrayList<String>( );
210 Field field;
211 field = DirectoryUtils.findFieldByValueInTheList( strImportValue, this.getFields( ) );
212
213 if ( field != null )
214 {
215 lstValue.add( Integer.toString( field.getIdField( ) ) );
216 }
217
218 getRecordFieldData( record, lstValue, bTestDirectoryError, false, listRecordField, locale );
219 }
220
221
222
223
224 @Override
225 public void getRecordFieldData( Record record, List<String> lstValue, boolean bTestDirectoryError, boolean bAddNewValue, List<RecordField> listRecordField,
226 Locale locale ) throws DirectoryErrorException
227 {
228 String strIdField = ( ( lstValue != null ) && ( lstValue.size( ) > 0 ) ) ? lstValue.get( 0 ) : null;
229 int nIdField = DirectoryUtils.convertStringToInt( strIdField );
230 Field field = null;
231 RecordField recordField = new RecordField( );
232 recordField.setEntry( this );
233
234 if ( nIdField != DirectoryUtils.CONSTANT_ID_NULL )
235 {
236 field = DirectoryUtils.findFieldByIdInTheList( nIdField, this.getFields( ) );
237 }
238
239 if ( bTestDirectoryError && this.isMandatory( ) )
240 {
241 if ( ( field == null ) || field.getValue( ).equals( DirectoryUtils.EMPTY_STRING ) )
242 {
243 throw new DirectoryErrorException( this.getTitle( ) );
244 }
245 }
246
247 if ( field != null )
248 {
249 recordField.setValue( field.getValue( ) );
250 recordField.setField( field );
251
252
253 if ( record != null )
254 {
255 if ( this.isRoleAssociated( ) )
256 {
257 record.setRoleKey( field.getRoleKey( ) );
258 }
259
260 if ( this.isWorkgroupAssociated( ) )
261 {
262 record.setWorkgroup( field.getWorkgroup( ) );
263 }
264 }
265 }
266
267 listRecordField.add( recordField );
268 }
269
270
271
272
273 @Override
274 public void addSearchCriteria( HashMap<String, Object> mapSearchItem, RecordField recordField )
275 {
276 if ( ( recordField.getField( ) != null ) && ( recordField.getField( ).getValue( ) != null )
277 && !recordField.getField( ).getValue( ).equals( DirectoryUtils.EMPTY_STRING ) )
278 {
279 List<Integer> listIdField = (List<Integer>) mapSearchItem.get( DirectorySearchItem.FIELD_ID_DIRECTORY_FIELD );
280
281 if ( listIdField == null )
282 {
283 listIdField = new ArrayList<Integer>( );
284 }
285
286 listIdField.add( recordField.getField( ).getIdField( ) );
287 mapSearchItem.put( DirectorySearchItem.FIELD_ID_DIRECTORY_FIELD, listIdField );
288 }
289 }
290
291
292
293
294 @Override
295 public boolean isSortable( )
296 {
297 return true;
298 }
299
300
301
302
303 @Override
304 public LocalizedPaginator getPaginator( int nItemPerPage, String strBaseUrl, String strPageIndexParameterName, String strPageIndex, Locale locale )
305 {
306 return new LocalizedPaginator( this.getFields( ), nItemPerPage, strBaseUrl, strPageIndexParameterName, strPageIndex, locale );
307 }
308 }