2012-07-29 17:21:28 +02:00
|
|
|
/**
|
|
|
|
* Client scripts for the Tasklist plugin
|
|
|
|
*
|
|
|
|
* @author Thomas Bruederli <bruederli@kolabsys.com>
|
|
|
|
*
|
2014-04-28 09:12:29 +02:00
|
|
|
* @licstart The following is the entire license notice for the
|
|
|
|
* JavaScript code in this file.
|
|
|
|
*
|
2018-03-22 12:38:43 +00:00
|
|
|
* Copyright (C) 2013-2018, Kolab Systems AG <contact@kolabsys.com>
|
2012-07-29 17:21:28 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-28 09:12:29 +02:00
|
|
|
*
|
|
|
|
* @licend The above is the entire license notice
|
|
|
|
* for the JavaScript code in this file.
|
2012-07-29 17:21:28 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
function rcube_tasklist(settings)
|
|
|
|
{
|
|
|
|
/* public methods */
|
|
|
|
this.create_from_mail = create_from_mail;
|
2014-07-29 15:11:05 +02:00
|
|
|
this.save_to_tasklist = save_to_tasklist;
|
2012-07-29 17:21:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open a new task dialog prefilled with contents from the currently selected mail message
|
|
|
|
*/
|
2013-10-30 16:05:07 +01:00
|
|
|
function create_from_mail(uid)
|
2012-07-29 17:21:28 +02:00
|
|
|
{
|
2018-03-22 12:38:43 +00:00
|
|
|
if (!uid && !(uid = rcmail.get_single_uid())) {
|
|
|
|
return;
|
2012-07-29 17:21:28 +02:00
|
|
|
}
|
2014-10-13 18:40:39 +02:00
|
|
|
|
2018-03-22 12:38:43 +00:00
|
|
|
var url = {_mbox: rcmail.env.mailbox, _uid: uid, _framed: 1},
|
|
|
|
buttons = {},
|
|
|
|
button_classes = ['mainaction save', 'cancel'],
|
|
|
|
title = rcmail.gettext('tasklist.createfrommail'),
|
|
|
|
dialog = $('<iframe>').attr({
|
|
|
|
id: 'kolabtasksinlinegui',
|
|
|
|
name: 'kolabtasksdialog',
|
|
|
|
src: rcmail.url('tasks/dialog-ui', url)
|
|
|
|
});
|
|
|
|
|
|
|
|
// dialog buttons
|
|
|
|
buttons[rcmail.gettext('save')] = function() {
|
|
|
|
var frame = rcmail.get_frame_window('kolabtasksinlinegui');
|
|
|
|
frame.rcmail.command('save-task');
|
|
|
|
};
|
|
|
|
|
|
|
|
buttons[rcmail.gettext('cancel')] = function() {
|
|
|
|
dialog.dialog('destroy');
|
|
|
|
};
|
|
|
|
|
|
|
|
// open jquery UI dialog
|
|
|
|
window.kolab_task_dialog_element = dialog = rcmail.show_popup_dialog(dialog, title, buttons, {
|
|
|
|
button_classes: button_classes,
|
|
|
|
minWidth: 500,
|
|
|
|
width: 600,
|
|
|
|
height: 600
|
|
|
|
});
|
2012-07-29 17:21:28 +02:00
|
|
|
}
|
|
|
|
|
2014-07-29 15:11:05 +02:00
|
|
|
// handler for attachment-save-tasklist commands
|
|
|
|
function save_to_tasklist()
|
|
|
|
{
|
|
|
|
// TODO: show dialog to select the tasklist for importing
|
|
|
|
if (this.selected_attachment && window.rcube_libcalendaring) {
|
|
|
|
rcmail.http_post('tasks/mailimportattach', {
|
|
|
|
_uid: rcmail.env.uid,
|
|
|
|
_mbox: rcmail.env.mailbox,
|
2015-04-27 08:59:16 +02:00
|
|
|
_part: this.selected_attachment
|
2014-07-29 15:11:05 +02:00
|
|
|
// _list: $('#tasklist-attachment-saveto').val(),
|
|
|
|
}, rcmail.set_busy(true, 'itip.savingdata'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-13 18:40:39 +02:00
|
|
|
// register event handlers on linked task items in message view
|
2018-03-22 12:38:43 +00:00
|
|
|
// the checkbox allows to mark a task as complete
|
2014-10-13 18:40:39 +02:00
|
|
|
if (rcmail.env.action == 'show' || rcmail.env.action == 'preview') {
|
|
|
|
$('div.messagetasklinks input.complete').click(function(e) {
|
|
|
|
var $this = $(this);
|
|
|
|
$(this).closest('.messagetaskref').toggleClass('complete');
|
|
|
|
|
|
|
|
// submit change to server
|
|
|
|
rcmail.http_post('tasks/task', {
|
|
|
|
action: 'complete',
|
|
|
|
t: { id:this.value, list:$this.attr('data-list') },
|
|
|
|
complete: this.checked?1:0
|
|
|
|
}, rcmail.set_busy(true, 'tasklist.savingdata'));
|
|
|
|
});
|
|
|
|
}
|
2012-07-29 17:21:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* tasklist plugin initialization (for email task) */
|
|
|
|
window.rcmail && rcmail.env.task == 'mail' && rcmail.addEventListener('init', function(evt) {
|
2012-08-16 08:57:25 +02:00
|
|
|
var tasks = new rcube_tasklist(rcmail.env.libcal_settings);
|
2012-07-29 17:21:28 +02:00
|
|
|
|
2014-07-29 15:11:05 +02:00
|
|
|
rcmail.register_command('tasklist-create-from-mail', function() { tasks.create_from_mail(); });
|
|
|
|
rcmail.register_command('attachment-save-task', function() { tasks.save_to_tasklist(); });
|
2012-07-29 17:21:28 +02:00
|
|
|
|
|
|
|
if (rcmail.env.action != 'show')
|
|
|
|
rcmail.env.message_commands.push('tasklist-create-from-mail');
|
|
|
|
else
|
|
|
|
rcmail.enable_command('tasklist-create-from-mail', true);
|
2013-10-30 16:05:07 +01:00
|
|
|
|
2014-07-29 15:11:05 +02:00
|
|
|
rcmail.addEventListener('beforemenu-open', function(p) {
|
|
|
|
if (p.menu == 'attachmentmenu') {
|
|
|
|
tasks.selected_attachment = p.id;
|
|
|
|
var mimetype = rcmail.env.attachments[p.id],
|
|
|
|
is_ics = mimetype == 'text/calendar' || mimetype == 'text/x-vcalendar' || mimetype == 'application/ics';
|
|
|
|
|
|
|
|
rcmail.enable_command('attachment-save-task', is_ics);
|
|
|
|
}
|
|
|
|
});
|
2012-07-29 17:21:28 +02:00
|
|
|
});
|