vcardattach.min.js 3.0 KB
/**
 * vcard_attachments plugin script
 *
 * @licstart  The following is the entire license notice for the
 * JavaScript code in this file.
 *
 * Copyright (c) The Roundcube Dev Team
 *
 * The JavaScript code in this page is free software: you can redistribute it
 * and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 *
 * @licend  The above is the entire license notice
 * for the JavaScript code in this file.
 */
function plugin_vcard_import(t){if(t)return rcmail.http_post("plugin.savevcard",{_uid:rcmail.env.uid,_mbox:rcmail.env.mailbox,_part:t},rcmail.set_busy(!0,"loading")),!1;var c=[];$.each(rcmail.env.vcards,function(t,a){t=$("<input>").attr({type:"checkbox",value:t,checked:!0,class:"pretty-checkbox"}),a=$("<label>").text(" "+a);c.push($("<div>").append(a.prepend(t)))});var t={button:"import",height:4<c.length?250:100},e=rcmail.simple_dialog(c,"vcard_attachments.addvcardmsg",function(t,a){var c=[];if(e.find("input:checked").each(function(){c.push(this.value)}),c.length)return plugin_vcard_import(c.join()),!0},t);return!1}function plugin_vcard_insertrow(t){t.row.ctype.match(/^(text\/vcard|text\/x-vcard|text\/directory)$/i)&&$(t.row.obj).find(".attachment > .attachment").addClass("vcard")}function plugin_vcard_attach(){for(var t,a=[],c=(new Date).getTime(),e={_uploadid:c,_id:rcmail.env.compose_id||null},i=rcmail.contact_list.get_selection(),n=0;n<i.length;n++)"addressbook"==rcmail.env.task?(t=i[n],a.push(rcmail.env.source+"-"+t+"-0")):(t=i[n])&&"E"!=t.charAt(0)&&rcmail.env.contactdata[t]&&a.push(t);if(!a.length)return!1;e._uri="vcard://"+a.join(","),"addressbook"==rcmail.env.task?(e._attach_vcard=1,rcmail.open_compose_step(e)):(rcmail.add2attachment_list(c,{name:"",html:rcmail.get_label("attaching"),classname:"uploading",complete:!1})||(rcmail.file_upload_id=rcmail.set_busy(!0,"attaching")),rcmail.http_post("upload",e))}window.rcmail&&rcmail.addEventListener("init",function(t){var a,c;rcmail.gui_objects.messagelist&&rcmail.addEventListener("insertrow",function(t,a){plugin_vcard_insertrow(t)}),("compose"==rcmail.env.action||"addressbook"==rcmail.env.task&&""==rcmail.env.action)&&rcmail.gui_objects.contactslist&&("compose"==rcmail.env.action&&(rcmail.env.compose_commands.push("attach-vcard"),window.UI&&UI.recipient_selector&&(a=$("#compose-attachments > div"),c=$('<button class="btn btn-secondary attach vcard">').attr({type:"button",tabindex:$("button,input",a).first().attr("tabindex")||0}).text(rcmail.gettext("vcard_attachments.attachvcard")).appendTo(a).click(function(){UI.recipient_selector("",{title:"vcard_attachments.attachvcard",button:"vcard_attachments.attachvcard",button_class:"attach",focus:c,multiselect:!1,action:function(){rcmail.command("attach-vcard")}})}))),rcmail.register_command("attach-vcard",function(){plugin_vcard_attach()}),rcmail.contact_list.addEventListener("select",function(t){t=t.get_selection();rcmail.enable_command("attach-vcard",1==t.length&&"E"!=t[0].charAt(0))}))});