Skip to content

Commit

Permalink
Fixed adding addresses email from records
Browse files Browse the repository at this point in the history
  • Loading branch information
TomaszQr committed Jan 23, 2017
1 parent b9523bf commit f8722cf
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 23 deletions.
47 changes: 27 additions & 20 deletions plugins/yetiforce/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/yetiforce/compose.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions plugins/yetiforce/yetiforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
return [
'patch' => '2017.01.19',
'version' => '0.0.22'
'patch' => '2017.01.23',
'version' => '0.0.23'
];

0 comments on commit f8722cf

Please sign in to comment.