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