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 = $('
').addClass('attachmentslist');
+
+ $.each(list || [], function(i, elem) {
+ var li = $('- ').addClass(elem.classname);
+
+ // name/link
+ $('').attr({href: '#load', 'class': 'filename'})
+ .append($('').text(elem.name))
+ .click({record: data, attachment: elem}, function(e) {
+ if (onload) {
+ onload(e.data);
+ }
+ return false;
+ })
+ .appendTo(li);
+
+ if (edit) {
+ rcmail.env.attachments[elem.id] = elem;
+ // delete link
+ $('').attr({href: '#delete', title: rcmail.gettext('delete'), 'class': 'delete'})
+ .click({id: elem.id}, function(e) {
+ $(this.parentNode).hide();
+ delete rcmail.env.attachments[e.data.id];
+ if (ondelete) {
+ ondelete(e.data.id);
+ }
+ return false;
+ })
+ .appendTo(li);
+ }
+
+ ul.append(li);
+ });
+
+ if (edit && rcmail.gui_objects.attachmentlist) {
+ ul.id = rcmail.gui_objects.attachmentlist.id;
+ rcmail.gui_objects.attachmentlist = ul.get(0);
+ }
+
+ container.empty().append(ul);
+};
+
+
function kolab_folderlist(node, p)
{
// extends treelist.js
@@ -533,26 +600,28 @@ function kolab_folderlist(node, p)
});
this.container.on('click', 'a.remove', function(e) {
- var li = $(this).closest('li'),
- id = li.attr('id').replace(new RegExp('^'+p.id_prefix), '');
+ var li = $(this).closest('li'),
+ id = li.attr('id').replace(new RegExp('^'+p.id_prefix), '');
- if (me.is_search()) {
- id = id.replace(/--xsR$/, '');
- li = $(me.get_item(id, true));
- }
+ if (me.is_search()) {
+ id = id.replace(/--xsR$/, '');
+ li = $(me.get_item(id, true));
+ }
- if (p.id_decode)
- id = p.id_decode(id);
+ if (p.id_decode)
+ id = p.id_decode(id);
- me.triggerEvent('remove', { id: id, item: li });
+ me.triggerEvent('remove', { id: id, item: li });
- e.stopPropagation();
- return false;
+ e.stopPropagation();
+ return false;
});
}
// link prototype from base class
-kolab_folderlist.prototype = rcube_treelist_widget.prototype;
+if (window.rcube_treelist_widget) {
+ kolab_folderlist.prototype = rcube_treelist_widget.prototype;
+}
window.rcmail && rcmail.addEventListener('init', function(e) {
@@ -599,7 +668,7 @@ window.rcmail && rcmail.addEventListener('init', function(e) {
}
if (rcmail.env.action == 'get-attachment') {
- if (rcmail.rcmail.gui_objects.attachmentframe) {
+ if (rcmail.gui_objects.attachmentframe) {
rcmail.gui_objects.messagepartframe = rcmail.gui_objects.attachmentframe;
rcmail.enable_command('image-scale', 'image-rotate', !!/^image\//.test(rcmail.env.mimetype));
rcmail.register_command('print-attachment', function() {
diff --git a/plugins/tasklist/tasklist.js b/plugins/tasklist/tasklist.js
index 9060817f..cd2a917a 100644
--- a/plugins/tasklist/tasklist.js
+++ b/plugins/tasklist/tasklist.js
@@ -2611,89 +2611,39 @@ function rcube_tasklist_ui(settings)
/**
* Open a task attachment either in a browser window for inline view or download it
*/
- function load_attachment(rec, att)
+ function load_attachment(data)
{
+ var rec = data.record;
+
// can't open temp attachments
if (!rec.id || rec.id < 0)
return false;
- var query = { _id: att.id, _t: rec.recurrence_id||rec.id, _list:rec.list, _frame: 1 };
+ var query = {_id: data.attachment.id, _t: rec.recurrence_id || rec.id, _list: rec.list};
if (rec.rev)
query._rev = rec.rev;
- // open attachment in frame if it's of a supported mimetype
- // similar as in app.js and calendar_ui.js
- if (att.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 task attachments list
*/
- function task_show_attachments(list, container, rec, edit)
+ function task_show_attachments(list, container, task, edit)
{
- var i, id, len, content, li, elem,
- ul = $('
').addClass('attachmentslist');
-
- for (i=0, len=list.length; i').addClass(elem.classname);
-
- if (edit) {
- rcmail.env.attachments[elem.id] = elem;
- // delete icon
- content = $('').attr({href: '#delete', title: rcmail.gettext('delete'), 'class': '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 {
- $('
').attr('src', rcmail.env.deleteicon).attr('alt', rcmail.gettext('delete')).appendTo(content);
- }
-
- li.append(content);
- }
-
- // name/link
- $('').attr({href: '#load', 'class': 'filename'})
- .append($('').text(elem.name))
- .click({ task:rec, att:elem }, function(e) {
- load_attachment(e.data.task, e.data.att);
- return false;
- })
- .appendTo(li);
-
- ul.append(li);
- }
-
- if (edit && rcmail.gui_objects.attachmentlist) {
- ul.id = rcmail.gui_objects.attachmentlist.id;
- rcmail.gui_objects.attachmentlist = ul.get(0);
- }
-
- container.empty().append(ul);
+ libkolab.list_attachments(list, container, edit, task,
+ function(id) { remove_attachment(id); },
+ function(data) { load_attachment(data); }
+ );
};
/**
*
*/
- function remove_attachment(elem, id)
+ function remove_attachment(id)
{
- $(elem.parentNode).hide();
me.selected_task.deleted_attachments.push(id);
- delete rcmail.env.attachments[id];
}
/**
diff --git a/plugins/tasklist/tasklist_ui.php b/plugins/tasklist/tasklist_ui.php
index a8bfb170..0d762b24 100644
--- a/plugins/tasklist/tasklist_ui.php
+++ b/plugins/tasklist/tasklist_ui.php
@@ -146,9 +146,6 @@ class tasklist_ui
$this->plugin->register_handler('plugin.tags_editline', array($this, 'tags_editline'));
$this->plugin->register_handler('plugin.alarm_select', array($this, 'alarm_select'));
$this->plugin->register_handler('plugin.recurrence_form', array($this->plugin->lib, 'recurrence_form'));
- $this->plugin->register_handler('plugin.attachments_form', array($this, 'attachments_form'));
- $this->plugin->register_handler('plugin.attachments_list', array($this, 'attachments_list'));
- $this->plugin->register_handler('plugin.filedroparea', array($this, 'file_drop_area'));
$this->plugin->register_handler('plugin.attendees_list', array($this, 'attendees_list'));
$this->plugin->register_handler('plugin.attendees_form', array($this, 'attendees_form'));
$this->plugin->register_handler('plugin.identity_select', array($this, 'identity_select'));
@@ -158,6 +155,8 @@ class tasklist_ui
$this->plugin->register_handler('plugin.tasks_export_form', array($this, 'tasks_export_form'));
$this->plugin->register_handler('plugin.tasks_import_form', array($this, 'tasks_import_form'));
+ kolab_attachments_handler::ui();
+
$this->plugin->include_script('tasklist.js');
$this->rc->output->include_script('treelist.js');
$this->plugin->api->include_script('libkolab/libkolab.js');
@@ -412,44 +411,6 @@ class tasklist_ui
return html::div($attrib, $input->show(''));
}
- /**
- * Generate HTML element for attachments list
- */
- function attachments_list($attrib = array())
- {
- if (!$attrib['id']) {
- $attrib['id'] = 'rcmtaskattachmentlist';
- }
-
- $this->register_gui_object('attachmentlist', $attrib['id']);
-
- return html::tag('ul', $attrib, '', html::$common_attrib);
- }
-
- /**
- * Generate the form for event attachments upload
- */
- function attachments_form($attrib = array())
- {
- // add ID if not given
- if (!$attrib['id']) {
- $attrib['id'] = 'rcmtaskuploadform';
- }
-
- 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->register_gui_object('filedrop', $attrib['id']);
- $this->rc->output->set_env('filedrop', array('action' => 'upload', 'fieldname' => '_attachments'));
- }
- }
-
/**
*
*/