diff --git a/plugins/yetiforce/compose.js b/plugins/yetiforce/compose.js index cff2a869..3b8f25b4 100644 --- a/plugins/yetiforce/compose.js +++ b/plugins/yetiforce/compose.js @@ -63,10 +63,11 @@ window.rcmail && rcmail.addEventListener('init', function (evt) { }; show(params, function (data) { var responseData = JSON.parse(data); - var length = Object.keys(responseData).length; + var ids = []; for (var id in responseData) { - getMailFromCRM(mailField, module, id, length); + ids.push(id); } + getMailFromCRM(mailField, module, ids); }); }); //Loading list of modules with templates mail @@ -158,25 +159,31 @@ function getCrmWindow() { return false; } -function getMailFromCRM(mailField, module, record, length) { - if (length > 1) { - length = 1; - } else { - length = 0; - } - window.crm.Vtiger_Index_Js.getEmailFromRecord(record, module, length).then(function (data) { - if (data == '') { - var notifyParams = { - text: window.crm.app.vtranslate('NoFindEmailInRecord'), - animation: 'show' - }; - window.crm.Vtiger_Helper_Js.showPnotify(notifyParams); - } else { - var emails = $('#' + mailField).val(); - if (emails != '' && emails.charAt(emails.length - 1) != ',') { - emails = emails + ','; +function getMailFromCRM(mailField, moduleName, records) { + jQuery.ajax({ + type: "POST", + url: "?_task=mail&_action=plugin.yetiforce.getEmailFromCRM&_id=" + rcmail.env.compose_id, + async: false, + data: { + recordsId: records, + moduleName: moduleName, + }, + success: function (data) { + data = JSON.parse(data); + if (data.length == 0 ) { + var notifyParams = { + text: window.crm.app.vtranslate('NoFindEmailInRecord'), + animation: 'show' + }; + window.crm.Vtiger_Helper_Js.showPnotify(notifyParams); + } else { + console.log(data); + var emails = $('#' + mailField).val(); + if (emails != '' && emails.charAt(emails.length - 1) != ',') { + emails = emails + ','; + } + $('#' + mailField).val(emails + data); } - $('#' + mailField).val(emails + data); } }); } diff --git a/plugins/yetiforce/compose.min.js b/plugins/yetiforce/compose.min.js index cba20059..e547fdc6 100644 --- a/plugins/yetiforce/compose.min.js +++ b/plugins/yetiforce/compose.min.js @@ -1,2 +1,2 @@ -window.rcmail&&rcmail.addEventListener("init",function(a){var c=window.crm=getCrmWindow();var b=rcmail.env.site_URL+"index.php?";rcmail.env.compose_commands.push("yetiforce.addFilesToMail");rcmail.env.compose_commands.push("yetiforce.addFilesFromCRM");rcmail.register_command("yetiforce.addFilesToMail",function(f){var e=new Date().getTime(),d="rcmupload"+e,g=rcmail.async_upload_form_frame(d);f._uploadid=e;jQuery.ajax({url:"?_task=mail&_action=plugin.yetiforce.addFilesToMail&_id="+rcmail.env.compose_id,type:"POST",data:f,success:function(i){var j=g[0].contentWindow.document;var h=$("html",j);h.html(i)}})},true);rcmail.register_command("yetiforce.addFilesFromCRM",function(e){if(c!=false){var g={module:"Documents",src_module:"Documents",multi_select:true,url:b};var f=$(this);var d=jQuery.Event(c.Vtiger_Edit_Js.preReferencePopUpOpenEvent);f.trigger(d);var e={};show(g,function(j){var i=JSON.parse(j);var h=[];for(var k in i){h.push(k)}rcmail.command("yetiforce.addFilesToMail",{ids:h,_uploadid:new Date().getTime()})})}},true);$("#composeheaders #yt_adress_buttons .button").click(function(){var e=$(this).attr("data-input");var d=$(this).attr("data-module");var f={module:d,src_module:"OSSMail",multi_select:true,url:b};show(f,function(i){var g=JSON.parse(i);var h=Object.keys(g).length;for(var j in g){getMailFromCRM(e,d,j,h)}})});if(rcmail.env.isPermittedMailTemplates){jQuery.ajax({type:"Get",url:"?_task=mail&_action=plugin.yetiforce.getEmailTemplates&_id="+rcmail.env.compose_id,async:false,success:function(f){var d=[];var e=[];f=JSON.parse(f);$.each(f,function(g,h){jQuery("#vtmodulemenulink").removeClass("disabled");jQuery("#tplmenulink").removeClass("disabled");e.push({name:h.moduleName,label:h.moduleName});jQuery("#tplmenu #texttplsmenu").append('
  • '+h.name+"
  • ")});$.each(e,function(g,h){if(jQuery.inArray(h.name,d)==-1){jQuery("#vtmodulemenu .toolbarmenu").append('
  • '+h.label+"
  • ");d.push(h.name)}})}})}jQuery("#vtmodulemenu li a").on("click",function(){var d=jQuery(this).data("module");if(d==undefined){jQuery("#tplmenu li").show()}else{jQuery("#tplmenu li."+d).show();jQuery("#tplmenu li").not("."+d).hide()}});if(rcmail.env.crmModule!=undefined){jQuery("#vtmodulemenu li."+rcmail.env.crmModule+" a").trigger("click")}jQuery("#tplmenu li a").on("click",function(){var h=jQuery(this).data("tplid");var f=rcmail.env.crmRecord,e=rcmail.env.crmModule,d=rcmail.env.crmView;if(d=="List"){var g=jQuery(c.document).find(".listViewEntriesCheckBox")[0];f=jQuery(g).val()}jQuery.ajax({type:"Get",url:"?_task=mail&_action=plugin.yetiforce.getConntentEmailTemplate&_id="+rcmail.env.compose_id,data:{id:h,record_id:f,select_module:e},success:function(l){l=JSON.parse(l);var j=jQuery('[name="_subject"]').val();var k=jQuery("
    ").html(l.content).html();jQuery('[name="_subject"]').val(j+" "+l.subject);if(window.tinyMCE&&(ed=tinyMCE.get(rcmail.env.composebody))){var i=tinyMCE.activeEditor.getContent();tinymce.activeEditor.setContent(k+i)}else{var i=jQuery("#composebody").val();jQuery("#composebody").val(k+i)}if(typeof l.attachments!=="undefined"){rcmail.command("yetiforce.addFilesToMail",l.attachments)}}})})});function getCrmWindow(){if(opener!==null){return opener.parent}else{if(typeof parent.app=="object"){return parent}}return false}function getMailFromCRM(c,b,a,d){if(d>1){d=1}else{d=0}window.crm.Vtiger_Index_Js.getEmailFromRecord(a,b,d).then(function(f){if(f==""){var e={text:window.crm.app.vtranslate("NoFindEmailInRecord"),animation:"show"};window.crm.Vtiger_Helper_Js.showPnotify(e)}else{var g=$("#"+c).val();if(g!=""&&g.charAt(g.length-1)!=","){g=g+","}$("#"+c).val(g+f)}})}function show(c,d,i,f,b){var h=window.crm.Vtiger_Popup_Js.getInstance();if(typeof c=="undefined"){c={}}if(typeof c=="object"&&(typeof c.view=="undefined")){c.view="Popup"}if(typeof f=="undefined"){f="postSelection"+Math.floor(Math.random()*10000)}if(typeof i=="undefined"){i="test"}if(typeof c=="object"){c.triggerEventName=f}else{c+="&triggerEventName="+f}var e=(typeof c=="string")?c:window.crm.jQuery.param(c);var a=c.url+e;var g=window.crm.window.open(a,i,"width=800,height=650,resizable=0,scrollbars=1");if(typeof h.destroy=="function"){h.destroy()}window.crm.jQuery.initWindowMsg();if(typeof d!="undefined"){h.retrieveSelectedRecords(d,f)}if(typeof b=="function"){window.crm.jQuery.windowMsg("Vtiger.OnPopupWindowLoad.Event",function(j){b(j)})}return g}; \ No newline at end of file +window.rcmail&&rcmail.addEventListener("init",function(a){var c=window.crm=getCrmWindow();var b=rcmail.env.site_URL+"index.php?";rcmail.env.compose_commands.push("yetiforce.addFilesToMail");rcmail.env.compose_commands.push("yetiforce.addFilesFromCRM");rcmail.register_command("yetiforce.addFilesToMail",function(f){var e=new Date().getTime(),d="rcmupload"+e,g=rcmail.async_upload_form_frame(d);f._uploadid=e;jQuery.ajax({url:"?_task=mail&_action=plugin.yetiforce.addFilesToMail&_id="+rcmail.env.compose_id,type:"POST",data:f,success:function(i){var j=g[0].contentWindow.document;var h=$("html",j);h.html(i)}})},true);rcmail.register_command("yetiforce.addFilesFromCRM",function(e){if(c!=false){var g={module:"Documents",src_module:"Documents",multi_select:true,url:b};var f=$(this);var d=jQuery.Event(c.Vtiger_Edit_Js.preReferencePopUpOpenEvent);f.trigger(d);var e={};show(g,function(j){var i=JSON.parse(j);var h=[];for(var k in i){h.push(k)}rcmail.command("yetiforce.addFilesToMail",{ids:h,_uploadid:new Date().getTime()})})}},true);$("#composeheaders #yt_adress_buttons .button").click(function(){var e=$(this).attr("data-input");var d=$(this).attr("data-module");var f={module:d,src_module:"OSSMail",multi_select:true,url:b};show(f,function(i){var h=JSON.parse(i);var g=[];for(var j in h){g.push(j)}getMailFromCRM(e,d,g)})});if(rcmail.env.isPermittedMailTemplates){jQuery.ajax({type:"Get",url:"?_task=mail&_action=plugin.yetiforce.getEmailTemplates&_id="+rcmail.env.compose_id,async:false,success:function(f){var d=[];var e=[];f=JSON.parse(f);$.each(f,function(g,h){jQuery("#vtmodulemenulink").removeClass("disabled");jQuery("#tplmenulink").removeClass("disabled");e.push({name:h.moduleName,label:h.moduleName});jQuery("#tplmenu #texttplsmenu").append('
  • '+h.name+"
  • ")});$.each(e,function(g,h){if(jQuery.inArray(h.name,d)==-1){jQuery("#vtmodulemenu .toolbarmenu").append('
  • '+h.label+"
  • ");d.push(h.name)}})}})}jQuery("#vtmodulemenu li a").on("click",function(){var d=jQuery(this).data("module");if(d==undefined){jQuery("#tplmenu li").show()}else{jQuery("#tplmenu li."+d).show();jQuery("#tplmenu li").not("."+d).hide()}});if(rcmail.env.crmModule!=undefined){jQuery("#vtmodulemenu li."+rcmail.env.crmModule+" a").trigger("click")}jQuery("#tplmenu li a").on("click",function(){var h=jQuery(this).data("tplid");var f=rcmail.env.crmRecord,e=rcmail.env.crmModule,d=rcmail.env.crmView;if(d=="List"){var g=jQuery(c.document).find(".listViewEntriesCheckBox")[0];f=jQuery(g).val()}jQuery.ajax({type:"Get",url:"?_task=mail&_action=plugin.yetiforce.getConntentEmailTemplate&_id="+rcmail.env.compose_id,data:{id:h,record_id:f,select_module:e},success:function(l){l=JSON.parse(l);var j=jQuery('[name="_subject"]').val();var k=jQuery("
    ").html(l.content).html();jQuery('[name="_subject"]').val(j+" "+l.subject);if(window.tinyMCE&&(ed=tinyMCE.get(rcmail.env.composebody))){var i=tinyMCE.activeEditor.getContent();tinymce.activeEditor.setContent(k+i)}else{var i=jQuery("#composebody").val();jQuery("#composebody").val(k+i)}if(typeof l.attachments!=="undefined"){rcmail.command("yetiforce.addFilesToMail",l.attachments)}}})})});function getCrmWindow(){if(opener!==null){return opener.parent}else{if(typeof parent.app=="object"){return parent}}return false}function getMailFromCRM(c,b,a){jQuery.ajax({type:"POST",url:"?_task=mail&_action=plugin.yetiforce.getEmailFromCRM&_id="+rcmail.env.compose_id,async:false,data:{recordsId:a,moduleName:b,},success:function(e){e=JSON.parse(e);if(e.length==0){var d={text:window.crm.app.vtranslate("NoFindEmailInRecord"),animation:"show"};window.crm.Vtiger_Helper_Js.showPnotify(d)}else{console.log(e);var f=$("#"+c).val();if(f!=""&&f.charAt(f.length-1)!=","){f=f+","}$("#"+c).val(f+e)}}})}function show(c,d,i,f,b){var h=window.crm.Vtiger_Popup_Js.getInstance();if(typeof c=="undefined"){c={}}if(typeof c=="object"&&(typeof c.view=="undefined")){c.view="Popup"}if(typeof f=="undefined"){f="postSelection"+Math.floor(Math.random()*10000)}if(typeof i=="undefined"){i="test"}if(typeof c=="object"){c.triggerEventName=f}else{c+="&triggerEventName="+f}var e=(typeof c=="string")?c:window.crm.jQuery.param(c);var a=c.url+e;var g=window.crm.window.open(a,i,"width=800,height=650,resizable=0,scrollbars=1");if(typeof h.destroy=="function"){h.destroy()}window.crm.jQuery.initWindowMsg();if(typeof d!="undefined"){h.retrieveSelectedRecords(d,f)}if(typeof b=="function"){window.crm.jQuery.windowMsg("Vtiger.OnPopupWindowLoad.Event",function(j){b(j)})}return g}; \ No newline at end of file diff --git a/plugins/yetiforce/yetiforce.php b/plugins/yetiforce/yetiforce.php index c8a5a8ff..092d78b1 100644 --- a/plugins/yetiforce/yetiforce.php +++ b/plugins/yetiforce/yetiforce.php @@ -24,6 +24,7 @@ public function init() if ($this->rc->task == 'mail') { $this->register_action('plugin.yetiforce.addFilesToMail', [$this, 'addFilesToMail']); $this->register_action('plugin.yetiforce.getEmailTemplates', [$this, 'getEmailTemplates']); + $this->register_action('plugin.yetiforce.getEmailFromCRM', [$this, 'getEmailFromCRM']); $this->register_action('plugin.yetiforce.getConntentEmailTemplate', [$this, 'getConntentEmailTemplate']); $this->rc->output->set_env('site_URL', $this->rc->config->get('site_URL')); $this->include_stylesheet($this->rc->config->get('site_URL') . 'layouts/basic/skins/icons/userIcons.css'); @@ -615,6 +616,32 @@ public function ytAdressButton($p) return $p; } + /** + * Get address email from CRM + */ + public function getEmailFromCRM() + { + $currentPath = getcwd(); + chdir($this->rc->config->get('root_directory')); + $this->loadCurrentUser(); + $ids = rcube_utils::get_input_value('recordsId', rcube_utils::INPUT_GPC); + $sourceModule = rcube_utils::get_input_value('moduleName', rcube_utils::INPUT_GPC); + $emailFields = OSSMailScanner_Record_Model::getEmailSearch($sourceModule); + $addresEmails = []; + foreach ($ids as $id) { + $recordModel = Vtiger_Record_Model::getInstanceById($id, $sourceModule); + foreach ($emailFields as &$emailField) { + $email = $recordModel->get($emailField['fieldname']); + if (!empty($email)) { + $addresEmails[] = $email; + } + } + } + echo App\Json::encode($addresEmails); + chdir($currentPath); + exit; + } + /** * Function to get templates */ diff --git a/version.php b/version.php index ffe917be..194fd408 100644 --- a/version.php +++ b/version.php @@ -1,5 +1,5 @@ '2017.01.19', - 'version' => '0.0.22' + 'patch' => '2017.01.23', + 'version' => '0.0.23' ];