diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php index 43818247..1f008023 100644 --- a/plugins/calendar/calendar.php +++ b/plugins/calendar/calendar.php @@ -1957,7 +1957,8 @@ class calendar extends rcube_plugin */ public function attachment_upload() { - $this->lib->attachment_upload(self::SESSION_KEY, 'cal-'); + $handler = new kolab_attachments_handler(); + $handler->attachment_upload(self::SESSION_KEY, 'cal-'); } /** @@ -1965,9 +1966,11 @@ class calendar extends rcube_plugin */ public function attachment_get() { + $handler = new kolab_attachments_handler(); + // show loading page if (!empty($_GET['_preload'])) { - return $this->lib->attachment_loading_page(); + return $handler->attachment_loading_page(); } $event_id = rcube_utils::get_input_value('_event', rcube_utils::INPUT_GPC); @@ -1992,12 +1995,7 @@ class calendar extends rcube_plugin // show part page if (!empty($_GET['_frame'])) { - $this->lib->attachment = $attachment; - $this->register_handler('plugin.attachmentframe', array($this->lib, 'attachment_frame')); - $this->register_handler('plugin.attachmentcontrols', array($this->lib, 'attachment_header')); - $this->rc->output->set_env('filename', $attachment['name']); - $this->rc->output->set_env('mimetype', $attachment['mimetype']); - $this->rc->output->send('calendar.attachment'); + $handler->attachment_page($attachment); } // deliver attachment content else if ($attachment) { @@ -2005,7 +2003,7 @@ class calendar extends rcube_plugin $attachment['body'] = $this->driver->get_attachment_body($id, $event); } - $this->lib->attachment_get($attachment); + $handler->attachment_get($attachment); } // if we arrive here, the requested part was not found diff --git a/plugins/calendar/calendar_ui.js b/plugins/calendar/calendar_ui.js index 775f9350..966dc448 100644 --- a/plugins/calendar/calendar_ui.js +++ b/plugins/calendar/calendar_ui.js @@ -284,86 +284,32 @@ function rcube_calendar_ui(settings) return date.getHours() >= settings['work_start'] && date.getHours() < settings['work_end']; }; - var load_attachment = function(event, att) + var load_attachment = function(data) { - var query = { _id: att.id, _event: event.recurrence_id || event.id, _cal:event.calendar, _frame: 1 }; + var event = data.record, + query = {_id: data.attachment.id, _event: event.recurrence_id || event.id, _cal: event.calendar}; + if (event.rev) query._rev = event.rev; if (event.calendar == "--invitation--itip") $.extend(query, {_uid: event._uid, _part: event._part, _mbox: event._mbox}); - // open attachment in frame if it's of a supported mimetype - if (id && att.mimetype && $.inArray(att.mimetype, settings.mimetypes)>=0) { - if (rcmail.open_window(rcmail.url('get-attachment', query), true, true)) { - return; - } - } - - query._frame = null; - query._download = 1; - rcmail.goto_url('get-attachment', query, false); + libkolab.load_attachment(query, data.attachment); }; // build event attachments list var event_show_attachments = function(list, container, event, edit) { - var i, id, len, img, content, li, elem, - ul = document.createElement('UL'); - ul.className = 'attachmentslist'; - - for (i=0, len=list.length; i') - .attr('title', rcmail.gettext('delete')) - .attr('aria-label', rcmail.gettext('delete') + ' ' + Q(elem.name)) - .addClass('delete') - .click({id: elem.id}, function(e) { remove_attachment(this, e.data.id); return false; }); - - if (!rcmail.env.deleteicon) - content.html(rcmail.gettext('delete')); - else { - img = document.createElement('IMG'); - img.src = rcmail.env.deleteicon; - img.alt = rcmail.gettext('delete'); - content.append(img); - } - - content.appendTo(li); - } - - // name/link - content = $('') - .html(Q(elem.name)) - .addClass('file') - .click({event: event, att: elem}, function(e) { - load_attachment(e.data.event, e.data.att); - return false; - }) - .appendTo(li); - - ul.appendChild(li); - } - - if (edit && rcmail.gui_objects.attachmentlist) { - ul.id = rcmail.gui_objects.attachmentlist.id; - rcmail.gui_objects.attachmentlist = ul; - } - - container.empty().append(ul); + libkolab.list_attachments(list, container, edit, event, + function(id) { remove_attachment(id); }, + function(data) { load_attachment(data); } + ); }; - var remove_attachment = function(elem, id) + var remove_attachment = function(id) { - $(elem.parentNode).hide(); rcmail.env.deleted_attachments.push(id); - delete rcmail.env.attachments[id]; }; // event details dialog (show only) diff --git a/plugins/calendar/lib/calendar_ui.php b/plugins/calendar/lib/calendar_ui.php index f99c658c..54e20a61 100644 --- a/plugins/calendar/lib/calendar_ui.php +++ b/plugins/calendar/lib/calendar_ui.php @@ -80,9 +80,6 @@ class calendar_ui $this->cal->register_handler('plugin.sensitivity_select', array($this, 'sensitivity_select')); $this->cal->register_handler('plugin.alarm_select', array($this, 'alarm_select')); $this->cal->register_handler('plugin.recurrence_form', array($this->cal->lib, 'recurrence_form')); - $this->cal->register_handler('plugin.attachments_form', array($this, 'attachments_form')); - $this->cal->register_handler('plugin.attachments_list', array($this, 'attachments_list')); - $this->cal->register_handler('plugin.filedroparea', array($this, 'file_drop_area')); $this->cal->register_handler('plugin.attendees_list', array($this, 'attendees_list')); $this->cal->register_handler('plugin.attendees_form', array($this, 'attendees_form')); $this->cal->register_handler('plugin.resources_form', array($this, 'resources_form')); @@ -100,6 +97,8 @@ class calendar_ui $this->cal->register_handler('plugin.events_export_form', array($this, 'events_export_form')); $this->cal->register_handler('plugin.object_changelog_table', array('libkolab', 'object_changelog_table')); $this->cal->register_handler('plugin.searchform', array($this->rc->output, 'search_form')); // use generic method from rcube_template + + kolab_attachments_handler::ui(); } /** @@ -610,54 +609,6 @@ class calendar_ui ); } - /** - * Generate the form for event attachments upload - */ - function attachments_form($attrib = array()) - { - // add ID if not given - if (!$attrib['id']) { - $attrib['id'] = 'rcmUploadForm'; - } - - return $this->rc->upload_form($attrib, 'uploadform', 'upload-file', array('multiple' => true)); - } - - /** - * Register UI object for HTML5 drag & drop file upload - */ - function file_drop_area($attrib = array()) - { - if ($attrib['id']) { - $this->rc->output->add_gui_object('filedrop', $attrib['id']); - $this->rc->output->set_env('filedrop', array('action' => 'upload', 'fieldname' => '_attachments')); - } - } - - /** - * Generate HTML element for attachments list - */ - function attachments_list($attrib = array()) - { - if (!$attrib['id']) - $attrib['id'] = 'rcmAttachmentList'; - - $skin_path = $this->cal->local_skin_path(); - if ($attrib['deleteicon']) { - $_SESSION[calendar::SESSION_KEY . '_deleteicon'] = $skin_path . $attrib['deleteicon']; - $this->rc->output->set_env('deleteicon', $skin_path . $attrib['deleteicon']); - } - if ($attrib['cancelicon']) - $this->rc->output->set_env('cancelicon', $skin_path . $attrib['cancelicon']); - if ($attrib['loadingicon']) - $this->rc->output->set_env('loadingicon', $skin_path . $attrib['loadingicon']); - - $this->rc->output->add_gui_object('attachmentlist', $attrib['id']); - $this->attachmentlist_id = $attrib['id']; - - return html::tag('ul', $attrib, '', html::$common_attrib); - } - /** * Handler for calendar form template. * The form content could be overriden by the driver diff --git a/plugins/libcalendaring/libcalendaring.php b/plugins/libcalendaring/libcalendaring.php index 4ae37166..b2297e00 100644 --- a/plugins/libcalendaring/libcalendaring.php +++ b/plugins/libcalendaring/libcalendaring.php @@ -250,10 +250,6 @@ class libcalendaring extends rcube_plugin ); $settings['today'] = $this->rc->gettext('today'); - // define list of file types which can be displayed inline - // same as in program/steps/mail/show.inc - $settings['mimetypes'] = (array)$this->rc->config->get('client_mimetypes'); - return $settings; } diff --git a/plugins/libkolab/lib/kolab_attachments_handler.php b/plugins/libkolab/lib/kolab_attachments_handler.php index 821aaaf9..d38739e6 100644 --- a/plugins/libkolab/lib/kolab_attachments_handler.php +++ b/plugins/libkolab/lib/kolab_attachments_handler.php @@ -33,6 +33,61 @@ class kolab_attachments_handler $this->rc = rcmail::get_instance(); } + public static function ui() + { + $rcmail = rcmail::get_instance(); + $self = new self; + + $rcmail->output->add_handler('plugin.attachments_form', array($self, 'files_form')); + $rcmail->output->add_handler('plugin.attachments_list', array($self, 'files_list')); + $rcmail->output->add_handler('plugin.filedroparea', array($self, 'files_drop_area')); + } + + /** + * Generate HTML element for attachments list + */ + public function files_list($attrib = array()) + { + if (!$attrib['id']) { + $attrib['id'] = 'kolabattachmentlist'; + } + + // define list of file types which can be displayed inline + // same as in program/steps/mail/show.inc + $this->rc->output->set_env('mimetypes', (array)$this->rc->config->get('client_mimetypes')); + + $this->rc->output->add_gui_object('attachmentlist', $attrib['id']); + + return html::tag('ul', $attrib, '', html::$common_attrib); + } + + /** + * Generate the form for event attachments upload + */ + public function files_form($attrib = array()) + { + // add ID if not given + if (!$attrib['id']) { + $attrib['id'] = 'kolabuploadform'; + } + + return $this->rc->upload_form($attrib, 'uploadform', 'upload-file', array('multiple' => true)); + } + + /** + * Register UI object for HTML5 drag & drop file upload + */ + public function files_drop_area($attrib = array()) + { + // add ID if not given + if (!$attrib['id']) { + $attrib['id'] = 'kolabfiledroparea'; + } + + $this->rc->output->add_gui_object('filedrop', $attrib['id']); + $this->rc->output->set_env('filedrop', array('action' => 'upload', 'fieldname' => '_attachments')); + } + /** * Displays attachment preview page */ @@ -40,6 +95,8 @@ class kolab_attachments_handler { $this->attachment = $attachment; + $this->rc->plugins->include_script('libkolab/libkolab.js'); + $this->rc->output->add_handler('plugin.attachmentframe', array($this, 'attachment_frame')); $this->rc->output->add_handler('plugin.attachmentcontrols', array($this, 'attachment_header')); $this->rc->output->set_env('filename', $attachment['name']); diff --git a/plugins/libkolab/libkolab.js b/plugins/libkolab/libkolab.js index 56c8dee7..1b669846 100644 --- a/plugins/libkolab/libkolab.js +++ b/plugins/libkolab/libkolab.js @@ -25,7 +25,7 @@ * for the JavaScript code in this file. */ -var libkolab_audittrail = {} +var libkolab_audittrail = {}, libkolab = {}; libkolab_audittrail.quote_html = function(str) { @@ -221,6 +221,73 @@ libkolab_audittrail.dialog_resize = function(id, height, width) $(id).dialog('option', { height: Math.min(h-20, height+130), width: Math.min(w-20, width+50) }); }; +/** + * Open an attachment either in a browser window for inline view or download it + */ +libkolab.load_attachment = function(query, attachment) +{ + query._frame = 1; + + // open attachment in frame if it's of a supported mimetype similar as in app.js + if (attachment.id && attachment.mimetype && $.inArray(attachment.mimetype, rcmail.env.mimetypes) >= 0) { + if (rcmail.open_window(rcmail.url('get-attachment', query), true, true)) { + return; + } + } + + query._frame = null; + query._download = 1; + rcmail.goto_url('get-attachment', query, false); +}; + +/** + * Build attachments list element + */ +libkolab.list_attachments = function(list, container, edit, data, ondelete, onload) +{ + var ul = $('