176 paginable = False |
176 paginable = False |
177 title = _('calendar') |
177 title = _('calendar') |
178 |
178 |
179 fullcalendar_options = { |
179 fullcalendar_options = { |
180 'firstDay': 1, |
180 'firstDay': 1, |
|
181 'firstHour': 8, |
|
182 'defaultView': 'month', |
|
183 'editable': True, |
181 'header': {'left': 'prev,next today', |
184 'header': {'left': 'prev,next today', |
182 'center': 'title', |
185 'center': 'title', |
183 'right': 'month,agendaWeek,agendaDay', |
186 'right': 'month,agendaWeek,agendaDay', |
184 }, |
187 }, |
185 'editable': True, |
|
186 'defaultView': 'month', |
|
187 'timeFormat': {'month': '', |
|
188 '': 'H:mm'}, |
|
189 'firstHour': 8, |
|
190 'axisFormat': 'H:mm', |
|
191 'columnFormat': {'month': 'dddd', |
|
192 'agendaWeek': 'dddd yyyy/M/dd', |
|
193 'agendaDay': 'dddd yyyy/M/dd'} |
|
194 } |
188 } |
195 |
|
196 |
189 |
197 def call(self): |
190 def call(self): |
198 self._cw.demote_to_html() |
191 self._cw.demote_to_html() |
199 self._cw.add_css(('fullcalendar.css', 'cubicweb.calendar.css')) |
192 self._cw.add_css(('fullcalendar.css', 'cubicweb.calendar.css')) |
200 self._cw.add_js(('jquery.ui.js', 'fullcalendar.min.js', 'jquery.qtip.min.js')) |
193 self._cw.add_js(('jquery.ui.js', 'fullcalendar.min.js', 'jquery.qtip.min.js')) |
201 self.calendar_id = 'cal' + make_uid('uid') |
194 self.calendar_id = 'cal' + make_uid('uid') |
202 self.add_onload() |
195 self.add_onload() |
203 # write calendar div to load jquery fullcalendar object |
196 # write calendar div to load jquery fullcalendar object |
204 self.w(u'<div id="%s"></div>' % self.calendar_id) |
197 self.w(u'<div id="%s"></div>' % self.calendar_id) |
205 |
198 |
206 |
|
207 def add_onload(self): |
199 def add_onload(self): |
208 fullcalendar_options = self.fullcalendar_options.copy() |
200 # i18n |
209 fullcalendar_options['events'] = self.get_events() |
201 self._cw.add_js('fullcalendar.locale.js') |
210 fullcalendar_options['buttonText'] = {'today': self._cw._('today'), |
|
211 'month': self._cw._('month'), |
|
212 'week': self._cw._('week'), |
|
213 'day': self._cw._('day')} |
|
214 # js callback to add a tooltip and to put html in event's title |
202 # js callback to add a tooltip and to put html in event's title |
215 js = """ |
203 js = """ |
216 var options = %s; |
204 var options = $.fullCalendar.regional('%s', %s); |
217 options.eventRender = function(event, $element) { |
205 options.eventRender = function(event, $element) { |
218 // add a tooltip for each event |
206 // add a tooltip for each event |
219 var div = '<div class="tooltip">'+ event.description+ '</div>'; |
207 var div = '<div class="tooltip">'+ event.description+ '</div>'; |
220 $element.append(div); |
208 $element.append(div); |
221 // allow to have html tags in event's title |
209 // allow to have html tags in event's title |
222 $element.find('span.fc-event-title').html($element.find('span.fc-event-title').text()); |
210 $element.find('span.fc-event-title').html($element.find('span.fc-event-title').text()); |
223 }; |
211 }; |
224 $("#%s").fullCalendar(options); |
212 $("#%s").fullCalendar(options); |
225 """ #" |
213 """ #" |
226 self._cw.add_onload(js % (json_dumps(fullcalendar_options), self.calendar_id)) |
214 self._cw.add_onload(js % (self._cw.lang, json_dumps(self.fullcalendar_options), self.calendar_id)) |
227 |
215 |
228 |
216 |
229 def get_events(self): |
217 def get_events(self): |
230 events = [] |
218 events = [] |
231 for entity in self.cw_rset.entities(): |
219 for entity in self.cw_rset.entities(): |