- 1 :
/**
- 2 :
* Client scripts for the Tasklist plugin
- 3 :
*
- 4 :
* @author Thomas Bruederli <bruederli@kolabsys.com>
- 5 :
*
- 6 :
* @licstart The following is the entire license notice for the
- 7 :
* JavaScript code in this file.
- 8 :
*
- 9 :
* Copyright (C) 2013-2018, Kolab Systems AG <contact@kolabsys.com>
- 10 :
*
- 11 :
* This program is free software: you can redistribute it and/or modify
- 12 :
* it under the terms of the GNU Affero General Public License as
- 13 :
* published by the Free Software Foundation, either version 3 of the
- 14 :
* License, or (at your option) any later version.
- 15 :
*
- 16 :
* This program is distributed in the hope that it will be useful,
- 17 :
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- 18 :
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- 19 :
* GNU Affero General Public License for more details.
- 20 :
*
- 21 :
* You should have received a copy of the GNU Affero General Public License
- 22 :
* along with this program. If not, see <http://www.gnu.org/licenses/>.
- 23 :
*
- 24 :
* @licend The above is the entire license notice
- 25 :
* for the JavaScript code in this file.
- 26 :
*/
- 27 :
- 28 :
function rcube_tasklist(settings)
- 29 :
{
- 30 :
/* public methods */
- 31 :
this.create_from_mail = create_from_mail;
- 32 :
this.save_to_tasklist = save_to_tasklist;
- 33 :
- 34 :
- 35 :
/**
- 36 :
* Open a new task dialog prefilled with contents from the currently selected mail message
- 37 :
*/
- 38 :
function create_from_mail(uid)
- 39 :
{
- 40 :
if (!uid && !(uid = rcmail.get_single_uid())) {
- 41 :
return;
- 42 :
}
- 43 :
- 44 :
var url = {_mbox: rcmail.env.mailbox, _uid: uid, _framed: 1},
- 45 :
buttons = {},
- 46 :
button_classes = ['mainaction save', 'cancel'],
- 47 :
title = rcmail.gettext('tasklist.createfrommail'),
- 48 :
dialog = $('<iframe>').attr({
- 49 :
id: 'kolabtasksinlinegui',
- 50 :
name: 'kolabtasksdialog',
- 51 :
src: rcmail.url('tasks/dialog-ui', url)
- 52 :
});
- 53 :
- 54 :
// dialog buttons
- 55 :
buttons[rcmail.gettext('save')] = function() {
- 56 :
var frame = rcmail.get_frame_window('kolabtasksinlinegui');
- 57 :
frame.rcmail.command('save-task');
- 58 :
};
- 59 :
- 60 :
buttons[rcmail.gettext('cancel')] = function() {
- 61 :
dialog.dialog('destroy');
- 62 :
};
- 63 :
- 64 :
// open jquery UI dialog
- 65 :
window.kolab_task_dialog_element = dialog = rcmail.show_popup_dialog(dialog, title, buttons, {
- 66 :
button_classes: button_classes,
- 67 :
minWidth: 500,
- 68 :
width: 600,
- 69 :
height: 600
- 70 :
});
- 71 :
}
- 72 :
- 73 :
// handler for attachment-save-tasklist commands
- 74 :
function save_to_tasklist()
- 75 :
{
- 76 :
// TODO: show dialog to select the tasklist for importing
- 77 :
if (this.selected_attachment && window.rcube_libcalendaring) {
- 78 :
rcmail.http_post('tasks/mailimportattach', {
- 79 :
_uid: rcmail.env.uid,
- 80 :
_mbox: rcmail.env.mailbox,
- 81 :
_part: this.selected_attachment
- 82 :
// _list: $('#tasklist-attachment-saveto').val(),
- 83 :
}, rcmail.set_busy(true, 'itip.savingdata'));
- 84 :
}
- 85 :
}
- 86 :
- 87 :
// register event handlers on linked task items in message view
- 88 :
// the checkbox allows to mark a task as complete
- 89 :
if (rcmail.env.action == 'show' || rcmail.env.action == 'preview') {
- 90 :
$('div.messagetasklinks input.complete').click(function(e) {
- 91 :
var $this = $(this);
- 92 :
$(this).closest('.messagetaskref').toggleClass('complete');
- 93 :
- 94 :
// submit change to server
- 95 :
rcmail.http_post('tasks/task', {
- 96 :
action: 'complete',
- 97 :
t: { id:this.value, list:$this.attr('data-list') },
- 98 :
complete: this.checked?1:0
- 99 :
}, rcmail.set_busy(true, 'tasklist.savingdata'));
- 100 :
});
- 101 :
}
- 102 :
}
- 103 :
- 104 :
/* tasklist plugin initialization (for email task) */
- 105 :
window.rcmail && rcmail.env.task == 'mail' && rcmail.addEventListener('init', function(evt) {
- 106 :
var tasks = new rcube_tasklist(rcmail.env.libcal_settings);
- 107 :
- 108 :
rcmail.register_command('tasklist-create-from-mail', function() { tasks.create_from_mail(); });
- 109 :
rcmail.register_command('attachment-save-task', function() { tasks.save_to_tasklist(); });
- 110 :
- 111 :
if (rcmail.env.action != 'show')
- 112 :
rcmail.env.message_commands.push('tasklist-create-from-mail');
- 113 :
else
- 114 :
rcmail.enable_command('tasklist-create-from-mail', true);
- 115 :
- 116 :
rcmail.addEventListener('beforemenu-open', function(p) {
- 117 :
if (p.menu == 'attachmentmenu') {
- 118 :
tasks.selected_attachment = p.id;
- 119 :
var mimetype = rcmail.env.attachments[p.id],
- 120 :
is_ics = mimetype == 'text/calendar' || mimetype == 'text/x-vcalendar' || mimetype == 'application/ics';
- 121 :
- 122 :
rcmail.enable_command('attachment-save-task', is_ics);
- 123 :
}
- 124 :
});
- 125 :
});