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.appointment.web.portlet;
35
36 import java.util.Collection;
37 import java.util.HashMap;
38 import java.util.Map;
39
40 import javax.servlet.http.HttpServletRequest;
41
42 import org.apache.commons.lang3.StringUtils;
43
44 import fr.paris.lutece.plugins.appointment.business.form.Form;
45 import fr.paris.lutece.plugins.appointment.business.portlet.AppointmentFormPortlet;
46 import fr.paris.lutece.plugins.appointment.business.portlet.AppointmentFormPortletHome;
47 import fr.paris.lutece.plugins.appointment.service.FormService;
48 import fr.paris.lutece.portal.business.portlet.PortletHome;
49 import fr.paris.lutece.portal.service.message.AdminMessage;
50 import fr.paris.lutece.portal.service.message.AdminMessageService;
51 import fr.paris.lutece.util.ReferenceList;
52 import fr.paris.lutece.util.html.HtmlTemplate;
53
54
55
56
57
58
59
60 public class AppointmentFormPortletJspBean extends AbstractPortletJspBean
61 {
62
63
64
65 private static final long serialVersionUID = 5342937491389478335L;
66
67
68 private static final String MARK_LIST_APPOINTMENT_FORM = "refListAppointmentForm";
69
70
71 private static final String PARAMETER_FORM = "id_form";
72
73
74 private static final String MESSAGE_ERROR_NO_APPOINTMENT_FORM_SELECTED = "appointment.message.error.noAppointmentFormSelected";
75
76
77
78
79 @Override
80 public String getCreate( HttpServletRequest request )
81 {
82 String strPageId = request.getParameter( PARAMETER_PAGE_ID );
83 String strPortletTypeId = request.getParameter( PARAMETER_PORTLET_TYPE_ID );
84
85 Collection<Form> listIsActiveAndIsDisplayedOnPortletAppointmentForm = FormService.findAllActiveAndDisplayedOnPortletForms( );
86
87 ReferenceList refListAppointmentForm = new ReferenceList( );
88
89 for ( Form form : listIsActiveAndIsDisplayedOnPortletAppointmentForm )
90 {
91 refListAppointmentForm.addItem( form.getIdForm( ), form.getTitle( ) );
92 }
93
94 Map<String, Object> model = new HashMap<>( );
95 model.put( MARK_LIST_APPOINTMENT_FORM, refListAppointmentForm );
96
97 HtmlTemplate template = getCreateTemplate( strPageId, strPortletTypeId, model );
98
99 return template.getHtml( );
100 }
101
102
103
104
105 @Override
106 public String getModify( HttpServletRequest request )
107 {
108 String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
109 int nPortletId = Integer.parseInt( strPortletId );
110 AppointmentFormPortlet/../fr/paris/lutece/plugins/appointment/business/portlet/AppointmentFormPortlet.html#AppointmentFormPortlet">AppointmentFormPortlet portlet = (AppointmentFormPortlet) PortletHome.findByPrimaryKey( nPortletId );
111
112 Collection<Form> listIsActiveAndIsDisplayedOnPortletAppointmentForm = FormService.findAllActiveAndDisplayedOnPortletForms( );
113
114 ReferenceList refListAppointmentForm = new ReferenceList( );
115
116 for ( Form form : listIsActiveAndIsDisplayedOnPortletAppointmentForm )
117 {
118 refListAppointmentForm.addItem( form.getIdForm( ), form.getTitle( ) );
119 }
120
121 Map<String, Object> model = new HashMap<>( );
122 model.put( MARK_LIST_APPOINTMENT_FORM, refListAppointmentForm );
123
124 HtmlTemplate template = getModifyTemplate( portlet, model );
125
126 return template.getHtml( );
127 }
128
129
130
131
132 @Override
133 public String doCreate( HttpServletRequest request )
134 {
135 AppointmentFormPortletbusiness/portlet/AppointmentFormPortlet.html#AppointmentFormPortlet">AppointmentFormPortlet portlet = new AppointmentFormPortlet( );
136
137
138 String strPageId = request.getParameter( PARAMETER_PAGE_ID );
139 int nPageId = Integer.parseInt( strPageId );
140
141 String strFormId = request.getParameter( PARAMETER_FORM );
142
143 if ( StringUtils.isNotEmpty( strFormId ) && StringUtils.isNumeric( strFormId ) )
144 {
145 int nIdForm = Integer.parseInt( strFormId );
146 portlet.setIdAppointmentForm( nIdForm );
147 }
148 else
149 {
150 return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_NO_APPOINTMENT_FORM_SELECTED, AdminMessage.TYPE_STOP );
151 }
152
153
154 String strErrorUrl = setPortletCommonData( request, portlet );
155
156 if ( strErrorUrl != null )
157 {
158 return strErrorUrl;
159 }
160
161 portlet.setPageId( nPageId );
162
163
164 AppointmentFormPortletHome.getInstance( ).create( portlet );
165
166
167 return getPageUrl( nPageId );
168 }
169
170
171
172
173 @Override
174 public String doModify( HttpServletRequest request )
175 {
176
177 String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
178 int nPortletId = Integer.parseInt( strPortletId );
179 AppointmentFormPortlet/../fr/paris/lutece/plugins/appointment/business/portlet/AppointmentFormPortlet.html#AppointmentFormPortlet">AppointmentFormPortlet portlet = (AppointmentFormPortlet) PortletHome.findByPrimaryKey( nPortletId );
180
181 String strFormId = request.getParameter( PARAMETER_FORM );
182
183 if ( StringUtils.isNotEmpty( strFormId ) && StringUtils.isNumeric( strFormId ) )
184 {
185 int nIdForm = Integer.parseInt( strFormId );
186 portlet.setIdAppointmentForm( nIdForm );
187 }
188 else
189 {
190 return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_NO_APPOINTMENT_FORM_SELECTED, AdminMessage.TYPE_STOP );
191 }
192
193
194 String strErrorUrl = setPortletCommonData( request, portlet );
195
196 if ( strErrorUrl != null )
197 {
198 return strErrorUrl;
199 }
200
201
202 portlet.update( );
203
204
205 return getPageUrl( portlet.getPageId( ) );
206 }
207 }