diff options
author | Thomas Bruederli <bruederli@kolabsys.com> | 2014-08-19 08:37:31 (GMT) |
---|---|---|
committer | Thomas Bruederli <bruederli@kolabsys.com> | 2014-08-19 08:37:40 (GMT) |
commit | ff9f87a037687a62dbd0070a6d2582fb9ec14d3b (patch) | |
tree | ccef9aeb84be644d7bcbbc40207a37c826a22f02 /plugins/libcalendaring | |
parent | 0747f9f95dbe245f63b85f55328377d2565b6839 (diff) | |
download | roundcubemail-plugins-kolab-ff9f87a037687a62dbd0070a6d2582fb9ec14d3b.tar.gz |
Add button to expand members of a group attendee (#3376); prefix edit-attendees-table styles to avoid unintended style overrides
Diffstat (limited to 'plugins/libcalendaring')
-rw-r--r-- | plugins/libcalendaring/libcalendaring.js | 59 | ||||
-rw-r--r-- | plugins/libcalendaring/libcalendaring.php | 56 | ||||
-rw-r--r-- | plugins/libcalendaring/localization/en_US.inc | 6 |
3 files changed, 121 insertions, 0 deletions
diff --git a/plugins/libcalendaring/libcalendaring.js b/plugins/libcalendaring/libcalendaring.js index 6f20ab7..39b34ae 100644 --- a/plugins/libcalendaring/libcalendaring.js +++ b/plugins/libcalendaring/libcalendaring.js @@ -33,6 +33,7 @@ function rcube_libcalendaring(settings) this.alarm_dialog = null; this.snooze_popup = null; this.dismiss_link = null; + this.group2expand = {}; // abort if env isn't set if (!settings || !settings.date_format) @@ -729,6 +730,64 @@ function rcube_libcalendaring(settings) $.each(listitems, function(idx, item) { mylist.append(item); }); }; + + /***** Attendee form handling *****/ + + // expand the given contact group into individual event/task attendees + this.expand_attendee_group = function(e, add, remove) + { + var id = (e.data ? e.data.email : null) || $(e.target).attr('data-email'), + role_select = $(e.target).closest('tr').find('select.edit-attendee-role option:selected'); + + this.group2expand[id] = { link: e.target, data: $.extend({}, e.data || {}), adder: add, remover: remove } + + // copy group role from the according form element + if (role_select.length) { + this.group2expand[id].data.role = role_select.val(); + } + + // register callback handler + if (!this._expand_attendee_listener) { + this._expand_attendee_listener = this.expand_attendee_callback; + rcmail.addEventListener('plugin.expand_attendee_callback', function(result) { + me._expand_attendee_listener(result); + }); + } + + rcmail.http_post('libcal/plugin.expand_attendee_group', { id: id, data: e.data || {} }, rcmail.set_busy(true, 'loading')); + }; + + // callback from server to expand an attendee group + this.expand_attendee_callback = function(result) + { + var attendee, id = result.id, + data = this.group2expand[id], + row = $(data.link).closest('tr'); + + // replace group entry with all members returned by the server + if (data && data.adder && result.members && result.members.length) { + for (var i=0; i < result.members.length; i++) { + attendee = result.members[i]; + attendee.role = data.data.role; + attendee.cutype = 'INDIVIDUAL'; + attendee.status = 'NEEDS-ACTION'; + data.adder(attendee, null, row); + } + + if (data.remover) { + data.remover(data.link, id) + } + else { + row.remove(); + } + + delete this.group2expand[id]; + } + else { + rcmail.display_message(result.error || rcmail.gettext('expandattendeegroupnodata','libcalendaring'), 'error'); + } + }; + } ////// static methods diff --git a/plugins/libcalendaring/libcalendaring.php b/plugins/libcalendaring/libcalendaring.php index 6ca548e..52a8134 100644 --- a/plugins/libcalendaring/libcalendaring.php +++ b/plugins/libcalendaring/libcalendaring.php @@ -106,6 +106,7 @@ class libcalendaring extends rcube_plugin // add hook to display alarms $this->add_hook('refresh', array($this, 'refresh')); $this->register_action('plugin.alarms', array($this, 'alarms_action')); + $this->register_action('plugin.expand_attendee_group', array($this, 'expand_attendee_group')); } // proceed initialization in startup hook @@ -1359,6 +1360,61 @@ class libcalendaring extends rcube_plugin } + /********* Attendee handling functions *********/ + + /** + * Handler for attendee group expansion requests + */ + public function expand_attendee_group() + { + $id = rcube_utils::get_input_value('id', rcube_utils::INPUT_POST); + $data = rcube_utils::get_input_value('data', rcube_utils::INPUT_POST, true); + $result = array('id' => $id, 'members' => array()); + $maxnum = 500; + + // iterate over all autocomplete address books (we don't know the source of the group) + foreach ((array)$this->rc->config->get('autocomplete_addressbooks', 'sql') as $abook_id) { + if (($abook = $this->rc->get_address_book($abook_id)) && $abook->groups) { + foreach ($abook->list_groups($data['name'], 1) as $group) { + // this is the matching group to expand + if (in_array($data['email'], (array)$group['email'])) { + $abook->set_pagesize($maxnum); + $abook->set_group($group['ID']); + + // get all members + $res = $abook->list_records($this->rc->config->get('contactlist_fields')); + + // handle errors (e.g. sizelimit, timelimit) + if ($abook->get_error()) { + $result['error'] = $this->rc->gettext('expandattendeegrouperror', 'libcalendaring'); + $res = false; + } + // check for maximum number of members (we don't wanna bloat the UI too much) + else if ($res->count > $maxnum) { + $result['error'] = $this->rc->gettext('expandattendeegroupsizelimit', 'libcalendaring'); + $res = false; + } + + while ($res && ($member = $res->iterate())) { + $emails = (array)$abook->get_col_values('email', $member, true); + if (!empty($emails) && ($email = array_shift($emails))) { + $result['members'][] = array( + 'email' => $email, + 'name' => rcube_addressbook::compose_list_name($member), + ); + } + } + + break 2; + } + } + } + } + + $this->rc->output->command('plugin.expand_attendee_callback', $result); + } + + /********* Static utility functions *********/ /** diff --git a/plugins/libcalendaring/localization/en_US.inc b/plugins/libcalendaring/localization/en_US.inc index 5ad34ed..82fb7a8 100644 --- a/plugins/libcalendaring/localization/en_US.inc +++ b/plugins/libcalendaring/localization/en_US.inc @@ -140,3 +140,9 @@ $labels['declinedeleteconfirm'] = 'Do you also want to delete this declined obje $labels['savingdata'] = 'Saving data...'; +// attendees labels +$labels['expandattendeegroup'] = 'Substitute with group members'; +$labels['expandattendeegroupnodata'] = 'Unable to substitute this group. No members found.'; +$labels['expandattendeegrouperror'] = 'Unable to substitute this group. It might contain too many members.'; +$labels['expandattendeegroupsizelimit'] = 'This group contains too many members for substituting.'; + |