Changeset View
Changeset View
Standalone View
Standalone View
plugins/libcalendaring/libcalendaring.js
Show First 20 Lines • Show All 564 Lines • ▼ Show 20 Lines | function rcube_libcalendaring(settings) | ||||
* Display a notification for the given pending alarms | * Display a notification for the given pending alarms | ||||
*/ | */ | ||||
this.display_alarms = function(alarms) | this.display_alarms = function(alarms) | ||||
{ | { | ||||
// clear old alert first | // clear old alert first | ||||
if (this.alarm_dialog) | if (this.alarm_dialog) | ||||
this.alarm_dialog.dialog('destroy').remove(); | this.alarm_dialog.dialog('destroy').remove(); | ||||
this.alarm_dialog = $('<div>').attr('id', 'alarm-display'); | var i, actions, adismiss, asnooze, alarm, html, | ||||
audio_alarms = [], records = [], event_ids = [], buttons = {}; | |||||
var i, actions, adismiss, asnooze, alarm, html, event_ids = [], buttons = {}; | |||||
for (i=0; i < alarms.length; i++) { | for (i=0; i < alarms.length; i++) { | ||||
alarm = alarms[i]; | alarm = alarms[i]; | ||||
alarm.start = this.parseISO8601(alarm.start); | alarm.start = this.parseISO8601(alarm.start); | ||||
alarm.end = this.parseISO8601(alarm.end); | alarm.end = this.parseISO8601(alarm.end); | ||||
if (alarm.action == 'AUDIO') { | |||||
audio_alarms.push(alarm); | |||||
continue; | |||||
} | |||||
event_ids.push(alarm.id); | event_ids.push(alarm.id); | ||||
html = '<h3 class="event-title">' + Q(alarm.title) + '</h3>'; | html = '<h3 class="event-title">' + Q(alarm.title) + '</h3>'; | ||||
html += '<div class="event-section">' + Q(alarm.location || '') + '</div>'; | html += '<div class="event-section">' + Q(alarm.location || '') + '</div>'; | ||||
html += '<div class="event-section">' + Q(this.event_date_text(alarm)) + '</div>'; | html += '<div class="event-section">' + Q(this.event_date_text(alarm)) + '</div>'; | ||||
adismiss = $('<a href="#" class="alarm-action-dismiss"></a>').html(rcmail.gettext('dismiss','libcalendaring')).click(function(e){ | adismiss = $('<a href="#" class="alarm-action-dismiss"></a>').html(rcmail.gettext('dismiss','libcalendaring')).click(function(e){ | ||||
me.dismiss_link = $(this); | me.dismiss_link = $(this); | ||||
me.dismiss_alarm(me.dismiss_link.data('id'), 0, e); | me.dismiss_alarm(me.dismiss_link.data('id'), 0, e); | ||||
}); | }); | ||||
asnooze = $('<a href="#" class="alarm-action-snooze"></a>').html(rcmail.gettext('snooze','libcalendaring')).click(function(e){ | asnooze = $('<a href="#" class="alarm-action-snooze"></a>').html(rcmail.gettext('snooze','libcalendaring')).click(function(e){ | ||||
me.snooze_dropdown($(this), e); | me.snooze_dropdown($(this), e); | ||||
e.stopPropagation(); | e.stopPropagation(); | ||||
return false; | return false; | ||||
}); | }); | ||||
actions = $('<div>').addClass('alarm-actions').append(adismiss.data('id', alarm.id)).append(asnooze.data('id', alarm.id)); | actions = $('<div>').addClass('alarm-actions').append(adismiss.data('id', alarm.id)).append(asnooze.data('id', alarm.id)); | ||||
$('<div>').addClass('alarm-item').html(html).append(actions).appendTo(this.alarm_dialog); | records.push($('<div>').addClass('alarm-item').html(html).append(actions)); | ||||
} | } | ||||
if (audio_alarms.length) | |||||
this.audio_alarms(audio_alarms); | |||||
if (!records.length) | |||||
return; | |||||
this.alarm_dialog = $('<div>').attr('id', 'alarm-display').append(records); | |||||
buttons[rcmail.gettext('close')] = function() { | buttons[rcmail.gettext('close')] = function() { | ||||
$(this).dialog('close'); | $(this).dialog('close'); | ||||
}; | }; | ||||
buttons[rcmail.gettext('dismissall','libcalendaring')] = function(e) { | buttons[rcmail.gettext('dismissall','libcalendaring')] = function(e) { | ||||
// submit dismissed event_ids to server | // submit dismissed event_ids to server | ||||
me.dismiss_alarm(me.alarm_ids.join(','), 0, e); | me.dismiss_alarm(me.alarm_ids.join(','), 0, e); | ||||
$(this).dialog('close'); | $(this).dialog('close'); | ||||
Show All 23 Lines | this.display_alarms = function(alarms) | ||||
}); | }); | ||||
this.alarm_dialog.closest('div[role=dialog]').attr('role', 'alertdialog'); | this.alarm_dialog.closest('div[role=dialog]').attr('role', 'alertdialog'); | ||||
this.alarm_ids = event_ids; | this.alarm_ids = event_ids; | ||||
}; | }; | ||||
/** | /** | ||||
* Display a notification and play a sound for a set of alarms | |||||
*/ | |||||
this.audio_alarms = function(alarms) | |||||
{ | |||||
var elem, txt = [], | |||||
src = rcmail.assets_path('plugins/libcalendaring/alarm'), | |||||
plugin = navigator.mimeTypes ? navigator.mimeTypes['audio/mp3'] : {}; | |||||
// first generate and display notification text | |||||
$.each(alarms, function() { txt.push(this.title); }); | |||||
rcmail.display_message(rcmail.gettext('alarmtitle','libcalendaring') + ': ' + Q(txt.join(', ')), 'notice', 10000); | |||||
// Internet Explorer does not support wav files, | |||||
// support in other browsers depends on enabled plugins, | |||||
// so we use wav as a fallback | |||||
src += bw.ie || (plugin && plugin.enabledPlugin) ? '.mp3' : '.wav'; | |||||
// HTML5 | |||||
try { | |||||
elem = $('<audio>').attr('src', src); | |||||
elem.get(0).play(); | |||||
} | |||||
// old method | |||||
catch (e) { | |||||
elem = $('<embed id="libcalsound" src="' + src + '" hidden=true autostart=true loop=false />'); | |||||
elem.appendTo($('body')); | |||||
window.setTimeout("$('#libcalsound').remove()", 10000); | |||||
} | |||||
}; | |||||
/** | |||||
* Show a drop-down menu with a selection of snooze times | * Show a drop-down menu with a selection of snooze times | ||||
*/ | */ | ||||
this.snooze_dropdown = function(link, event) | this.snooze_dropdown = function(link, event) | ||||
{ | { | ||||
if (!this.snooze_popup) { | if (!this.snooze_popup) { | ||||
this.snooze_popup = $('#alarm-snooze-dropdown'); | this.snooze_popup = $('#alarm-snooze-dropdown'); | ||||
// create popup if not found | // create popup if not found | ||||
if (!this.snooze_popup.length) { | if (!this.snooze_popup.length) { | ||||
▲ Show 20 Lines • Show All 678 Lines • Show Last 20 Lines |