Added generator for random event data; improved event display (with lots of events); save hidden calendars in user prefs
This commit is contained in:
parent
92d4974a49
commit
80ebe6f445
4 changed files with 123 additions and 12 deletions
|
@ -30,7 +30,8 @@ function rcube_calendar(settings)
|
|||
this.alarm_ids = [];
|
||||
this.alarm_dialog = null;
|
||||
this.snooze_popup = null;
|
||||
this.dismiss_link = null
|
||||
this.dismiss_link = null;
|
||||
this.eventcount = [];
|
||||
|
||||
|
||||
/*** private vars ***/
|
||||
|
@ -600,9 +601,11 @@ function rcube_calendar(settings)
|
|||
};
|
||||
|
||||
|
||||
/*** startup code ***/
|
||||
|
||||
// create list of event sources AKA calendars
|
||||
this.calendars = {};
|
||||
var li, cal, event_sources = [];
|
||||
var li, cal, active, event_sources = [];
|
||||
for (var id in rcmail.env.calendars) {
|
||||
cal = rcmail.env.calendars[id];
|
||||
this.calendars[id] = $.extend({
|
||||
|
@ -611,17 +614,29 @@ function rcube_calendar(settings)
|
|||
className: 'fc-event-cal-'+id,
|
||||
id: id
|
||||
}, cal);
|
||||
event_sources.push(this.calendars[id]);
|
||||
|
||||
if ((active = ($.inArray(String(id), settings.hidden_calendars) < 0)))
|
||||
event_sources.push(this.calendars[id]);
|
||||
|
||||
// init event handler on calendar list checkbox
|
||||
if ((li = rcmail.get_folder_li(id, 'rcmlical'))) {
|
||||
$('#'+li.id+' input').click(function(e){
|
||||
var id = $(this).data('id');
|
||||
if (me.calendars[id]) { // add or remove event source on click
|
||||
var action = this.checked ? 'addEventSource' : 'removeEventSource';
|
||||
var action;
|
||||
if (this.checked) {
|
||||
action = 'addEventSource';
|
||||
settings.hidden_calendars = $.map(settings.hidden_calendars, function(v){ return v == id ? null : v; });
|
||||
}
|
||||
else {
|
||||
action = 'removeEventSource';
|
||||
settings.hidden_calendars.push(id);
|
||||
}
|
||||
$('#calendar').fullCalendar(action, me.calendars[id]);
|
||||
rcmail.save_pref({ name:'hidden_calendars', value:settings.hidden_calendars.join(',') });
|
||||
}
|
||||
}).data('id', id);
|
||||
}).data('id', id).get(0).checked = active;
|
||||
|
||||
$(li).click(function(e){
|
||||
var id = $(this).data('id');
|
||||
rcmail.select_folder(id, me.selected_calendar, 'rcmlical');
|
||||
|
@ -643,7 +658,7 @@ function rcube_calendar(settings)
|
|||
right: 'agendaDay,agendaWeek,month'
|
||||
},
|
||||
aspectRatio: 1,
|
||||
height: $(window).height() - 95,
|
||||
height: $(window).height() - 96,
|
||||
eventSources: event_sources,
|
||||
monthNames : settings['months'],
|
||||
monthNamesShort : settings['months_short'],
|
||||
|
@ -679,7 +694,23 @@ function rcube_calendar(settings)
|
|||
},
|
||||
// event rendering
|
||||
eventRender: function(event, element, view) {
|
||||
if(view.name != "month") {
|
||||
element.attr('title', event.title);
|
||||
if (view.name == 'month') {
|
||||
/* attempt to limit the number of events displayed
|
||||
(could also be used to init fish-eye-view)
|
||||
var max = 4; // to be derrived from window size
|
||||
var sday = event.start.getMonth()*12 + event.start.getDate();
|
||||
var eday = event.end.getMonth()*12 + event.end.getDate();
|
||||
if (!me.eventcount[sday]) me.eventcount[sday] = 1;
|
||||
else me.eventcount[sday]++;
|
||||
if (!me.eventcount[eday]) me.eventcount[eday] = 1;
|
||||
else if (eday != sday) me.eventcount[eday]++;
|
||||
|
||||
if (me.eventcount[sday] > max || me.eventcount[eday] > max)
|
||||
return false;
|
||||
*/
|
||||
}
|
||||
else {
|
||||
if (event.location) {
|
||||
element.find('div.fc-event-title').after('<div class="fc-event-location">@ ' + Q(event.location) + '</div>');
|
||||
}
|
||||
|
@ -713,7 +744,7 @@ function rcube_calendar(settings)
|
|||
day_clicked_ts = now;
|
||||
},
|
||||
// callback when a specific event is clicked
|
||||
eventClick : function(event) {
|
||||
eventClick: function(event) {
|
||||
event_show_dialog(event);
|
||||
},
|
||||
// callback when an event was dragged and finally dropped
|
||||
|
@ -734,7 +765,7 @@ function rcube_calendar(settings)
|
|||
rcmail.http_post('plugin.event', { action:'move', e:data });
|
||||
},
|
||||
// callback for event resizing
|
||||
eventResize : function(event, delta) {
|
||||
eventResize: function(event, delta) {
|
||||
// send resize request to server
|
||||
var data = {
|
||||
id: event.id,
|
||||
|
@ -745,6 +776,13 @@ function rcube_calendar(settings)
|
|||
recurring_edit_confirm(data, 'resize');
|
||||
else
|
||||
rcmail.http_post('plugin.event', { action:'resize', e:data });
|
||||
},
|
||||
viewDisplay: function(view) {
|
||||
me.eventcount = [];
|
||||
window.setTimeout(function(){ $('div.fc-content').css('overflow', view.name == 'month' ? 'auto' : 'hidden') }, 10);
|
||||
},
|
||||
windowResize: function(view) {
|
||||
me.eventcount = [];
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -912,10 +950,9 @@ window.rcmail && rcmail.addEventListener('init', function(evt) {
|
|||
|
||||
// let's go
|
||||
var cal = new rcube_calendar(rcmail.env.calendar_settings);
|
||||
cal.init_ui();
|
||||
|
||||
$(window).resize(function() {
|
||||
$('#calendar').fullCalendar('option', 'height', $(window).height() - 95);
|
||||
$('#calendar').fullCalendar('option', 'height', $(window).height() - 96);
|
||||
}).resize();
|
||||
|
||||
// show toolbar
|
||||
|
|
|
@ -75,6 +75,7 @@ class calendar extends rcube_plugin
|
|||
$this->register_action('plugin.load_events', array($this, 'load_events'));
|
||||
$this->register_action('plugin.event', array($this, 'event'));
|
||||
$this->register_action('plugin.export_events', array($this, 'export_events'));
|
||||
$this->register_action('plugin.randomdata', array($this, 'generate_randomdata'));
|
||||
$this->add_hook('keep_alive', array($this, 'keep_alive'));
|
||||
|
||||
// set user's timezone
|
||||
|
@ -472,6 +473,9 @@ class calendar extends rcube_plugin
|
|||
$this->rc->gettext('nov'), $this->rc->gettext('dec')
|
||||
);
|
||||
$settings['today'] = rcube_label('today');
|
||||
|
||||
// user prefs
|
||||
$settings['hidden_calendars'] = array_filter(explode(',', $this->rc->config->get('hidden_calendars', '')));
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
@ -694,5 +698,53 @@ class calendar extends rcube_plugin
|
|||
'u' => 'c',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* TEMPORARY: generate random event data for testing
|
||||
* Create events by opening http://<roundcubeurl>/?_task=calendar&_action=plugin.randomdata&_num=500
|
||||
*/
|
||||
public function generate_randomdata()
|
||||
{
|
||||
$cats = array_keys($this->driver->list_categories());
|
||||
$cals = $this->driver->list_calendars();
|
||||
$num = $_REQUEST['_num'] ? intval($_REQUEST['_num']) : 100;
|
||||
|
||||
while ($count++ < $num) {
|
||||
$start = round((time() + rand(-2600, 2600) * 1000) / 300) * 300;
|
||||
$duration = round(rand(30, 360) / 30) * 30 * 60;
|
||||
$allday = rand(0,20) > 18;
|
||||
$alarm = rand(-30,12) * 5;
|
||||
$fb = rand(0,2);
|
||||
|
||||
if (date('G', $start) > 23)
|
||||
$start -= 3600;
|
||||
|
||||
if ($allday) {
|
||||
$start = strtotime(date('Y-m-d 00:00:00', $start));
|
||||
$duration = 86399;
|
||||
}
|
||||
|
||||
$title = '';
|
||||
$len = rand(4, 40);
|
||||
$chars = "!# abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890";
|
||||
for ($i = 0; $i < $len; $i++)
|
||||
$title .= $chars[rand(0,strlen($chars)-1)];
|
||||
|
||||
$this->driver->new_event(array(
|
||||
'uid' => $this->generate_uid(),
|
||||
'start' => $start,
|
||||
'end' => $start + $duration,
|
||||
'allday' => $allday,
|
||||
'title' => $title,
|
||||
'free_busy' => $fb == 2 ? 'outofoffice' : ($fb ? 'busy' : 'free'),
|
||||
'categories' => $cats[array_rand($cats)],
|
||||
'calendar' => array_rand($cals),
|
||||
'alarms' => $alarm > 0 ? "-{$alarm}M:DISPLAY" : '',
|
||||
'priority' => 1,
|
||||
));
|
||||
}
|
||||
|
||||
$this->rc->output->redirect('');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -126,6 +126,7 @@ class calendar_ui
|
|||
function calendar_list($attrib = array())
|
||||
{
|
||||
$calendars = $this->calendar->driver->list_calendars();
|
||||
$hidden = explode(',', $this->rc->config->get('hidden_calendars', ''));
|
||||
|
||||
$li = '';
|
||||
foreach ((array)$calendars as $id => $prop) {
|
||||
|
@ -137,7 +138,7 @@ class calendar_ui
|
|||
|
||||
$html_id = html_identifier($id);
|
||||
$li .= html::tag('li', array('id' => 'rcmlical' . $html_id, 'class' =>'cal-' . asciiwords($id, true)),
|
||||
html::tag('input', array('type' => 'checkbox', 'name' => '_cal[]', 'value' => $id, 'checked' => true), '') . html::span(null, Q($prop['name'])));
|
||||
html::tag('input', array('type' => 'checkbox', 'name' => '_cal[]', 'value' => $id, 'checked' => !in_array($id, $hidden)), '') . html::span(null, Q($prop['name'])));
|
||||
}
|
||||
|
||||
$this->rc->output->set_env('calendars', $jsenv);
|
||||
|
|
|
@ -434,10 +434,31 @@ a.alarm-action-snooze:after {
|
|||
|
||||
/* fullcalendar style overrides */
|
||||
|
||||
.fc-content {
|
||||
position: absolute !important;
|
||||
top: 37px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.fc-event-title {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.fc-event-hori .fc-event-title {
|
||||
font-weight: normal;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.fc-event-hori .fc-event-time {
|
||||
white-space: nowrap;
|
||||
font-weight: normal;
|
||||
font-size: 10px;
|
||||
padding-right: 0.6em;
|
||||
}
|
||||
|
||||
.fc-event-cateories {
|
||||
font-style:italic;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue