Delegation support in Calendar event edit/create
This commit is contained in:
parent
8e5a92044e
commit
343a4371ab
4 changed files with 163 additions and 7 deletions
|
@ -253,6 +253,9 @@ function rcube_calendar_ui(settings)
|
||||||
var calendar = event.calendar && me.calendars[event.calendar] ? me.calendars[event.calendar] : { editable:false };
|
var calendar = event.calendar && me.calendars[event.calendar] ? me.calendars[event.calendar] : { editable:false };
|
||||||
me.selected_event = event;
|
me.selected_event = event;
|
||||||
|
|
||||||
|
// allow other plugins to do actions when event form is opened
|
||||||
|
rcmail.triggerEvent('calendar-event-init', {o: event});
|
||||||
|
|
||||||
$dialog.find('div.event-section, div.event-line').hide();
|
$dialog.find('div.event-section, div.event-line').hide();
|
||||||
$('#event-title').html(Q(event.title)).show();
|
$('#event-title').html(Q(event.title)).show();
|
||||||
|
|
||||||
|
@ -393,6 +396,9 @@ function rcube_calendar_ui(settings)
|
||||||
// reset dialog first
|
// reset dialog first
|
||||||
$('#eventtabs').get(0).reset();
|
$('#eventtabs').get(0).reset();
|
||||||
|
|
||||||
|
// allow other plugins to do actions when event form is opened
|
||||||
|
rcmail.triggerEvent('calendar-event-init', {o: event});
|
||||||
|
|
||||||
// event details
|
// event details
|
||||||
var title = $('#edit-title').val(event.title || '');
|
var title = $('#edit-title').val(event.title || '');
|
||||||
var location = $('#edit-location').val(event.location || '');
|
var location = $('#edit-location').val(event.location || '');
|
||||||
|
@ -552,7 +558,6 @@ function rcube_calendar_ui(settings)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// init dialog buttons
|
// init dialog buttons
|
||||||
var buttons = {};
|
var buttons = {};
|
||||||
|
|
||||||
|
@ -1412,6 +1417,10 @@ function rcube_calendar_ui(settings)
|
||||||
tr.find('a.deletelink').click({ id:(data.email || data.name) }, function(e) { remove_attendee(this, e.data.id); return false; });
|
tr.find('a.deletelink').click({ id:(data.email || data.name) }, function(e) { remove_attendee(this, e.data.id); return false; });
|
||||||
tr.find('a.mailtolink').click(function(e) { rcmail.redirect(rcmail.url('mail/compose', { _to:this.href.substr(7) })); return false; });
|
tr.find('a.mailtolink').click(function(e) { rcmail.redirect(rcmail.url('mail/compose', { _to:this.href.substr(7) })); return false; });
|
||||||
|
|
||||||
|
// select organizer identity
|
||||||
|
if (data.identity_id)
|
||||||
|
$('#edit-identities-list').val(data.identity_id);
|
||||||
|
|
||||||
// check free-busy status
|
// check free-busy status
|
||||||
if (avail == 'loading') {
|
if (avail == 'loading') {
|
||||||
check_freebusy_status(tr.find('img.availabilityicon'), data.email, me.selected_event);
|
check_freebusy_status(tr.find('img.availabilityicon'), data.email, me.selected_event);
|
||||||
|
@ -2607,7 +2616,7 @@ function rcube_calendar_ui(settings)
|
||||||
|
|
||||||
$('#event-rsvp input.button').click(function(){
|
$('#event-rsvp input.button').click(function(){
|
||||||
event_rsvp($(this).attr('rel'))
|
event_rsvp($(this).attr('rel'))
|
||||||
})
|
});
|
||||||
|
|
||||||
$('#agenda-listrange').change(function(e){
|
$('#agenda-listrange').change(function(e){
|
||||||
settings['agenda_range'] = parseInt($(this).val());
|
settings['agenda_range'] = parseInt($(this).val());
|
||||||
|
|
|
@ -22,10 +22,18 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
window.rcmail && rcmail.addEventListener('init', function(evt) {
|
window.rcmail && rcmail.addEventListener('init', function(evt) {
|
||||||
if (rcmail.env.task == 'mail') {
|
if (rcmail.env.task == 'mail' || rcmail.env.task == 'calendar') {
|
||||||
// set delegator context for calendar requests on invitation message
|
// set delegator context for calendar requests on invitation message
|
||||||
rcmail.addEventListener('requestcalendar/event', function(o) { rcmail.event_delegator_request(o); });
|
rcmail.addEventListener('requestcalendar/event', function(o) { rcmail.event_delegator_request(o); });
|
||||||
rcmail.addEventListener('requestcalendar/mailimportevent', function(o) { rcmail.event_delegator_request(o); });
|
rcmail.addEventListener('requestcalendar/mailimportevent', function(o) { rcmail.event_delegator_request(o); });
|
||||||
|
|
||||||
|
if (rcmail.env.delegators && window.rcube_calendar_ui) {
|
||||||
|
rcmail.calendar_identity_init();
|
||||||
|
// delegator context for calendar event form
|
||||||
|
rcmail.addEventListener('calendar-event-init', function(o) { return rcmail.calendar_event_init(o); });
|
||||||
|
// change organizer identity on calendar folder change
|
||||||
|
$('#edit-calendar').change(function() { rcmail.calendar_change(); });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (rcmail.env.task != 'settings')
|
else if (rcmail.env.task != 'settings')
|
||||||
return;
|
return;
|
||||||
|
@ -239,3 +247,78 @@ rcube_webmail.prototype.event_delegator_request = function(data)
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// callback for calendar event form initialization
|
||||||
|
rcube_webmail.prototype.calendar_event_init = function(data)
|
||||||
|
{
|
||||||
|
// set identity for delegator context
|
||||||
|
this.env.calendar_settings.identity = this.calendar_folder_delegator(data.o.calendar);
|
||||||
|
};
|
||||||
|
|
||||||
|
// returns delegator's identity data according to selected calendar folder
|
||||||
|
rcube_webmail.prototype.calendar_folder_delegator = function(calendar)
|
||||||
|
{
|
||||||
|
var d, delegator;
|
||||||
|
|
||||||
|
$.each(this.env.namespace, function(i, v) {
|
||||||
|
var delim = v[v.length-1], pos;
|
||||||
|
if (calendar.indexOf(v) === 0 && (pos = calendar.indexOf(delim, v.length))) {
|
||||||
|
delegator = calendar.substr(v.length, pos - v.length)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (delegator && (d = this.env.delegators[delegator])) {
|
||||||
|
// find delegator's identity id
|
||||||
|
if (!d.identity_id)
|
||||||
|
$.each(this.env.calendar_settings.identities, function(i, v) {
|
||||||
|
if (d.email == v) {
|
||||||
|
d.identity_id = i;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
d.uid = delegator;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
d = this.env.original_identity;
|
||||||
|
|
||||||
|
this.env.delegator_context = d.uid;
|
||||||
|
|
||||||
|
return d;
|
||||||
|
};
|
||||||
|
|
||||||
|
// handler for calendar folder change
|
||||||
|
rcube_webmail.prototype.calendar_change = function()
|
||||||
|
{
|
||||||
|
var calendar = $('#edit-calendar').val(),
|
||||||
|
select = $('#edit-identities-list'),
|
||||||
|
old = this.env.calendar_settings.identity;
|
||||||
|
|
||||||
|
this.env.calendar_settings.identity = this.calendar_folder_delegator(calendar);
|
||||||
|
|
||||||
|
// change organizer identity in identity selector
|
||||||
|
if (select.length && old != this.env.calendar_settings.identity) {
|
||||||
|
// @TODO: run freebusy update?
|
||||||
|
var id = this.env.calendar_settings.identity.identity_id;
|
||||||
|
select.val(id ? id : '');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// modify default identity of the user
|
||||||
|
rcube_webmail.prototype.calendar_identity_init = function()
|
||||||
|
{
|
||||||
|
var identity = this.env.calendar_settings.identity,
|
||||||
|
emails = identity.emails.split(';');
|
||||||
|
|
||||||
|
// remove delegators' emails from list of emails of the current user
|
||||||
|
emails = $.map(emails, function(v) {
|
||||||
|
for (var n in rcmail.env.delegators)
|
||||||
|
if (rcmail.env.delegators[n].emails.indexOf(';'+v) > -1)
|
||||||
|
return null;
|
||||||
|
return v;
|
||||||
|
});
|
||||||
|
|
||||||
|
identity.emails = emails.join(';');
|
||||||
|
this.env.original_identity = identity;
|
||||||
|
}
|
||||||
|
|
|
@ -66,6 +66,10 @@ class kolab_delegation extends rcube_plugin
|
||||||
$this->include_stylesheet($this->skin_path . '/style.css');
|
$this->include_stylesheet($this->skin_path . '/style.css');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Calendar plugin UI bindings
|
||||||
|
else if ($this->rc->task == 'calendar' && empty($_REQUEST['_framed'])) {
|
||||||
|
$this->calendar_ui();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,6 +211,21 @@ class kolab_delegation extends rcube_plugin
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delegation support in Calendar plugin UI
|
||||||
|
*/
|
||||||
|
public function calendar_ui()
|
||||||
|
{
|
||||||
|
// Initialize handling of delegators' identities in event form
|
||||||
|
|
||||||
|
if (!empty($_SESSION['delegators'])) {
|
||||||
|
$engine = $this->engine();
|
||||||
|
$this->rc->output->set_env('namespace', $engine->namespace_js());
|
||||||
|
$this->rc->output->set_env('delegators', $engine->list_delegators_js());
|
||||||
|
$this->include_script('kolab_delegation.js');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delegation UI handler
|
* Delegation UI handler
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -296,6 +296,51 @@ class kolab_delegation_engine
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List current user delegators in format compatible with Calendar plugin
|
||||||
|
*
|
||||||
|
* @return array List of delegators
|
||||||
|
*/
|
||||||
|
public function list_delegators_js()
|
||||||
|
{
|
||||||
|
$list = $this->list_delegators();
|
||||||
|
$result = array();
|
||||||
|
|
||||||
|
foreach ($list as $delegator) {
|
||||||
|
$name = $delegator['name'];
|
||||||
|
if ($pos = strrpos($name, '(')) {
|
||||||
|
$name = trim(substr($name, 0, $pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
$result[$delegator['imap_uid']] = array(
|
||||||
|
'emails' => ';' . implode(';', $delegator['email']),
|
||||||
|
'email' => $delegator['email'][0],
|
||||||
|
'name' => $name,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare namespace prefixes for JS environment
|
||||||
|
*
|
||||||
|
* @return array List of prefixes
|
||||||
|
*/
|
||||||
|
public function namespace_js()
|
||||||
|
{
|
||||||
|
$storage = $this->rc->get_storage();
|
||||||
|
$ns = $storage->get_namespace('other');
|
||||||
|
|
||||||
|
if ($ns) {
|
||||||
|
foreach ($ns as $idx => $nsval) {
|
||||||
|
$ns[$idx] = kolab_storage::folder_id($nsval[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ns;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all folders to which current user has admin access
|
* Get all folders to which current user has admin access
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue