You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vcardattach.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * vcard_attachments plugin script
  3. *
  4. * @licstart The following is the entire license notice for the
  5. * JavaScript code in this file.
  6. *
  7. * Copyright (c) 2012-2016, The Roundcube Dev Team
  8. *
  9. * The JavaScript code in this page is free software: you can redistribute it
  10. * and/or modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation, either version 3 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * @licend The above is the entire license notice
  15. * for the JavaScript code in this file.
  16. */
  17. function plugin_vcard_save_contact(mime_id)
  18. {
  19. var lock = rcmail.set_busy(true, 'loading');
  20. rcmail.http_post('plugin.savevcard', { _uid: rcmail.env.uid, _mbox: rcmail.env.mailbox, _part: mime_id }, lock);
  21. return false;
  22. }
  23. function plugin_vcard_insertrow(data)
  24. {
  25. var ctype = data.row.ctype;
  26. if (ctype == 'text/vcard' || ctype == 'text/x-vcard' || ctype == 'text/directory') {
  27. $('#rcmrow' + rcmail.html_identifier(data.uid, true) + ' > td.attachment')
  28. .html('<img src="' + rcmail.env.vcard_icon + '" alt="" />');
  29. }
  30. }
  31. function plugin_vcard_attach()
  32. {
  33. var id, n, contacts = [],
  34. ts = new Date().getTime(),
  35. args = {_uploadid: ts, _id: rcmail.env.compose_id};
  36. for (n=0; n < rcmail.contact_list.selection.length; n++) {
  37. id = rcmail.contact_list.selection[n];
  38. if (id && id.charAt(0) != 'E' && rcmail.env.contactdata[id])
  39. contacts.push(id);
  40. }
  41. if (!contacts.length)
  42. return false;
  43. args._uri = 'vcard://' + contacts.join(',');
  44. // add to attachments list
  45. if (!rcmail.add2attachment_list(ts, {name: '', html: rcmail.get_label('attaching'), classname: 'uploading', complete: false}))
  46. rcmail.file_upload_id = rcmail.set_busy(true, 'attaching');
  47. rcmail.http_post('upload', args);
  48. }
  49. window.rcmail && rcmail.addEventListener('init', function(evt) {
  50. if (rcmail.gui_objects.messagelist)
  51. rcmail.addEventListener('insertrow', function(data, evt) { plugin_vcard_insertrow(data); });
  52. if (rcmail.env.action == 'compose' && rcmail.gui_objects.contactslist) {
  53. rcmail.env.compose_commands.push('attach-vcard');
  54. rcmail.register_command('attach-vcard', function() { plugin_vcard_attach(); });
  55. rcmail.contact_list.addEventListener('select', function(list) {
  56. // TODO: support attaching more than one at once
  57. rcmail.enable_command('attach-vcard', list.selection.length == 1 && rcmail.contact_list.selection[0].charAt(0) != 'E');
  58. });
  59. }
  60. });