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.calendar.web;
35
36 import fr.paris.lutece.plugins.calendar.business.Event;
37 import fr.paris.lutece.plugins.calendar.business.MultiAgenda;
38 import fr.paris.lutece.plugins.calendar.business.MultiAgendaEvent;
39 import fr.paris.lutece.plugins.calendar.service.CalendarPlugin;
40 import fr.paris.lutece.plugins.calendar.service.Utils;
41 import fr.paris.lutece.plugins.calendar.service.search.CalendarSearchService;
42 import fr.paris.lutece.portal.service.plugin.Plugin;
43 import fr.paris.lutece.portal.service.plugin.PluginService;
44 import fr.paris.lutece.portal.service.template.AppTemplateService;
45 import fr.paris.lutece.portal.service.util.AppPropertiesService;
46 import fr.paris.lutece.util.html.HtmlTemplate;
47
48 import java.util.Calendar;
49 import java.util.Date;
50 import java.util.HashMap;
51 import java.util.List;
52 import java.util.Locale;
53 import java.util.Map;
54
55 import javax.servlet.http.HttpServletRequest;
56
57
58
59
60
61 public class WeekCalendarView implements CalendarView
62 {
63 private static final String TEMPLATE_VIEW_WEEK = "skin/plugins/calendar/calendar_view_week.html";
64 private static final String TEMPLATE_VIEW_WEEK_DAY = "skin/plugins/calendar/calendar_view_week_day.html";
65 private static final String TEMPLATE_VIEW_DAY_EVENT = "skin/plugins/calendar/calendar_view_week_event.html";
66
67
68
69
70
71
72
73
74
75
76
77 public String getCalendarView( String strDate, MultiAgenda agenda, CalendarUserOptions options,
78 HttpServletRequest request )
79 {
80 Locale locale = options.getLocale( );
81 Calendar calendar = Utils.getFirstDayOfWeek( strDate );
82 StringBuffer sbDays = new StringBuffer( );
83
84 for ( int i = 0; i < 7; i++ )
85 {
86 sbDays.append( getDay( calendar, agenda, locale, request ) );
87 calendar.roll( Calendar.DAY_OF_WEEK, true );
88 }
89
90 Map<String, Object> model = new HashMap<String, Object>( );
91 model.put( Constants.MARK_DAYS, sbDays.toString( ) );
92
93 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_VIEW_WEEK, options.getLocale( ), model );
94
95 return template.getHtml( );
96 }
97
98
99
100
101
102
103
104
105
106 private String getDay( Calendar calendar, MultiAgenda agenda, Locale locale, HttpServletRequest request )
107 {
108 StringBuffer sbEvents = new StringBuffer( );
109 String strDate = Utils.getDate( calendar );
110
111 if ( agenda.hasEvents( strDate ) )
112 {
113 Date date = Utils.getDate( Utils.getDate( calendar ) );
114 Plugin plugin = PluginService.getPlugin( CalendarPlugin.PLUGIN_NAME );
115 List<Event> listIndexedEvents = CalendarSearchService.getInstance( ).getSearchResults(
116 agenda.getAgendaIds( ), null, "", date, date, plugin );
117
118 for ( Event event : listIndexedEvents )
119 {
120 MultiAgendaEvent multiAgendaEvent = new MultiAgendaEvent( event,
121 String.valueOf( event.getIdCalendar( ) ) );
122 HashMap<String, Object> eventModel = new HashMap<String, Object>( );
123 HtmlUtils.fillEventTemplate( eventModel, multiAgendaEvent, strDate );
124 eventModel.put( Constants.MARK_JSP_URL,
125 AppPropertiesService.getProperty( Constants.PROPERTY_RUNAPP_JSP_URL ) );
126
127 HtmlTemplate tEvent = AppTemplateService.getTemplate( TEMPLATE_VIEW_DAY_EVENT, locale, eventModel );
128 sbEvents.append( tEvent.getHtml( ) );
129 }
130 }
131
132 String strDayOfMonth = Utils.getWeekDayLabel( Utils.getDate( calendar ), locale );
133 String strDateLink = Utils.getDate( calendar );
134 HashMap<String, Object> dayModel = new HashMap<String, Object>( );
135 dayModel.put( Constants.MARK_DAY_CLASS, getDayClass( calendar ) );
136 dayModel.put( Constants.MARK_DAY, strDayOfMonth );
137 dayModel.put( Constants.MARK_DAY_LINK, strDateLink );
138 dayModel.put( Constants.MARK_EVENTS, sbEvents.toString( ) );
139 dayModel.put( Constants.MARK_JSP_URL, AppPropertiesService.getProperty( Constants.PROPERTY_RUNAPP_JSP_URL ) );
140
141 HtmlTemplate tDay = AppTemplateService.getTemplate( TEMPLATE_VIEW_WEEK_DAY, locale, dayModel );
142
143 return tDay.getHtml( );
144 }
145
146
147
148
149
150
151 private String getDayClass( Calendar calendar )
152 {
153 String strClass = Constants.STYLE_CLASS_VIEW_MONTH_DAY;
154 String strDate = Utils.getDate( calendar );
155 String strToday = Utils.getDateToday( );
156
157 if ( Utils.isDayOff( calendar ) )
158 {
159 strClass += Constants.STYLE_CLASS_SUFFIX_OFF;
160 }
161 else if ( strDate.compareTo( strToday ) < 0 )
162 {
163 strClass += Constants.STYLE_CLASS_SUFFIX_OLD;
164 }
165 else if ( strDate.equals( strToday ) )
166 {
167 strClass += Constants.STYLE_CLASS_SUFFIX_TODAY;
168 }
169
170 return strClass;
171 }
172
173
174
175
176
177
178
179 public String getNext( String strDate )
180 {
181 return Utils.getNextWeek( strDate );
182 }
183
184
185
186
187
188
189
190 public String getPrevious( String strDate )
191 {
192 return Utils.getPreviousWeek( strDate );
193 }
194
195
196
197
198
199
200
201 public String getTitle( String strDate, CalendarUserOptions options )
202 {
203 String strTitle = Utils.getWeekLabel( strDate, Locale.getDefault( ) );
204
205 return strTitle;
206 }
207
208
209
210
211
212
213
214 public String getPath( String strDate, CalendarUserOptions options )
215 {
216 return getTitle( strDate, options );
217 }
218
219
220
221
222
223 public int getType( )
224 {
225 return CalendarView.TYPE_WEEK;
226 }
227 }