From a95acf21817659a91b4524206da833e72af0fb6e Mon Sep 17 00:00:00 2001 From: Siddhant Rajagopalan Date: Sun, 17 Aug 2014 13:59:26 +0530 Subject: [PATCH] indented code --- CRM/Mailing/Info.php | 314 +++--- api/v3/Mailing.php | 372 +++---- api/v3/MailingGroup.php | 44 +- api/v3/MailingRecipients.php | 2 +- js/angular-crmCaseType.js | 558 +++++----- js/angular-newMailing.js | 963 +++++++++--------- partials/crmMailingType/attachments.html | 36 +- partials/crmMailingType/composeonScreen.html | 16 +- partials/crmMailingType/content.html | 118 +-- partials/crmMailingType/headerandFooter.html | 20 +- partials/crmMailingType/ht.html | 2 +- partials/crmMailingType/mailingList.html | 48 +- partials/crmMailingType/main.html | 76 +- partials/crmMailingType/plainText.html | 2 +- partials/crmMailingType/previewMailing.html | 8 +- partials/crmMailingType/preview_ht.html | 18 +- .../crmMailingType/preview_plaintext.html | 18 +- partials/crmMailingType/recipient.html | 58 +- partials/crmMailingType/sched.html | 36 +- partials/crmMailingType/send.html | 42 +- partials/crmMailingType/test.html | 42 +- partials/crmMailingType/trackandRespond.html | 170 ++-- partials/crmMailingType/uploadContent.html | 20 +- 23 files changed, 1486 insertions(+), 1497 deletions(-) diff --git a/CRM/Mailing/Info.php b/CRM/Mailing/Info.php index 07968a1544..1c41f981d0 100644 --- a/CRM/Mailing/Info.php +++ b/CRM/Mailing/Info.php @@ -37,172 +37,172 @@ */ class CRM_Mailing_Info extends CRM_Core_Component_Info { - // docs inherited from interface - protected $keyword = 'mailing'; - - - // docs inherited from interface - /** - * @return array - */ - public function getInfo() { - return array( - 'name' => 'CiviMail', - 'translatedName' => ts('CiviMail'), - 'title' => 'CiviCRM Mailing Engine', - 'search' => 1, - 'showActivitiesInCore' => 1, - ); - } - - public function getAngularModules() { - $result = array(); - $result['crmMailing'] = array( - 'ext' => 'civicrm', - 'js' => array('js/angular-newMailing.js' , 'js/angularsanitize.js'), - ); + // docs inherited from interface + protected $keyword = 'mailing'; + + + // docs inherited from interface + /** + * @return array + */ + public function getInfo() { + return array( + 'name' => 'CiviMail', + 'translatedName' => ts('CiviMail'), + 'title' => 'CiviCRM Mailing Engine', + 'search' => 1, + 'showActivitiesInCore' => 1, + ); + } + + public function getAngularModules() { + $result = array(); + $result['crmMailing'] = array( + 'ext' => 'civicrm', + 'js' => array('js/angular-newMailing.js' , 'js/angularsanitize.js'), + ); $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); - $civiMails = civicrm_api3('Mailing', 'get', array()); - $campNames = civicrm_api3('Campaign', 'get', array()); - $mailStatus = civicrm_api3('MailingJob', 'get', array()); + $civiMails = civicrm_api3('Mailing', 'get', array()); + $campNames = civicrm_api3('Campaign', 'get', array()); + $mailStatus = civicrm_api3('MailingJob', 'get', array()); $groupNames = civicrm_api3('Group', 'get', array()); $headerfooterList = civicrm_api3('MailingComponent', 'get', array()); $emailAdd = civicrm_api3('Email', 'get', array( - 'sequential' => 1, - 'return' => "email", - 'contact_id' => $contactID, - )); + 'sequential' => 1, + 'return' => "email", + 'contact_id' => $contactID, + )); $mesTemplate = civicrm_api3('MessageTemplate', 'get', array( 'sequential' => 1, 'return' => array("msg_html", "id", "msg_title", "msg_subject"), 'workflow_id' => array('IS NULL' => ""), - )); + )); $mailGrp = civicrm_api3('MailingGroup','get', array()); $mailTokens = civicrm_api3('Mailing', 'get_token', array( 'usage' => 'Mailing')); - - - - CRM_Core_Resources::singleton()->addSetting(array( - 'crmMailing' => array( - 'civiMails' => array_values($civiMails['values']), - 'campNames' => array_values($campNames['values']), - 'mailStatus' => array_values($mailStatus['values']), - 'groupNames' => array_values($groupNames['values']), - 'headerfooterList' => array_values($headerfooterList['values']), - 'mesTemplate' => array_values($mesTemplate['values']), - 'emailAdd' => array_values($emailAdd['values']), - 'mailGrp' => array_values($mailGrp['values']), - 'mailTokens' => array_values($mailTokens), - 'contactid' => $contactID - ), - )); - return $result; - } - - /** - * @return bool - */ - static function workflowEnabled() { - $config = CRM_Core_Config::singleton(); - - // early exit, since not true for most - if (!$config->userSystem->is_drupal || - !function_exists('module_exists') - ) { - return FALSE; - } - - if (!module_exists('rules')) { - return FALSE; - } - - $enableWorkflow = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, - 'civimail_workflow', - NULL, - FALSE - ); - - return ($enableWorkflow && - $config->userSystem->is_drupal - ) ? TRUE : FALSE; - } - - // docs inherited from interface - /** - * @param bool $getAllUnconditionally - * - * @return array - */ - public function getPermissions($getAllUnconditionally = FALSE) { - $permissions = array( - 'access CiviMail', - 'access CiviMail subscribe/unsubscribe pages', - 'delete in CiviMail', - 'view public CiviMail content', - ); - - if (self::workflowEnabled() || $getAllUnconditionally) { - $permissions[] = 'create mailings'; - $permissions[] = 'schedule mailings'; - $permissions[] = 'approve mailings'; - } - - return $permissions; - } - - - // docs inherited from interface - /** - * @return null - */ - public function getUserDashboardElement() { - // no dashboard element for this component - return NULL; - } - - /** - * @return null - */ - public function getUserDashboardObject() { - // no dashboard element for this component - return NULL; - } - - // docs inherited from interface - /** - * @return array - */ - public function registerTab() { - return array( - 'title' => ts('Mailings'), - 'id' => 'mailing', - 'url' => 'mailing', - 'weight' => 45, - ); - } - - // docs inherited from interface - /** - * @return array - */ - public function registerAdvancedSearchPane() { - return array('title' => ts('Mailings'), - 'weight' => 20, - ); - } - - // docs inherited from interface - /** - * @return null - */ - public function getActivityTypes() { - return NULL; - } - - // add shortcut to Create New - /** - * @param $shortCuts - */ - public function creatNewShortcut(&$shortCuts) {} + + + + CRM_Core_Resources::singleton()->addSetting(array( + 'crmMailing' => array( + 'civiMails' => array_values($civiMails['values']), + 'campNames' => array_values($campNames['values']), + 'mailStatus' => array_values($mailStatus['values']), + 'groupNames' => array_values($groupNames['values']), + 'headerfooterList' => array_values($headerfooterList['values']), + 'mesTemplate' => array_values($mesTemplate['values']), + 'emailAdd' => array_values($emailAdd['values']), + 'mailGrp' => array_values($mailGrp['values']), + 'mailTokens' => array_values($mailTokens), + 'contactid' => $contactID + ), + )); + return $result; + } + + /** + * @return bool + */ + static function workflowEnabled() { + $config = CRM_Core_Config::singleton(); + + // early exit, since not true for most + if (!$config->userSystem->is_drupal || + !function_exists('module_exists') + ) { + return FALSE; + } + + if (!module_exists('rules')) { + return FALSE; + } + + $enableWorkflow = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, + 'civimail_workflow', + NULL, + FALSE + ); + + return ($enableWorkflow && + $config->userSystem->is_drupal + ) ? TRUE : FALSE; + } + + // docs inherited from interface + /** + * @param bool $getAllUnconditionally + * + * @return array + */ + public function getPermissions($getAllUnconditionally = FALSE) { + $permissions = array( + 'access CiviMail', + 'access CiviMail subscribe/unsubscribe pages', + 'delete in CiviMail', + 'view public CiviMail content', + ); + + if (self::workflowEnabled() || $getAllUnconditionally) { + $permissions[] = 'create mailings'; + $permissions[] = 'schedule mailings'; + $permissions[] = 'approve mailings'; + } + + return $permissions; + } + + + // docs inherited from interface + /** + * @return null + */ + public function getUserDashboardElement() { + // no dashboard element for this component + return NULL; + } + + /** + * @return null + */ + public function getUserDashboardObject() { + // no dashboard element for this component + return NULL; + } + + // docs inherited from interface + /** + * @return array + */ + public function registerTab() { + return array( + 'title' => ts('Mailings'), + 'id' => 'mailing', + 'url' => 'mailing', + 'weight' => 45, + ); + } + + // docs inherited from interface + /** + * @return array + */ + public function registerAdvancedSearchPane() { + return array('title' => ts('Mailings'), + 'weight' => 20, + ); + } + + // docs inherited from interface + /** + * @return null + */ + public function getActivityTypes() { + return NULL; + } + + // add shortcut to Create New + /** + * @param $shortCuts + */ + public function creatNewShortcut(&$shortCuts) {} } diff --git a/api/v3/Mailing.php b/api/v3/Mailing.php index 6f8446cc79..e0631f6fed 100644 --- a/api/v3/Mailing.php +++ b/api/v3/Mailing.php @@ -50,34 +50,34 @@ * @return array API Success Array */ function civicrm_api3_mailing_create($params, $ids = array()) { - return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); + return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); } -function civicrm_api3_mailing_get_token($params) { - if (!array_key_exists("usage", $params)) { - throw new API_Exception('Mandatory keys missing from params array: entity'); - } - +function civicrm_api3_mailing_get_token($params) { + if (!array_key_exists("usage", $params)) { + throw new API_Exception('Mandatory keys missing from params array: entity'); + } + $tokens = CRM_Core_SelectValues::contactTokens(); switch ($params['usage']) { - case 'Mailing' : - $tokens = array_merge(CRM_Core_SelectValues::mailingTokens(), $tokens); - break; + case 'Mailing' : + $tokens = array_merge(CRM_Core_SelectValues::mailingTokens(), $tokens); + break; case 'ScheduleEventReminder' : - $tokens = array_merge(CRM_Core_SelectValues::activityTokens(), $tokens); + $tokens = array_merge(CRM_Core_SelectValues::activityTokens(), $tokens); $tokens = array_merge(CRM_Core_SelectValues::eventTokens(), $tokens); - $tokens = array_merge(CRM_Core_SelectValues::membershipTokens(), $tokens); - break; - case 'ManageEventScheduleReminder' : + $tokens = array_merge(CRM_Core_SelectValues::membershipTokens(), $tokens); + break; + case 'ManageEventScheduleReminder' : $tokens = array_merge(CRM_Core_SelectValues::eventTokens(), $tokens); break; - } - - return CRM_Utils_Token::formatTokensForDisplay($tokens); + } + + return CRM_Utils_Token::formatTokensForDisplay($tokens); } - - + + /** * Adjust Metadata for Create action @@ -86,12 +86,12 @@ function civicrm_api3_mailing_get_token($params) { * @param array $params array or parameters determined by getfields */ function _civicrm_api3_mailing_create_spec(&$params) { - $params['name']['api.required'] = 1; - $params['subject']['api.required'] = 1; - // should be able to default to 'user_contact_id' & have it work but it didn't work in test so - // making required for simplicity - $params['created_id']['api.required'] = 1; - $params['api.mailing_job.create']['api.default'] = 1; + $params['name']['api.required'] = 1; + $params['subject']['api.required'] = 1; + // should be able to default to 'user_contact_id' & have it work but it didn't work in test so + // making required for simplicity + $params['created_id']['api.required'] = 1; + $params['api.mailing_job.create']['api.default'] = 1; } /** @@ -103,7 +103,7 @@ function _civicrm_api3_mailing_create_spec(&$params) { * @return array API Success Array */ function civicrm_api3_mailing_delete($params, $ids = array()) { - return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); + return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); } @@ -114,7 +114,7 @@ function civicrm_api3_mailing_delete($params, $ids = array()) { * @return array */ function civicrm_api3_mailing_get($params) { - return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); + return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } /** @@ -127,18 +127,18 @@ function civicrm_api3_mailing_get($params) { */ function civicrm_api3_mailing_event_bounce($params) { - $body = $params['body']; - unset($params['body']); + $body = $params['body']; + unset($params['body']); - $params += CRM_Mailing_BAO_BouncePattern::match($body); + $params += CRM_Mailing_BAO_BouncePattern::match($body); - if (CRM_Mailing_Event_BAO_Bounce::create($params)) { - return civicrm_api3_create_success($params); - } - else { - throw new API_Exception(ts('Queue event could not be found'),'no_queue_event + if (CRM_Mailing_Event_BAO_Bounce::create($params)) { + return civicrm_api3_create_success($params); + } + else { + throw new API_Exception(ts('Queue event could not be found'),'no_queue_event '); - } + } } /** @@ -148,10 +148,10 @@ function civicrm_api3_mailing_event_bounce($params) { * @param array $params array or parameters determined by getfields */ function _civicrm_api3_mailing_event_bounce_spec(&$params) { - $params['job_id']['api.required'] = 1; - $params['event_queue_id']['api.required'] = 1; - $params['hash']['api.required'] = 1; - $params['body']['api.required'] = 1; + $params['job_id']['api.required'] = 1; + $params['event_queue_id']['api.required'] = 1; + $params['hash']['api.required'] = 1; + $params['body']['api.required'] = 1; } /** @@ -163,7 +163,7 @@ function _civicrm_api3_mailing_event_bounce_spec(&$params) { * @return array */ function civicrm_api3_mailing_event_confirm($params) { - return civicrm_api('mailing_event_confirm', 'create', $params); + return civicrm_api('mailing_event_confirm', 'create', $params); } /** @@ -174,23 +174,23 @@ function civicrm_api3_mailing_event_confirm($params) { * @return array */ function civicrm_api3_mailing_event_reply($params) { - $job = $params['job_id']; - $queue = $params['event_queue_id']; - $hash = $params['hash']; - $replyto = $params['replyTo']; - $bodyTxt = CRM_Utils_Array::value('bodyTxt', $params); - $bodyHTML = CRM_Utils_Array::value('bodyHTML', $params); - $fullEmail = CRM_Utils_Array::value('fullEmail', $params); + $job = $params['job_id']; + $queue = $params['event_queue_id']; + $hash = $params['hash']; + $replyto = $params['replyTo']; + $bodyTxt = CRM_Utils_Array::value('bodyTxt', $params); + $bodyHTML = CRM_Utils_Array::value('bodyHTML', $params); + $fullEmail = CRM_Utils_Array::value('fullEmail', $params); - $mailing = CRM_Mailing_Event_BAO_Reply::reply($job, $queue, $hash, $replyto); + $mailing = CRM_Mailing_Event_BAO_Reply::reply($job, $queue, $hash, $replyto); - if (empty($mailing)) { - return civicrm_api3_create_error('Queue event could not be found'); - } + if (empty($mailing)) { + return civicrm_api3_create_error('Queue event could not be found'); + } - CRM_Mailing_Event_BAO_Reply::send($queue, $mailing, $bodyTxt, $replyto, $bodyHTML, $fullEmail); + CRM_Mailing_Event_BAO_Reply::send($queue, $mailing, $bodyTxt, $replyto, $bodyHTML, $fullEmail); - return civicrm_api3_create_success($params); + return civicrm_api3_create_success($params); } /** @@ -200,10 +200,10 @@ function civicrm_api3_mailing_event_reply($params) { * @param array $params array or parameters determined by getfields */ function _civicrm_api3_mailing_event_reply_spec(&$params) { - $params['job_id']['api.required'] = 1; - $params['event_queue_id']['api.required'] = 1; - $params['hash']['api.required'] = 1; - $params['replyTo']['api.required'] = 0; + $params['job_id']['api.required'] = 1; + $params['event_queue_id']['api.required'] = 1; + $params['hash']['api.required'] = 1; + $params['replyTo']['api.required'] = 0; } /** @@ -214,20 +214,20 @@ function _civicrm_api3_mailing_event_reply_spec(&$params) { * @return array */ function civicrm_api3_mailing_event_forward($params) { - $job = $params['job_id']; - $queue = $params['event_queue_id']; - $hash = $params['hash']; - $email = $params['email']; - $fromEmail = CRM_Utils_Array::value('fromEmail', $params); - $params = CRM_Utils_Array::value('params', $params); + $job = $params['job_id']; + $queue = $params['event_queue_id']; + $hash = $params['hash']; + $email = $params['email']; + $fromEmail = CRM_Utils_Array::value('fromEmail', $params); + $params = CRM_Utils_Array::value('params', $params); - $forward = CRM_Mailing_Event_BAO_Forward::forward($job, $queue, $hash, $email, $fromEmail, $params); + $forward = CRM_Mailing_Event_BAO_Forward::forward($job, $queue, $hash, $email, $fromEmail, $params); - if ($forward) { - return civicrm_api3_create_success($params); - } + if ($forward) { + return civicrm_api3_create_success($params); + } - return civicrm_api3_create_error('Queue event could not be found'); + return civicrm_api3_create_error('Queue event could not be found'); } /** @@ -237,10 +237,10 @@ function civicrm_api3_mailing_event_forward($params) { * @param array $params array or parameters determined by getfields */ function _civicrm_api3_mailing_event_forward_spec(&$params) { - $params['job_id']['api.required'] = 1; - $params['event_queue_id']['api.required'] = 1; - $params['hash']['api.required'] = 1; - $params['email']['api.required'] = 1; + $params['job_id']['api.required'] = 1; + $params['event_queue_id']['api.required'] = 1; + $params['hash']['api.required'] = 1; + $params['email']['api.required'] = 1; } /** @@ -252,22 +252,22 @@ function _civicrm_api3_mailing_event_forward_spec(&$params) { */ function civicrm_api3_mailing_event_click($params) { - civicrm_api3_verify_mandatory($params, - 'CRM_Mailing_Event_DAO_TrackableURLOpen', - array('event_queue_id', 'url_id'), - FALSE - ); + civicrm_api3_verify_mandatory($params, + 'CRM_Mailing_Event_DAO_TrackableURLOpen', + array('event_queue_id', 'url_id'), + FALSE + ); - $url_id = $params['url_id']; - $queue = $params['event_queue_id']; + $url_id = $params['url_id']; + $queue = $params['event_queue_id']; - $url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($queue, $url_id); + $url = CRM_Mailing_Event_BAO_TrackableURLOpen::track($queue, $url_id); - $values = array(); - $values['url'] = $url; - $values['is_error'] = 0; + $values = array(); + $values['url'] = $url; + $values['is_error'] = 0; - return civicrm_api3_create_success($values); + return civicrm_api3_create_success($values); } /** @@ -279,20 +279,20 @@ function civicrm_api3_mailing_event_click($params) { */ function civicrm_api3_mailing_event_open($params) { - civicrm_api3_verify_mandatory($params, - 'CRM_Mailing_Event_DAO_Opened', - array('event_queue_id'), - FALSE - ); + civicrm_api3_verify_mandatory($params, + 'CRM_Mailing_Event_DAO_Opened', + array('event_queue_id'), + FALSE + ); - $queue = $params['event_queue_id']; - $success = CRM_Mailing_Event_BAO_Opened::open($queue); + $queue = $params['event_queue_id']; + $success = CRM_Mailing_Event_BAO_Opened::open($queue); - if (!$success) { - return civicrm_api3_create_error('mailing open event failed'); - } + if (!$success) { + return civicrm_api3_create_error('mailing open event failed'); + } - return civicrm_api3_create_success($params); + return civicrm_api3_create_success($params); } /** @@ -301,57 +301,57 @@ function civicrm_api3_mailing_event_open($params) { * Both the min and max days can be set via the params */ function civicrm_api3_mailing_update_email_resetdate($params) { - CRM_Mailing_Event_BAO_Delivered::updateEmailResetDate( - CRM_Utils_Array::value('minDays', $params, 3), - CRM_Utils_Array::value('maxDays', $params, 3) - ); - return civicrm_api3_create_success(); + CRM_Mailing_Event_BAO_Delivered::updateEmailResetDate( + CRM_Utils_Array::value('minDays', $params, 3), + CRM_Utils_Array::value('maxDays', $params, 3) + ); + return civicrm_api3_create_success(); } function civicrm_api3_mailing_preview($params) { - civicrm_api3_verify_mandatory($params, - 'CRM_Mailing_DAO_Mailing', - array('id'), - FALSE - ); - $session = CRM_Core_Session::singleton(); - $mailing = new CRM_Mailing_BAO_Mailing(); - $mailing->id = $params['id']; - $mailing->find(TRUE); - CRM_Mailing_BAO_Mailing::tokenReplace($mailing); - // get and format attachments - $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id); - $returnProperties = $mailing->getReturnProperties(); - $contactID = CRM_Utils_Array::value('contact_id', $params); - if (!$contactID) { - $contactID = $session->get('userID'); - } - $mailingParams = array('contact_id' => $contactID); - $details = CRM_Utils_Token::getTokenDetails($mailingParams, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens()); - $mime = &$mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, - TRUE, $details[0][$session->get('userID')], $attachments - ); - return civicrm_api3_create_success(array('subject' => $mime->_headers['Subject'], 'html' => $mime->getHTMLBody(), 'text' => $mime->getTXTBody())); + civicrm_api3_verify_mandatory($params, + 'CRM_Mailing_DAO_Mailing', + array('id'), + FALSE + ); + $session = CRM_Core_Session::singleton(); + $mailing = new CRM_Mailing_BAO_Mailing(); + $mailing->id = $params['id']; + $mailing->find(TRUE); + CRM_Mailing_BAO_Mailing::tokenReplace($mailing); + // get and format attachments + $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id); + $returnProperties = $mailing->getReturnProperties(); + $contactID = CRM_Utils_Array::value('contact_id', $params); + if (!$contactID) { + $contactID = $session->get('userID'); + } + $mailingParams = array('contact_id' => $contactID); + $details = CRM_Utils_Token::getTokenDetails($mailingParams, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens()); + $mime = &$mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, + TRUE, $details[0][$session->get('userID')], $attachments + ); + return civicrm_api3_create_success(array('subject' => $mime->_headers['Subject'], 'html' => $mime->getHTMLBody(), 'text' => $mime->getTXTBody())); } function civicrm_api3_mailing_send_test($params) { - if (!array_key_exists('test_group', $params) && !array_key_exists('test_email', $params)) { - throw new API_Exception("Mandatory key(s) missing from params array: test_group and/or test_email field are required" ); - } - civicrm_api3_verify_mandatory($params, - 'CRM_Mailing_DAO_MailingJob', - array('mailing_id'), - FALSE - ); - - $testEmailParams = _civicrm_api3_generic_replace_base_params($params); - $testEmailParams['is_test'] = 1; - $job = civicrm_api3('MailingJob', 'create', $testEmailParams); - print_r($job); - $testEmailParams['job_id'] = $job['id']; - $testEmailParams['emails'] = explode(',', $testEmailParams['test_email']); - if (!empty($params['test_email'])) { - $query = " + if (!array_key_exists('test_group', $params) && !array_key_exists('test_email', $params)) { + throw new API_Exception("Mandatory key(s) missing from params array: test_group and/or test_email field are required" ); + } + civicrm_api3_verify_mandatory($params, + 'CRM_Mailing_DAO_MailingJob', + array('mailing_id'), + FALSE + ); + + $testEmailParams = _civicrm_api3_generic_replace_base_params($params); + $testEmailParams['is_test'] = 1; + $job = civicrm_api3('MailingJob', 'create', $testEmailParams); + print_r($job); + $testEmailParams['job_id'] = $job['id']; + $testEmailParams['emails'] = explode(',', $testEmailParams['test_email']); + if (!empty($params['test_email'])) { + $query = " SELECT e.id, e.contact_id, e.email FROM civicrm_email e INNER JOIN civicrm_contact c ON e.contact_id = c.id @@ -363,51 +363,51 @@ AND c.is_deceased = 0 GROUP BY e.id ORDER BY e.is_bulkmail DESC, e.is_primary DESC "; - $dao = CRM_Core_DAO::executeQuery($query); - $emailDetail = array(); - // fetch contact_id and email id for all existing emails - while ($dao->fetch()) { - $emailDetail[$dao->email] = array( - 'contact_id' => $dao->contact_id, - 'email_id' => $dao->id, - ); - } - $dao->free(); - foreach ($testEmailParams['emails'] as $key => $email) { - $email = trim($email); - $contactId = $emailId = NULL; - if (array_key_exists($email, $emailDetail)) { - $emailId = $emailDetail[$email]['email_id']; - $contactId = $emailDetail[$email]['contact_id']; - } - if (!$contactId) { - //create new contact. - $contact = civicrm_api3('Contact', 'create', - array('contact_type' => 'Individual', - 'email' => $email, - 'api.Email.get' => array('return' => 'id') - ) - ); - $contactId = $contact['id']; - $emailId = $contact['values'][$contactId]['api.Email.get']['id']; - } - civicrm_api3('MailingEventQueue', 'create', - array('job_id' => $job['id'], - 'email_id' => $emailId, - 'contact_id' => $contactId - ) - ); - } - } - - $isComplete = FALSE; - while (!$isComplete) { - $isComplete = CRM_Mailing_BAO_MailingJob::runJobs($testEmailParams); - } - - //return delivered mail info - $mailDelivered = CRM_Mailing_Event_BAO_Delivered::getRows($params['mailing_id'], $job['id'], TRUE, NULL, NULL, NULL); -print_r($mailDelivered); - return civicrm_api3_create_success($mailDelivered); + $dao = CRM_Core_DAO::executeQuery($query); + $emailDetail = array(); + // fetch contact_id and email id for all existing emails + while ($dao->fetch()) { + $emailDetail[$dao->email] = array( + 'contact_id' => $dao->contact_id, + 'email_id' => $dao->id, + ); + } + $dao->free(); + foreach ($testEmailParams['emails'] as $key => $email) { + $email = trim($email); + $contactId = $emailId = NULL; + if (array_key_exists($email, $emailDetail)) { + $emailId = $emailDetail[$email]['email_id']; + $contactId = $emailDetail[$email]['contact_id']; + } + if (!$contactId) { + //create new contact. + $contact = civicrm_api3('Contact', 'create', + array('contact_type' => 'Individual', + 'email' => $email, + 'api.Email.get' => array('return' => 'id') + ) + ); + $contactId = $contact['id']; + $emailId = $contact['values'][$contactId]['api.Email.get']['id']; + } + civicrm_api3('MailingEventQueue', 'create', + array('job_id' => $job['id'], + 'email_id' => $emailId, + 'contact_id' => $contactId + ) + ); + } + } + + $isComplete = FALSE; + while (!$isComplete) { + $isComplete = CRM_Mailing_BAO_MailingJob::runJobs($testEmailParams); + } + + //return delivered mail info + $mailDelivered = CRM_Mailing_Event_BAO_Delivered::getRows($params['mailing_id'], $job['id'], TRUE, NULL, NULL, NULL); + print_r($mailDelivered); + return civicrm_api3_create_success($mailDelivered); } diff --git a/api/v3/MailingGroup.php b/api/v3/MailingGroup.php index 5ab4923761..546d2de808 100644 --- a/api/v3/MailingGroup.php +++ b/api/v3/MailingGroup.php @@ -46,7 +46,7 @@ * @return array */ function civicrm_api3_mailing_group_event_unsubscribe($params) { - return civicrm_api('mailing_event_unsubscribe', 'create', $params); + return civicrm_api('mailing_event_unsubscribe', 'create', $params); } /** @@ -58,8 +58,8 @@ function civicrm_api3_mailing_group_event_unsubscribe($params) { * @return array */ function civicrm_api3_mailing_group_event_domain_unsubscribe($params) { - $params['org_unsubscribe'] = 1; - return civicrm_api('mailing_event_unsubscribe', 'create', $params); + $params['org_unsubscribe'] = 1; + return civicrm_api('mailing_event_unsubscribe', 'create', $params); } /** @@ -71,7 +71,7 @@ function civicrm_api3_mailing_group_event_domain_unsubscribe($params) { * @return array */ function civicrm_api3_mailing_group_event_resubscribe($params) { - return civicrm_api('mailing_event_resubscribe', 'create', $params); + return civicrm_api('mailing_event_resubscribe', 'create', $params); } /** @@ -83,7 +83,7 @@ function civicrm_api3_mailing_group_event_resubscribe($params) { * @return array */ function civicrm_api3_mailing_group_event_subscribe($params) { - return civicrm_api('mailing_event_subscribe', 'create', $params); + return civicrm_api('mailing_event_subscribe', 'create', $params); } /** @@ -92,31 +92,31 @@ function civicrm_api3_mailing_group_event_subscribe($params) { * @return array */ function civicrm_api3_mailing_group_get($params) { - return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); + return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } - + function civicrm_api3_mailing_group_delete($params, $ids = array()) { - return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); + return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); } function civicrm_api3_mailing_group_getfields($params) { - $dao = _civicrm_api3_get_DAO('Subscribe'); - $d = new $dao(); - $fields = $d->fields(); - $d->free(); + $dao = _civicrm_api3_get_DAO('Subscribe'); + $d = new $dao(); + $fields = $d->fields(); + $d->free(); - $dao = _civicrm_api3_get_DAO('Unsubscribe'); - $d = new $dao(); - $fields = $fields + $d->fields(); - $d->free(); + $dao = _civicrm_api3_get_DAO('Unsubscribe'); + $d = new $dao(); + $fields = $fields + $d->fields(); + $d->free(); - // CRM-13830 - prevent the api wrapper from helping out with pseudoconstants - // Since these fields don't belong to this entity it will fail - foreach ($fields as &$field) { - unset($field['pseudoconstant']); - } + // CRM-13830 - prevent the api wrapper from helping out with pseudoconstants + // Since these fields don't belong to this entity it will fail + foreach ($fields as &$field) { + unset($field['pseudoconstant']); + } - return civicrm_api3_create_success($fields); + return civicrm_api3_create_success($fields); } diff --git a/api/v3/MailingRecipients.php b/api/v3/MailingRecipients.php index 2cdc4a6611..f230eb0dc4 100644 --- a/api/v3/MailingRecipients.php +++ b/api/v3/MailingRecipients.php @@ -53,7 +53,7 @@ * @access public */ function civicrm_api3_mailing_recipients_get($params, $ids = array()) { - return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); + return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); } diff --git a/js/angular-crmCaseType.js b/js/angular-crmCaseType.js index b6d107ca3c..06e2cfbe7d 100644 --- a/js/angular-crmCaseType.js +++ b/js/angular-crmCaseType.js @@ -1,313 +1,313 @@ (function(angular, $, _) { - var partialUrl = function(relPath) { - return CRM.resourceUrls['civicrm'] + '/partials/crmCaseType/' + relPath; - }; + var partialUrl = function(relPath) { + return CRM.resourceUrls['civicrm'] + '/partials/crmCaseType/' + relPath; + }; - var crmCaseType = angular.module('crmCaseType', ['ngRoute', 'ui.utils', 'crmUi', 'unsavedChanges']); + var crmCaseType = angular.module('crmCaseType', ['ngRoute', 'ui.utils', 'crmUi', 'unsavedChanges']); - // Note: This template will be passed to cloneDeep(), so don't put any funny stuff in here! - var newCaseTypeTemplate = { - title: "", - name: "", - is_active: "1", - weight: "1", - definition: { - activityTypes: [ - {name: 'Open Case', max_instances: 1 } - ], - activitySets: [ - { - name: 'standard_timeline', - label: 'Standard Timeline', - timeline: '1', // Angular won't bind checkbox correctly with numeric 1 - activityTypes: [ - {name: 'Open Case', status: 'Completed' } - ] - } - ], - caseRoles: [ - { name: 'Case Coordinator', creator: '1', manager: '1'} - ] - } - }; + // Note: This template will be passed to cloneDeep(), so don't put any funny stuff in here! + var newCaseTypeTemplate = { + title: "", + name: "", + is_active: "1", + weight: "1", + definition: { + activityTypes: [ + {name: 'Open Case', max_instances: 1 } + ], + activitySets: [ + { + name: 'standard_timeline', + label: 'Standard Timeline', + timeline: '1', // Angular won't bind checkbox correctly with numeric 1 + activityTypes: [ + {name: 'Open Case', status: 'Completed' } + ] + } + ], + caseRoles: [ + { name: 'Case Coordinator', creator: '1', manager: '1'} + ] + } + }; - crmCaseType.config(['$routeProvider', - function($routeProvider) { - $routeProvider.when('/caseType', { - templateUrl: partialUrl('list.html'), - controller: 'CaseTypeListCtrl', - resolve: { - caseTypes: function($route, crmApi) { - return crmApi('CaseType', 'get', {}); - } - } - }); - $routeProvider.when('/caseType/:id', { - templateUrl: partialUrl('edit.html'), - controller: 'CaseTypeCtrl', - resolve: { - apiCalls: function($route, crmApi) { - var reqs = {}; - reqs.actStatuses = ['OptionValue', 'get', { - option_group_id: 'activity_status' - }]; - reqs.actTypes = ['OptionValue', 'get', { - option_group_id: 'activity_type', - options: { - sort: 'name', - limit: 0 - } - }]; - reqs.relTypes = ['RelationshipType', 'get', { - options: { - sort: CRM.crmCaseType.REL_TYPE_CNAME, - limit: 0 - } - }]; - if ($route.current.params.id !== 'new') { - reqs.caseType = ['CaseType', 'getsingle', { - id: $route.current.params.id - }]; - } - return crmApi(reqs); - } - } - }); - } - ]); + crmCaseType.config(['$routeProvider', + function($routeProvider) { + $routeProvider.when('/caseType', { + templateUrl: partialUrl('list.html'), + controller: 'CaseTypeListCtrl', + resolve: { + caseTypes: function($route, crmApi) { + return crmApi('CaseType', 'get', {}); + } + } + }); + $routeProvider.when('/caseType/:id', { + templateUrl: partialUrl('edit.html'), + controller: 'CaseTypeCtrl', + resolve: { + apiCalls: function($route, crmApi) { + var reqs = {}; + reqs.actStatuses = ['OptionValue', 'get', { + option_group_id: 'activity_status' + }]; + reqs.actTypes = ['OptionValue', 'get', { + option_group_id: 'activity_type', + options: { + sort: 'name', + limit: 0 + } + }]; + reqs.relTypes = ['RelationshipType', 'get', { + options: { + sort: CRM.crmCaseType.REL_TYPE_CNAME, + limit: 0 + } + }]; + if ($route.current.params.id !== 'new') { + reqs.caseType = ['CaseType', 'getsingle', { + id: $route.current.params.id + }]; + } + return crmApi(reqs); + } + } + }); + } + ]); - // Add a new record by name. - // Ex: - crmCaseType.directive('crmAddName', function() { - return { - restrict: 'AE', - template: '', - link: function(scope, element, attrs) { - /// Format list of options for select2's "data" - var getFormattedOptions = function() { - return { - results: _.map(scope[attrs.crmOptions], function(option){ - return {id: option, text: option}; - }) - }; - }; + // Add a new record by name. + // Ex: + crmCaseType.directive('crmAddName', function() { + return { + restrict: 'AE', + template: '', + link: function(scope, element, attrs) { + /// Format list of options for select2's "data" + var getFormattedOptions = function() { + return { + results: _.map(scope[attrs.crmOptions], function(option){ + return {id: option, text: option}; + }) + }; + }; - var input = $('input', element); + var input = $('input', element); - scope._resetSelection = function() { - $(input).select2('close'); - $(input).select2('val', ''); - scope[attrs.crmVar] = ''; - }; + scope._resetSelection = function() { + $(input).select2('close'); + $(input).select2('val', ''); + scope[attrs.crmVar] = ''; + }; - $(input).select2({ - data: getFormattedOptions, - createSearchChoice: function(term) { - return {id: term, text: term}; - } - }); - $(input).on('select2-selecting', function(e) { - scope[attrs.crmVar] = e.val; - scope.$evalAsync(attrs.crmOnAdd); - scope.$evalAsync('_resetSelection()'); - e.preventDefault(); - }); + $(input).select2({ + data: getFormattedOptions, + createSearchChoice: function(term) { + return {id: term, text: term}; + } + }); + $(input).on('select2-selecting', function(e) { + scope[attrs.crmVar] = e.val; + scope.$evalAsync(attrs.crmOnAdd); + scope.$evalAsync('_resetSelection()'); + e.preventDefault(); + }); - scope.$watch(attrs.crmOptions, function(value) { - $(input).select2('data', getFormattedOptions); - $(input).select2('val', ''); - }); - } - }; - }); + scope.$watch(attrs.crmOptions, function(value) { + $(input).select2('data', getFormattedOptions); + $(input).select2('val', ''); + }); + } + }; + }); - crmCaseType.controller('CaseTypeCtrl', function($scope, crmApi, apiCalls) { - $scope.partialUrl = partialUrl; + crmCaseType.controller('CaseTypeCtrl', function($scope, crmApi, apiCalls) { + $scope.partialUrl = partialUrl; - $scope.activityStatuses = _.values(apiCalls.actStatuses.values); - $scope.activityTypes = apiCalls.actTypes.values; - $scope.activityTypeNames = _.pluck(apiCalls.actTypes.values, 'name'); - $scope.relationshipTypeNames = _.pluck(apiCalls.relTypes.values, CRM.crmCaseType.REL_TYPE_CNAME); // CRM_Case_XMLProcessor::REL_TYPE_CNAME - $scope.locks = {caseTypeName: true}; + $scope.activityStatuses = _.values(apiCalls.actStatuses.values); + $scope.activityTypes = apiCalls.actTypes.values; + $scope.activityTypeNames = _.pluck(apiCalls.actTypes.values, 'name'); + $scope.relationshipTypeNames = _.pluck(apiCalls.relTypes.values, CRM.crmCaseType.REL_TYPE_CNAME); // CRM_Case_XMLProcessor::REL_TYPE_CNAME + $scope.locks = {caseTypeName: true}; - $scope.workflows = { - 'timeline': 'Timeline', - 'sequence': 'Sequence' - }; + $scope.workflows = { + 'timeline': 'Timeline', + 'sequence': 'Sequence' + }; - $scope.caseType = apiCalls.caseType ? apiCalls.caseType : _.cloneDeep(newCaseTypeTemplate); - $scope.caseType.definition = $scope.caseType.definition || []; - $scope.caseType.definition.activityTypes = $scope.caseType.definition.activityTypes || []; - $scope.caseType.definition.activitySets = $scope.caseType.definition.activitySets || []; - $scope.caseType.definition.caseRoles = $scope.caseType.definition.caseRoles || []; - window.ct = $scope.caseType; + $scope.caseType = apiCalls.caseType ? apiCalls.caseType : _.cloneDeep(newCaseTypeTemplate); + $scope.caseType.definition = $scope.caseType.definition || []; + $scope.caseType.definition.activityTypes = $scope.caseType.definition.activityTypes || []; + $scope.caseType.definition.activitySets = $scope.caseType.definition.activitySets || []; + $scope.caseType.definition.caseRoles = $scope.caseType.definition.caseRoles || []; + window.ct = $scope.caseType; - $scope.addActivitySet = function(workflow) { - var activitySet = {}; - activitySet[workflow] = '1'; - activitySet.activityTypes = []; + $scope.addActivitySet = function(workflow) { + var activitySet = {}; + activitySet[workflow] = '1'; + activitySet.activityTypes = []; - var offset = 1; - var names = _.pluck($scope.caseType.definition.activitySets, 'name'); - while (_.contains(names, workflow + '_' + offset)) offset++; - activitySet.name = workflow + '_' + offset; - activitySet.label = (offset == 1 ) ? $scope.workflows[workflow] : ($scope.workflows[workflow] + ' #' + offset); + var offset = 1; + var names = _.pluck($scope.caseType.definition.activitySets, 'name'); + while (_.contains(names, workflow + '_' + offset)) offset++; + activitySet.name = workflow + '_' + offset; + activitySet.label = (offset == 1 ) ? $scope.workflows[workflow] : ($scope.workflows[workflow] + ' #' + offset); - $scope.caseType.definition.activitySets.push(activitySet); - _.defer(function() { - $('.crmCaseType-acttab').tabs('refresh').tabs({active: -1}); - }); - }; + $scope.caseType.definition.activitySets.push(activitySet); + _.defer(function() { + $('.crmCaseType-acttab').tabs('refresh').tabs({active: -1}); + }); + }; - /// Add a new activity entry to an activity-set - $scope.addActivity = function(activitySet, activityType) { - activitySet.activityTypes.push({ - name: activityType, - status: 'Scheduled', - reference_activity: 'Open Case', - reference_offset: '1', - reference_select: 'newest' - }); - if (!_.contains($scope.activityTypeNames, activityType)) { - $scope.activityTypeNames.push(activityType); - } - }; + /// Add a new activity entry to an activity-set + $scope.addActivity = function(activitySet, activityType) { + activitySet.activityTypes.push({ + name: activityType, + status: 'Scheduled', + reference_activity: 'Open Case', + reference_offset: '1', + reference_select: 'newest' + }); + if (!_.contains($scope.activityTypeNames, activityType)) { + $scope.activityTypeNames.push(activityType); + } + }; - /// Add a new top-level activity-type entry - $scope.addActivityType = function(activityType) { - var names = _.pluck($scope.caseType.definition.activityTypes, 'name'); - if (!_.contains(names, activityType)) { - $scope.caseType.definition.activityTypes.push({ - name: activityType - }); + /// Add a new top-level activity-type entry + $scope.addActivityType = function(activityType) { + var names = _.pluck($scope.caseType.definition.activityTypes, 'name'); + if (!_.contains(names, activityType)) { + $scope.caseType.definition.activityTypes.push({ + name: activityType + }); - } - if (!_.contains($scope.activityTypeNames, activityType)) { - $scope.activityTypeNames.push(activityType); - } - }; + } + if (!_.contains($scope.activityTypeNames, activityType)) { + $scope.activityTypeNames.push(activityType); + } + }; - /// Add a new role - $scope.addRole = function(roles, roleName) { - var names = _.pluck($scope.caseType.definition.caseRoles, 'name'); - if (!_.contains(names, roleName)) { - roles.push({ - name: roleName - }); - } - if (!_.contains($scope.relationshipTypeNames, roleName)) { - $scope.relationshipTypeNames.push(roleName); - } - }; + /// Add a new role + $scope.addRole = function(roles, roleName) { + var names = _.pluck($scope.caseType.definition.caseRoles, 'name'); + if (!_.contains(names, roleName)) { + roles.push({ + name: roleName + }); + } + if (!_.contains($scope.relationshipTypeNames, roleName)) { + $scope.relationshipTypeNames.push(roleName); + } + }; - $scope.onManagerChange = function(managerRole) { - angular.forEach($scope.caseType.definition.caseRoles, function(caseRole) { - if (caseRole != managerRole) { - caseRole.manager = '0'; - } - }); - }; + $scope.onManagerChange = function(managerRole) { + angular.forEach($scope.caseType.definition.caseRoles, function(caseRole) { + if (caseRole != managerRole) { + caseRole.manager = '0'; + } + }); + }; - $scope.removeItem = function(array, item) { - var idx = _.indexOf(array, item); - if (idx != -1) { - array.splice(idx, 1); - } - }; + $scope.removeItem = function(array, item) { + var idx = _.indexOf(array, item); + if (idx != -1) { + array.splice(idx, 1); + } + }; - $scope.isNewActivitySetAllowed = function(workflow) { - switch (workflow) { - case 'timeline': - return true; - case 'sequence': - return 0 == _.where($scope.caseType.definition.activitySets, {sequence: '1'}).length; - default: - if (console && console.log) console.log('Denied access to unrecognized workflow: (' + workflow + ')'); - return false; - } - }; + $scope.isNewActivitySetAllowed = function(workflow) { + switch (workflow) { + case 'timeline': + return true; + case 'sequence': + return 0 == _.where($scope.caseType.definition.activitySets, {sequence: '1'}).length; + default: + if (console && console.log) console.log('Denied access to unrecognized workflow: (' + workflow + ')'); + return false; + } + }; - $scope.getWorkflowName = function(activitySet) { - var result = 'Unknown'; - _.each($scope.workflows, function(value, key) { - if (activitySet[key]) result = value; - }); - return result; - }; + $scope.getWorkflowName = function(activitySet) { + var result = 'Unknown'; + _.each($scope.workflows, function(value, key) { + if (activitySet[key]) result = value; + }); + return result; + }; - /** - * Determine which HTML partial to use for a particular - * - * @return string URL of the HTML partial - */ - $scope.activityTableTemplate = function(activitySet) { - if (activitySet.timeline) { - return partialUrl('timelineTable.html'); - } else if (activitySet.sequence) { - return partialUrl('sequenceTable.html'); - } else { - return ''; - } - }; + /** + * Determine which HTML partial to use for a particular + * + * @return string URL of the HTML partial + */ + $scope.activityTableTemplate = function(activitySet) { + if (activitySet.timeline) { + return partialUrl('timelineTable.html'); + } else if (activitySet.sequence) { + return partialUrl('sequenceTable.html'); + } else { + return ''; + } + }; - $scope.dump = function() { - console.log($scope.caseType); - }; + $scope.dump = function() { + console.log($scope.caseType); + }; - $scope.save = function() { - var result = crmApi('CaseType', 'create', $scope.caseType, true); - result.success(function(data) { - if (data.is_error == 0) { - $scope.caseType.id = data.id; - window.location.href = '#/caseType'; - } - }); - }; + $scope.save = function() { + var result = crmApi('CaseType', 'create', $scope.caseType, true); + result.success(function(data) { + if (data.is_error == 0) { + $scope.caseType.id = data.id; + window.location.href = '#/caseType'; + } + }); + }; - $scope.$watchCollection('caseType.definition.activitySets', function() { - _.defer(function() { - $('.crmCaseType-acttab').tabs('refresh'); - }); - }); + $scope.$watchCollection('caseType.definition.activitySets', function() { + _.defer(function() { + $('.crmCaseType-acttab').tabs('refresh'); + }); + }); - var updateCaseTypeName = function () { - if (!$scope.caseType.id && $scope.locks.caseTypeName) { - // Should we do some filtering? Lowercase? Strip whitespace? - var t = $scope.caseType.title ? $scope.caseType.title : ''; - $scope.caseType.name = t.replace(/ /g, '_').replace(/[^a-zA-Z0-9_]/g, '').toLowerCase(); - } - }; - $scope.$watch('locks.caseTypeName', updateCaseTypeName); - $scope.$watch('caseType.title', updateCaseTypeName); - }); + var updateCaseTypeName = function () { + if (!$scope.caseType.id && $scope.locks.caseTypeName) { + // Should we do some filtering? Lowercase? Strip whitespace? + var t = $scope.caseType.title ? $scope.caseType.title : ''; + $scope.caseType.name = t.replace(/ /g, '_').replace(/[^a-zA-Z0-9_]/g, '').toLowerCase(); + } + }; + $scope.$watch('locks.caseTypeName', updateCaseTypeName); + $scope.$watch('caseType.title', updateCaseTypeName); + }); - crmCaseType.controller('CaseTypeListCtrl', function($scope, crmApi, caseTypes) { - $scope.caseTypes = caseTypes.values; - $scope.toggleCaseType = function (caseType) { - caseType.is_active = (caseType.is_active == '1') ? '0' : '1'; - crmApi('CaseType', 'create', caseType, true) - .then(function (data) { - if (data.is_error) { - caseType.is_active = (caseType.is_active == '1') ? '0' : '1'; // revert - $scope.$digest(); - } - }); - }; - $scope.deleteCaseType = function (caseType) { - crmApi('CaseType', 'delete', {id: caseType.id}, { - error: function (data) { - CRM.alert(data.error_message, ts('Error')); - } - }) - .then(function (data) { - if (!data.is_error) { + crmCaseType.controller('CaseTypeListCtrl', function($scope, crmApi, caseTypes) { + $scope.caseTypes = caseTypes.values; + $scope.toggleCaseType = function (caseType) { + caseType.is_active = (caseType.is_active == '1') ? '0' : '1'; + crmApi('CaseType', 'create', caseType, true) + .then(function (data) { + if (data.is_error) { + caseType.is_active = (caseType.is_active == '1') ? '0' : '1'; // revert + $scope.$digest(); + } + }); + }; + $scope.deleteCaseType = function (caseType) { + crmApi('CaseType', 'delete', {id: caseType.id}, { + error: function (data) { + CRM.alert(data.error_message, ts('Error')); + } + }) + .then(function (data) { + if (!data.is_error) { console.log(caseTypes.values[caseType.id]); - delete caseTypes.values[caseType.id]; - $scope.$digest(); - } - }); - }; - }); + delete caseTypes.values[caseType.id]; + $scope.$digest(); + } + }); + }; + }); })(angular, CRM.$, CRM._); diff --git a/js/angular-newMailing.js b/js/angular-newMailing.js index 7cad3fa58f..ef6c7b9713 100644 --- a/js/angular-newMailing.js +++ b/js/angular-newMailing.js @@ -1,68 +1,56 @@ (function(angular, $, _) { //partials for the html pages - var partialUrl = function(relPath) { - return CRM.resourceUrls['civicrm'] + '/partials/crmMailingType/' + relPath; - }; + var partialUrl = function(relPath) { + return CRM.resourceUrls['civicrm'] + '/partials/crmMailingType/' + relPath; + }; - var crmMailing = angular.module('crmMailing', ['ngRoute', 'ui.utils','ngSanitize']); - var chck = []; //to fill the group variable $scope.incGroup - var chck2= []; // to get id and text in the required format + var crmMailing = angular.module('crmMailing', ['ngRoute', 'ui.utils','ngSanitize']); + var chck = []; //to fill the group variable $scope.incGroup + var chck2= []; // to get id and text in the required format var mltokens = []; var global = 0; //------------------------------------------------------------------------------------------------------- - crmMailing.config(['$routeProvider', - function($routeProvider) { - $routeProvider.when('/mailing', { - templateUrl: partialUrl('mailingList.html'), - controller: 'mailingListCtrl', - resolve: { - mailingList: function($route, crmApi) { - return crmApi('Mailing', 'get', {}); - } - - } - }); //This route is used for generating the list of mails created. - - - - $routeProvider.when('/mailing/:id', { - templateUrl: partialUrl('main.html'), - controller: 'mailingCtrl', - resolve: { - selectedMail: function($route, crmApi) { - if ( $route.current.params.id !== 'new') { - return crmApi('Mailing', 'getsingle', {id: $route.current.params.id}); - } - else { - //created_id has been set to my id. Does not save without created_id. Needs to made generic based on the user - return {visibility: "Public Pages", url_tracking:"1", forward_replies:"0", auto_responder:"0", open_tracking:"1", - }; - } - } - } - }); //This route is used for creating new mails and editing the current mails - } - ]); + crmMailing.config(['$routeProvider', + function($routeProvider) { + $routeProvider.when('/mailing', { + templateUrl: partialUrl('mailingList.html'), + controller: 'mailingListCtrl', + resolve: { + mailingList: function($route, crmApi) { + return crmApi('Mailing', 'get', {}); + } + + } + }); //This route is used for generating the list of mails created. + + + + $routeProvider.when('/mailing/:id', { + templateUrl: partialUrl('main.html'), + controller: 'mailingCtrl', + resolve: { + selectedMail: function($route, crmApi) { + if ( $route.current.params.id !== 'new') { + return crmApi('Mailing', 'getsingle', {id: $route.current.params.id}); + } + else { + //created_id has been set to my id. Does not save without created_id. Needs to made generic based on the user + return {visibility: "Public Pages", url_tracking:"1", forward_replies:"0", auto_responder:"0", open_tracking:"1", + }; + } + } + } + }); //This route is used for creating new mails and editing the current mails + } + ]); //----------------------------------------- - + //This controller is used in creating new mail and editing current mails crmMailing.controller('mailingCtrl', function($scope, crmApi, selectedMail, $location,$route, $sce, $window) { - - //Making some dummy api to see if my from email, reply to email works. To see if all options come in select box - $scope.cool_api= [ - {'name': 'rajgo94', - 'from_mail': 'rajgo94@gmail.com', - 'reply_mail': 'rajgo94@gmail.com' }, - {'name': 'rajgo94_2', - 'from_mail': 'rajgo94@gmail_2.com', - 'reply_mail': 'rajgo94@gmail_2.com'}, - {'name': 'rajgo94_3', - 'from_mail': 'rajgo94@gmail_3.com', - 'reply_mail': 'rajgo94@gmail_3.com'} - ]; - //setting variables to the values we have got to the api - $scope.submitted = false; + + //setting variables to the values we have got to the api + $scope.submitted = false; $scope.partialUrl = partialUrl; $scope.campaignList = CRM.crmMailing.campNames; $scope.mailList = CRM.crmMailing.civiMails; @@ -77,10 +65,10 @@ $scope.currentMailing.created_id = $scope.user_id; mltokens = CRM.crmMailing.mailTokens; $scope.pre = false; - // $scope.sendtest = false; - /* $scope.set_sendtest = function(){ - $scope.sendtest = true; - };*/ + // $scope.sendtest = false; + /* $scope.set_sendtest = function(){ + $scope.sendtest = true; + };*/ $scope.noOfRecipients = 0; $scope.testMailing = {}; $scope.testMailing.name = ""; @@ -94,58 +82,59 @@ chck = []; chck2 = []; $scope.mailid = []; - for(var a in $scope.mailingGrp){ - if($scope.mailingGrp[a].mailing_id==$scope.currentMailing.id){ + + for (var a in $scope.mailingGrp) { + if ($scope.mailingGrp[a].mailing_id==$scope.currentMailing.id) { var b = $scope.mailingGrp[a].entity_id + " " + $scope.mailingGrp[a].entity_table +" " + $scope.mailingGrp[a].group_type; var c = $scope.mailingGrp[a].id; chck.push(b); $scope.mailid.push(c); } } - + console.log(chck); - console.log($scope.mailid); - if($scope.currentMailing.msg_template_id!=null){ + console.log($scope.mailid); + if ($scope.currentMailing.msg_template_id!=null) { $scope.tst=$scope.currentMailing.msg_template_id; } console.log($scope.tst); //Making the object for data - - for(var a in chck) - { var b ={} + + for (var a in chck) { + var b ={} b.id = chck[a]; - var splt = chck[a].split(" "); - + var splt = chck[a].split(" "); + if(splt[1] == "civicrm_group"){ - for(var c in $scope.groupNamesList){ - if($scope.groupNamesList[c].id==splt[0]){ - b.text = $scope.groupNamesList[c].title; - } - } + for(var c in $scope.groupNamesList){ + if($scope.groupNamesList[c].id==splt[0]){ + b.text = $scope.groupNamesList[c].title; } + } + } if(splt[1] == "civicrm_mailing"){ - for(var c in $scope.mailList){ - if($scope.mailList[c].id==splt[0]){ - b.text = $scope.mailList[c].name; - } - } + for(var c in $scope.mailList){ + if($scope.mailList[c].id==splt[0]){ + b.text = $scope.mailList[c].name; } + } + } chck2.push(b); } - - console.log(chck2); + + console.log(chck2); $scope.incGroup = chck2; - - + + $scope.mailingForm = function() { if ($scope.mailing_form.$valid) { // Submit as normal - } + } else { $scope.mailing_form.submitted = true; } }; - + $scope.back = function (){ $window.location.href = "#/mailing" ; $route.reload(); @@ -160,66 +149,66 @@ } else{ for(var a in $scope.tmpList){ - + if($scope.tmpList[a].id==$scope.currentMailing.msg_template_id){ $scope.currentMailing.body_html=$scope.tmpList[a].msg_html; console.log($scope.tmpList[a].msg_subject); $scope.currentMailing.subject=$scope.tmpList[a].msg_subject; console.log($scope.currentMailing.subject); - } } - } + } + } }; - //initializing variables we will use for checkboxes, or for purpose of ng-show + //initializing variables we will use for checkboxes, or for purpose of ng-show $scope.acttab=0; $scope.composeS="1"; if($scope.currentMailing.forward_replies==0 && $scope.currentMailing.auto_responder==0){ - $scope.trackreplies="0"; + $scope.trackreplies="0"; } else { - $scope.trackreplies="1"; + $scope.trackreplies="1"; } if($scope.currentMailing.scheduled_date == null || $scope.currentMailing.scheduled_date == "") $scope.now="1"; else $scope.now="0"; - + $scope.reply = function(){ if($scope.trackreplies==0){ - $scope.trackreplies=1; - } + $scope.trackreplies=1; + } else{ - $scope.trackreplies=0; - $scope.currentMailing.forward_replies=0; - $scope.currentMailing.auto_responder=0; - } + $scope.trackreplies=0; + $scope.currentMailing.forward_replies=0; + $scope.currentMailing.auto_responder=0; } - + } + $scope.recclicked = function(){ - if($scope.acttab >=0){ - $scope.acttab =0; - } + if($scope.acttab >=0){ + $scope.acttab =0; + } }; $scope.conclicked = function(){ - if($scope.acttab >=1){ - $scope.acttab =1; - } - }; - + if($scope.acttab >=1){ + $scope.acttab =1; + } + }; + $scope.schedclicked = function(){ - if($scope.acttab >=2){ - $scope.acttab =2; - } - }; - - //to split the value of selectedMail.scheduled_date into the date and time separately + if($scope.acttab >=2){ + $scope.acttab =2; + } + }; + + //to split the value of selectedMail.scheduled_date into the date and time separately $scope.scheddate={}; - $scope.scheddate.date = ""; - $scope.scheddate.time = ""; + $scope.scheddate.date = ""; + $scope.scheddate.time = ""; $scope.ans=""; - + $scope.checkNow = function(){ if($scope.now == 1 ){ $scope.now = 0; @@ -229,129 +218,129 @@ $scope.currentMailing.scheduled_date = null; $scope.currentMailing.scheduled_id = null; console.log($scope.currentMailing.scheduled_date); - $scope.scheddate.date = ""; - $scope.scheddate.time = ""; + $scope.scheddate.date = ""; + $scope.scheddate.time = ""; } } - - // To split the scheduled_date into date and time. The date format is not accepting + + // To split the scheduled_date into date and time. The date format is not accepting if(selectedMail.scheduled_date != null){ - $scope.ans= selectedMail.scheduled_date.split(" "); - $scope.scheddate.date=$scope.ans[0]; - $scope.scheddate.time=$scope.ans[1]; - console.log("scheddate.date is " + $scope.scheddate.date); - console.log("scheddate.time is " + $scope.scheddate.time); - } + $scope.ans= selectedMail.scheduled_date.split(" "); + $scope.scheddate.date=$scope.ans[0]; + $scope.scheddate.time=$scope.ans[1]; + console.log("scheddate.date is " + $scope.scheddate.date); + console.log("scheddate.time is " + $scope.scheddate.time); + } + + console.log(selectedMail); - console.log(selectedMail); - - //changing the screen from compose on screen to upload content + //changing the screen from compose on screen to upload content $scope.upldChange= function(composeS){ if(composeS=="1"){ return true; } - else + else return false; }; - //filter so we only get headers from mailing component + //filter so we only get headers from mailing component $scope.isHeader= function(hf){ return hf.component_type == "Header"; }; - //filter so we only get footers from mailing component + //filter so we only get footers from mailing component $scope.isFooter= function(f){ return f.component_type == "Footer"; }; - //filter so we only get auto-Responders from mailing component + //filter so we only get auto-Responders from mailing component $scope.isAuto= function(au){ return au.component_type == "Reply"; }; - //filter so we only get userDriven message templates + //filter so we only get userDriven message templates $scope.isUserDriven= function(mstemp){ return (parseInt(mstemp.id)>58); - }; - //used for ng-show when trackreplies is selected. Only then we show forward replies and auto-responders options + }; + //used for ng-show when trackreplies is selected. Only then we show forward replies and auto-responders options $scope.trackr= function(trackreplies){ if(trackreplies=="1"){ return true; } - else + else return false; } - + $scope.isGrp= function(grp){ return grp.visibility == "Public Pages"; }; - + $scope.isCompMail= function(ml){ return ml.is_completed == 1; }; - + $scope.upload = function(){ console.log($scope.param.file_1.type); - }; - + }; + $scope.upload_2 = function(){ console.log($scope.param.file_2); - }; - + }; + $scope.upload_3 = function(){ console.log($scope.param.file_3); }; - + $scope.preview_update = function(){ var resulta =crmApi('Mailing','preview',{id:$scope.currentMailing.id}); - resulta.success(function(data) { - if (data.is_error == 0) { - console.log("came"); - console.log(data.values); - $scope.previewbody_html=data.values.html; - $scope.previewbody_text=data.values.text; - $scope.preview_subject=data.values.subject; - console.log($scope.preview_subject); - $scope.pre = true; - $scope.$digest(); - $scope.$apply(); - } - }); - }; - + resulta.success(function(data) { + if (data.is_error == 0) { + console.log("came"); + console.log(data.values); + $scope.previewbody_html=data.values.html; + $scope.previewbody_text=data.values.text; + $scope.preview_subject=data.values.subject; + console.log($scope.preview_subject); + $scope.pre = true; + $scope.$digest(); + $scope.$apply(); + } + }); + }; + $scope.isBody_text = function(){ if($scope.currentMailing.body_text == null || $scope.currentMailing.body_text == "" ) return false; else return true; }; - + $scope.deliberatelyTrustDangerousSnippet = function() { - return $sce.trustAsHtml($scope.previewbody_html); - }; - - $scope.deliberatelyTrustDangerousSnippet2 = function() { - return $sce.trustAsHtml($scope.previewbody_text); - }; - - $scope.deliberatelyTrustDangerousSnippet3 = function() { - return $sce.trustAsHtml($scope.preview_subject); - }; - - $scope.mailing_recipients= function() { + return $sce.trustAsHtml($scope.previewbody_html); + }; + + $scope.deliberatelyTrustDangerousSnippet2 = function() { + return $sce.trustAsHtml($scope.previewbody_text); + }; + + $scope.deliberatelyTrustDangerousSnippet3 = function() { + return $sce.trustAsHtml($scope.preview_subject); + }; + + $scope.mailing_recipients= function() { console.log("the id is " + $scope.currentMailing.id); var resulta =crmApi('MailingRecipients', 'get', {mailing_id: $scope.currentMailing.id, options: {limit:1000}}); - resulta.success(function(data) { - if (data.is_error == 0) { - console.log("Entered Mailing Recipients"); - console.log(data); - $scope.noOfRecipients=data.count; - console.log($scope.noOfRecipients); + resulta.success(function(data) { + if (data.is_error == 0) { + console.log("Entered Mailing Recipients"); + console.log(data); + $scope.noOfRecipients=data.count; + console.log($scope.noOfRecipients); $scope.$digest(); - $scope.$apply(); - } - }); + $scope.$apply(); + } + }); } - + $scope.mailingGroup = function() { var resulta =crmApi('MailingGroup', 'get', {mailing_id: $scope.currentMailing.id, options: {limit:1000}}) - resulta.success(function(data) { + resulta.success(function(data) { console.log("I am awesome " ); console.log(data.values); $scope.mailid = []; @@ -360,98 +349,98 @@ var b = value.entity_id + " " + value.entity_table +" " + value.group_type; var c = value.id; chck.push(b); - $scope.mailid.push(c); + $scope.mailid.push(c); }); console.log(chck); - console.log($scope.mailid); + console.log($scope.mailid); for(var a in chck) { var b ={} b.id = chck[a]; var splt = chck[a].split(" "); - + if(splt[1] == "civicrm_group"){ - for(var c in $scope.groupNamesList){ - if($scope.groupNamesList[c].id==splt[0]){ - b.text = $scope.groupNamesList[c].title; - } - } + for(var c in $scope.groupNamesList){ + if($scope.groupNamesList[c].id==splt[0]){ + b.text = $scope.groupNamesList[c].title; } + } + } if(splt[1] == "civicrm_mailing"){ - for(var c in $scope.mailList){ - if($scope.mailList[c].id==splt[0]){ - b.text = $scope.mailList[c].name; - } - } + for(var c in $scope.mailList){ + if($scope.mailList[c].id==splt[0]){ + b.text = $scope.mailList[c].name; } + } + } chck2.push(b); } - - console.log(chck2); + + console.log(chck2); $scope.incGroup = chck2; $scope.mailing_recipients(); }); - } - + } + $scope.save_next = function() { - console.log($scope.testMailing.name + "THIS IS THE TEST MAILING"); - console.log($scope.testMailing.group + "THIS IS THE TEST MAILING GROUP"); - $scope.incGrp=[]; - $scope.excGrp=[]; - $scope.incMail=[]; - $scope.excMail=[]; - console.log(chck); - $scope.answer=""; - for(req_id in chck){ - $scope.answer = chck[req_id].split(" "); - - if($scope.answer[1] == "civicrm_mailing" && $scope.answer[2]=="include"){ - $scope.incMail.push($scope.answer[0]); - } - else if($scope.answer[1] == "civicrm_mailing" && $scope.answer[2]=="exclude"){ - $scope.excMail.push($scope.answer[0]); - } - if($scope.answer[1] == "civicrm_group" && $scope.answer[2]=="include"){ - $scope.incGrp.push($scope.answer[0]); - } - else if($scope.answer[1] == "civicrm_group" && $scope.answer[2]=="exclude"){ - $scope.excGrp.push($scope.answer[0]); - } + console.log($scope.testMailing.name + "THIS IS THE TEST MAILING"); + console.log($scope.testMailing.group + "THIS IS THE TEST MAILING GROUP"); + $scope.incGrp=[]; + $scope.excGrp=[]; + $scope.incMail=[]; + $scope.excMail=[]; + console.log(chck); + $scope.answer=""; + for(req_id in chck){ + $scope.answer = chck[req_id].split(" "); + + if($scope.answer[1] == "civicrm_mailing" && $scope.answer[2]=="include"){ + $scope.incMail.push($scope.answer[0]); } - - console.log($scope.incMail + " inc mail"); - console.log($scope.excMail + " exc mail"); - console.log($scope.incGrp + " inc group"); - console.log($scope.excGrp + " exc group"); - - - if ($scope.currentMailing.scheduled_date == $scope.currentMailing.approval_date - && $scope.currentMailing.scheduled_date != null) { - console.log("Do Nothing"); + else if($scope.answer[1] == "civicrm_mailing" && $scope.answer[2]=="exclude"){ + $scope.excMail.push($scope.answer[0]); } - else { - $scope.currentMailing.scheduled_date= $scope.scheddate.date + " " + $scope.scheddate.time ; - if ($scope.currentMailing.scheduled_date!=" ") { - $scope.currentMailing.scheduled_id= $scope.user_id; - } - else { - $scope.currentMailing.scheduled_date= null; - } + if($scope.answer[1] == "civicrm_group" && $scope.answer[2]=="include"){ + $scope.incGrp.push($scope.answer[0]); } - console.log($scope.mailid + "coolio") - if ($scope.mailid != null) { - for (var a in $scope.mailid) { - var result_2= crmApi('MailingGroup', 'delete', { - id: $scope.mailid[a] - }); - } + else if($scope.answer[1] == "civicrm_group" && $scope.answer[2]=="exclude"){ + $scope.excGrp.push($scope.answer[0]); + } + } + + console.log($scope.incMail + " inc mail"); + console.log($scope.excMail + " exc mail"); + console.log($scope.incGrp + " inc group"); + console.log($scope.excGrp + " exc group"); + + + if ($scope.currentMailing.scheduled_date == $scope.currentMailing.approval_date + && $scope.currentMailing.scheduled_date != null) { + console.log("Do Nothing"); + } + else { + $scope.currentMailing.scheduled_date= $scope.scheddate.date + " " + $scope.scheddate.time ; + if ($scope.currentMailing.scheduled_date!=" ") { + $scope.currentMailing.scheduled_id= $scope.user_id; + } + else { + $scope.currentMailing.scheduled_date= null; } - - var result = crmApi('Mailing', 'create', { + } + console.log($scope.mailid + "coolio") + if ($scope.mailid != null) { + for (var a in $scope.mailid) { + var result_2= crmApi('MailingGroup', 'delete', { + id: $scope.mailid[a] + }); + } + } + + var result = crmApi('Mailing', 'create', { id: $scope.currentMailing.id, - name: $scope.currentMailing.name, - visibility: $scope.currentMailing.visibility, - created_id: $scope.currentMailing.created_id, - subject: $scope.currentMailing.subject, + name: $scope.currentMailing.name, + visibility: $scope.currentMailing.visibility, + created_id: $scope.currentMailing.created_id, + subject: $scope.currentMailing.subject, msg_template_id: $scope.currentMailing.msg_template_id==null ? "" : $scope.currentMailing.msg_template_id, open_tracking: $scope.currentMailing.open_tracking, url_tracking: $scope.currentMailing.url_tracking, @@ -470,51 +459,51 @@ header_id: $scope.currentMailing.header_id, footer_id: $scope.currentMailing.footer_id, groups: {include: $scope.incGrp, - exclude: $scope.excGrp - }, + exclude: $scope.excGrp + }, mailings: {include: $scope.incMail, - exclude: $scope.excMail - }, + exclude: $scope.excMail + }, is_completed: $scope.currentMailing.is_completed, approver_id: $scope.currentMailing.approver_id, approval_status_id: $scope.currentMailing.approval_status_id, approval_date: $scope.currentMailing.approval_date, - }, - true); - //var result = crmApi('Mailing', 'create', $scope.currentMailing, true); - result.success(function(data) { - if (data.is_error == 0) { - $scope.currentMailing.id = data.id; - console.log("the id is " + $scope.currentMailing.id ); - console.log("OK"); - console.log(data); - $scope.mailingGroup(); - } - console.log("OK2"); - }); - }; - - $scope.save_next_page2 = function() { - if ($scope.currentMailing.scheduled_date == $scope.currentMailing.approval_date - && $scope.currentMailing.scheduled_date != null) { - console.log("Do Nothing"); + }, + true); + //var result = crmApi('Mailing', 'create', $scope.currentMailing, true); + result.success(function(data) { + if (data.is_error == 0) { + $scope.currentMailing.id = data.id; + console.log("the id is " + $scope.currentMailing.id ); + console.log("OK"); + console.log(data); + $scope.mailingGroup(); } - else { - $scope.currentMailing.scheduled_date= $scope.scheddate.date + " " + $scope.scheddate.time ; - if ($scope.currentMailing.scheduled_date!=" ") { - $scope.currentMailing.scheduled_id= $scope.user_id; - } - else { - $scope.currentMailing.scheduled_date= null; - } + console.log("OK2"); + }); + }; + + $scope.save_next_page2 = function() { + if ($scope.currentMailing.scheduled_date == $scope.currentMailing.approval_date + && $scope.currentMailing.scheduled_date != null) { + console.log("Do Nothing"); + } + else { + $scope.currentMailing.scheduled_date= $scope.scheddate.date + " " + $scope.scheddate.time ; + if ($scope.currentMailing.scheduled_date!=" ") { + $scope.currentMailing.scheduled_id= $scope.user_id; + } + else { + $scope.currentMailing.scheduled_date= null; } + } - var result = crmApi('Mailing', 'create', { + var result = crmApi('Mailing', 'create', { id: $scope.currentMailing.id, - name: $scope.currentMailing.name, - visibility: $scope.currentMailing.visibility, - created_id: $scope.currentMailing.created_id, - subject: $scope.currentMailing.subject, + name: $scope.currentMailing.name, + visibility: $scope.currentMailing.visibility, + created_id: $scope.currentMailing.created_id, + subject: $scope.currentMailing.subject, msg_template_id: $scope.currentMailing.msg_template_id==null ? "" : $scope.currentMailing.msg_template_id, open_tracking: $scope.currentMailing.open_tracking, url_tracking: $scope.currentMailing.url_tracking, @@ -536,97 +525,97 @@ approver_id: $scope.currentMailing.approver_id, approval_status_id: $scope.currentMailing.approval_status_id, approval_date: $scope.currentMailing.approval_date, - }, - true); - //var result = crmApi('Mailing', 'create', $scope.currentMailing, true); - result.success(function(data) { - if (data.is_error == 0) { - $scope.currentMailing.id = data.id; - console.log("the id is " + $scope.currentMailing.id ); - console.log("OK"); - console.log(data); - } - console.log("OK2"); - }); - }; - - - $scope.save = function() { - $scope.save_next_page2(); - $scope.back(); - }; - - $scope.save_page1 = function() { - $scope.save_next_page1(); - $scope.back(); - }; - - $scope.save_next_page1 = function() { - if($scope.currentMailing.id == null){ - $scope.currentMailing.subject = $scope.currentMailing.name; - $scope.save_next(); - } - else { - $scope.save_next(); + }, + true); + //var result = crmApi('Mailing', 'create', $scope.currentMailing, true); + result.success(function(data) { + if (data.is_error == 0) { + $scope.currentMailing.id = data.id; + console.log("the id is " + $scope.currentMailing.id ); + console.log("OK"); + console.log(data); } - - }; - - $scope.submitButton= function(){ - $scope.currentMailing.approval_status_id = "1"; - $scope.currentMailing.approver_id = $scope.user_id; - var currentdate = new Date(); - var yyyy = currentdate.getFullYear(); - var mm = currentdate.getMonth() + 1; - mm = mm<10 ? '0' + mm : mm; - var dd = currentdate.getDate(); - dd = dd<10 ? '0' + dd : dd; - var hh = currentdate.getHours(); - hh = hh<10 ? '0' + hh : hh; - var min = currentdate.getMinutes(); - min = min<10 ? '0' + min : min; - var sec = currentdate.getSeconds(); - sec = sec<10 ? '0' + sec : sec; - $scope.currentMailing.approval_date = yyyy + "/"+ mm - + "/" + dd + " " - + hh + ":" + console.log("OK2"); + }); + }; + + + $scope.save = function() { + $scope.save_next_page2(); + $scope.back(); + }; + + $scope.save_page1 = function() { + $scope.save_next_page1(); + $scope.back(); + }; + + $scope.save_next_page1 = function() { + if($scope.currentMailing.id == null){ + $scope.currentMailing.subject = $scope.currentMailing.name; + $scope.save_next(); + } + else { + $scope.save_next(); + } + + }; + + $scope.submitButton= function(){ + $scope.currentMailing.approval_status_id = "1"; + $scope.currentMailing.approver_id = $scope.user_id; + var currentdate = new Date(); + var yyyy = currentdate.getFullYear(); + var mm = currentdate.getMonth() + 1; + mm = mm<10 ? '0' + mm : mm; + var dd = currentdate.getDate(); + dd = dd<10 ? '0' + dd : dd; + var hh = currentdate.getHours(); + hh = hh<10 ? '0' + hh : hh; + var min = currentdate.getMinutes(); + min = min<10 ? '0' + min : min; + var sec = currentdate.getSeconds(); + sec = sec<10 ? '0' + sec : sec; + $scope.currentMailing.approval_date = yyyy + "/"+ mm + + "/" + dd + " " + + hh + ":" + min + ":" + sec; - console.log($scope.now + "sched immediately"); - if($scope.now == 1){ - $scope.currentMailing.scheduled_date = $scope.currentMailing.approval_date; - } - console.log($scope.currentMailing.approval_date); - $scope.save(); - }; - - $scope.$watch('pre',function(){ + console.log($scope.now + "sched immediately"); + if($scope.now == 1){ + $scope.currentMailing.scheduled_date = $scope.currentMailing.approval_date; + } + console.log($scope.currentMailing.approval_date); + $scope.save(); + }; + + $scope.$watch('pre',function(){ console.log("dsfdfsfds"); - if($scope.pre==true){ - $('#prevmail').dialog({ - title: 'Preview Mailing', - width: 1080, - height: 800, - closed: false, - cache: false, - modal: true, - close :function(){console.log("close"); - $scope.pre = false; $scope.$apply();} - }); - } - },true); + if($scope.pre==true){ + $('#prevmail').dialog({ + title: 'Preview Mailing', + width: 1080, + height: 800, + closed: false, + cache: false, + modal: true, + close :function(){console.log("close"); + $scope.pre = false; $scope.$apply();} + }); + } + },true); $scope.sendTest = function(){ - console.log("Opened send Test"); + console.log("Opened send Test"); - var resulta =crmApi('Mailing','send_test',{test_email:$scope.testMailing.name, test_group:$scope.testMailing.group, - mailing_id:$scope.currentMailing.id}); - resulta.success(function(data) { - console.log("worked"); - }); - console.log("didnt work"); + var resulta =crmApi('Mailing','send_test',{test_email:$scope.testMailing.name, test_group:$scope.testMailing.group, + mailing_id:$scope.currentMailing.id}); + resulta.success(function(data) { + console.log("worked"); + }); + console.log("didnt work"); }; }); - + // Directive to go to the next tab crmMailing.directive('nexttab', function() { @@ -638,12 +627,12 @@ $(element).parent().parent().tabs({disabled:myarr}); $(element).on("click",function() { scope.acttab=scope.acttab +1; - var myArray1 = new Array( ); - for ( var i = 0; i < 3; i++ ) { + var myArray1 = new Array( ); + for ( var i = 0; i < 3; i++ ) { if(scope.acttab!=i) - myArray1.push(i); - } - $(element).parent().parent().tabs( "option", "disabled", myArray1 ); + myArray1.push(i); + } + $(element).parent().parent().tabs( "option", "disabled", myArray1 ); $(element).parent().parent().tabs({active:scope.acttab}); console.log("sid"); }); @@ -661,84 +650,84 @@ $(element).parent().parent().tabs({disabled:myarr}); $(element).on("click",function() { scope.acttab=scope.acttab -1; - var myArray1 = new Array( ); - for ( var i = 0; i < 3; i++ ) { + var myArray1 = new Array( ); + for ( var i = 0; i < 3; i++ ) { if(scope.acttab!=i) - myArray1.push(i); - } - $(element).parent().parent().tabs( "option", "disabled", myArray1 ); + myArray1.push(i); + } + $(element).parent().parent().tabs( "option", "disabled", myArray1 ); $(element).parent().parent().tabs({active:scope.acttab}); console.log("sid"); }); } }; - }); + }); // Select 2 Widget for selecting the included group crmMailing.directive('chsgroup',function(){ - return { + return { restrict : 'AE', link: function(scope,element, attrs){ - function format(item) { - if(!item.id) { - // return `text` for optgroup - return item.text; - } - // return item template - var a = item.id.split(" "); - if(a[1]=="civicrm_group" && a[2]=="include") + function format(item) { + if(!item.id) { + // return `text` for optgroup + return item.text; + } + // return item template + var a = item.id.split(" "); + if(a[1]=="civicrm_group" && a[2]=="include") return "" + " " + "" + item.text; - if(a[1]=="civicrm_group" && a[2]=="exclude") + if(a[1]=="civicrm_group" && a[2]=="exclude") return "" + " " + "" + item.text; if(a[1]=="civicrm_mailing" && a[2]=="include") return "" + " " + "" + item.text; if(a[1]=="civicrm_mailing" && a[2]=="exclude") return "" + " " + "" + item.text; - } - - $(element).select2({ - width:"400px", - placeholder: "Choose Recipients", - formatResult: format, - formatSelection: format, - escapeMarkup: function(m) { return m; }, + } + + $(element).select2({ + width:"400px", + placeholder: "Choose Recipients", + formatResult: format, + formatSelection: format, + escapeMarkup: function(m) { return m; }, }).select2("data", scope.incGroup); $(element).on("select2-opening", function() - { scope.incGroup=chck; - console.log(scope.incGroup); - scope.$apply(); - - }); - - $(element).on('select2-selecting', function(e) { + { scope.incGroup=chck; + console.log(scope.incGroup); + scope.$apply(); + + }); + + $(element).on('select2-selecting', function(e) { chck.push(e.val); - scope.incGroup=chck; - scope.$apply(); - console.log(scope.incGroup); + scope.incGroup=chck; + scope.$apply(); + console.log(scope.incGroup); + + }); - }); - - $(element).on("select2-removed", function(e) { - var index = chck.indexOf(e.val); - chck.splice(index, 1); - scope.incGroup=chck; - console.log(scope.incGroup); - scope.$apply(); - }); + $(element).on("select2-removed", function(e) { + var index = chck.indexOf(e.val); + chck.splice(index, 1); + scope.incGroup=chck; + console.log(scope.incGroup); + scope.$apply(); + }); } }; - }); - + }); + crmMailing.directive('groupselect',function(){ return { restrict : 'AE', link: function(scope,element, attrs){ $(element).select2({width:"200px", data: mltokens, placeholder:"Insert Token"}); $(element).on('select2-selecting', function(e) { - + scope.$evalAsync('_resetSelection()');console.log(mltokens); var a = $(element).attr('id'); if(a=="htgroup"){ @@ -753,10 +742,10 @@ var cursorPos = (cursorlen + e.val.length); document.getElementById("body_html").selectionStart = cursorPos; document.getElementById("body_html").selectionEnd = cursorPos; - document.getElementById("body_html").focus(); + document.getElementById("body_html").focus(); } else if(a=="subgroup"){ - var msg = document.getElementById("sub").value; + var msg = document.getElementById("sub").value; var cursorlen = document.getElementById("sub").selectionStart; console.log(cursorlen); var textlen = msg.length; @@ -767,29 +756,29 @@ var cursorPos = (cursorlen + e.val.length); document.getElementById("sub").selectionStart = cursorPos; document.getElementById("sub").selectionEnd = cursorPos; - document.getElementById("sub").focus(); - } + document.getElementById("sub").focus(); + } else if(a=="textgroup"){ - var msg = document.getElementById("body_text").value; - var cursorlen = document.getElementById("body_text").selectionStart; - console.log(cursorlen); - var textlen = msg.length; - document.getElementById("body_text").value = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); - scope.currentMailing.body_text = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); - console.log(document.getElementById("body_text").value); - console.log(scope.currentMailing.body_text); - var cursorPos = (cursorlen + e.val.length); - document.getElementById("body_text").selectionStart = cursorPos; - document.getElementById("body_text").selectionEnd = cursorPos; - document.getElementById("body_text").focus(); - } + var msg = document.getElementById("body_text").value; + var cursorlen = document.getElementById("body_text").selectionStart; + console.log(cursorlen); + var textlen = msg.length; + document.getElementById("body_text").value = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); + scope.currentMailing.body_text = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); + console.log(document.getElementById("body_text").value); + console.log(scope.currentMailing.body_text); + var cursorPos = (cursorlen + e.val.length); + document.getElementById("body_text").selectionStart = cursorPos; + document.getElementById("body_text").selectionEnd = cursorPos; + document.getElementById("body_text").focus(); + } scope.$apply(); e.preventDefault(); }) } }; }); - + // Used for the select date option. This is used for giving scheduled_date its date value @@ -797,69 +786,69 @@ return { restrict: 'AE', link: function(scope,element,attrs){ - $(element).datepicker({ - dateFormat: "yy-mm-dd", - onSelect: function(date) { - $(".ui-datepicker a").removeAttr("href"); - scope.scheddate.date=date.toString(); - scope.$apply(); - console.log(scope.scheddate.date); - } + $(element).datepicker({ + dateFormat: "yy-mm-dd", + onSelect: function(date) { + $(".ui-datepicker a").removeAttr("href"); + scope.scheddate.date=date.toString(); + scope.$apply(); + console.log(scope.scheddate.date); + } }); } }; }); crmMailing.directive('file', function(){ - return { - scope: { - file: '=' - }, - link: function(scope, el, attrs){ - el.bind('change', function(event){ - var files = event.target.files; - console.log(event); - var file = files[0]; - scope.file = file ? file : undefined; - scope.$apply(); - }); - } - }; + return { + scope: { + file: '=' + }, + link: function(scope, el, attrs){ + el.bind('change', function(event){ + var files = event.target.files; + console.log(event); + var file = files[0]; + scope.file = file ? file : undefined; + scope.$apply(); + }); + } + }; }); - //This controller is used for creating the mailing list. Simply gets all the mailing data from civiAPI + //This controller is used for creating the mailing list. Simply gets all the mailing data from civiAPI crmMailing.controller('mailingListCtrl', function($scope, crmApi, mailingList, $route) { - if (global == 0) { + if (global == 0) { global = global + 1; $route.reload(); } $scope.mailingList = mailingList.values; - $scope.deleteMail = function (mail) { - crmApi('Mailing', 'delete', {id: mail.id}, { - error: function (data) { - CRM.alert(data.error_message, ts('Error')); - } - }) - .then(function (data) { - if (!data.is_error) { + $scope.deleteMail = function (mail) { + crmApi('Mailing', 'delete', {id: mail.id}, { + error: function (data) { + CRM.alert(data.error_message, ts('Error')); + } + }) + .then(function (data) { + if (!data.is_error) { console.log(mailingList.values); - console.log(mailingList.values[mail.id]); - delete mailingList.values[mail.id]; - $scope.$digest(); - $route.reload(); - } - }); - - }; - - $scope.edit = function (){ + console.log(mailingList.values[mail.id]); + delete mailingList.values[mail.id]; + $scope.$digest(); + $route.reload(); + } + }); + + }; + + $scope.edit = function (){ global = global - 1; }; - + }); })(angular, CRM.$, CRM._); /* example of params [attachFile_1] => Array ( [uri] => /var/www/siddhant/drupal-7.27/sites/default/files/civicrm/custom/blog_2_odt_2c622a7b5e32415a92e81ed97d6554c7.unknown [type] => application/vnd.oasis.opendocument.text [location] => /var/www/siddhant/drupal-7.27/sites/default/files/civicrm/custom/blog_2_odt_2c622a7b5e32415a92e81ed97d6554c7.unknown [description] => dasdas [upload_date] => 20140706105804 [tag] => Array ( ) [attachment_taglist] => Array ( ) ) -*/ + */ diff --git a/partials/crmMailingType/attachments.html b/partials/crmMailingType/attachments.html index b652dcd731..85b7d47d39 100644 --- a/partials/crmMailingType/attachments.html +++ b/partials/crmMailingType/attachments.html @@ -1,35 +1,35 @@ - - - +
Attach Files
+ + - - - + + + - - - + + + - - -
Attach Files - + - +
Attach Files
Attach Files - + - +
Attach Files
Attach Files - + - +
+ + + diff --git a/partials/crmMailingType/composeonScreen.html b/partials/crmMailingType/composeonScreen.html index 7953733ac0..a6b38a34e3 100644 --- a/partials/crmMailingType/composeonScreen.html +++ b/partials/crmMailingType/composeonScreen.html @@ -1,17 +1,17 @@
- - + +
-   Save Template -
+   Save Template +
diff --git a/partials/crmMailingType/content.html b/partials/crmMailingType/content.html index 389e332c3c..60e6d09403 100644 --- a/partials/crmMailingType/content.html +++ b/partials/crmMailingType/content.html @@ -5,57 +5,57 @@ Required Variables: cool_api and currentMailing and eMailing
- - - - + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + - - + + + - - - - - -
From E-mail Address -
From E-mail Address + -
Reply to E-mail Address - -
Mailing Subject - -
- Mailing subject required.
Mailing Subject Token +
Reply to E-mail Address + +
Mailing Subject + +
+ Mailing subject required. +
Mailing Subject Token -
Use Template -
Use Template + -
I want to Compose on screenUpload Content
+ + Upload Content + + + +

- - - +
Mailing Header
+ + - - - + + + - -
Mailing Header -
Mailing Footer
Mailing Footer -
+ + diff --git a/partials/crmMailingType/ht.html b/partials/crmMailingType/ht.html index a4413744e5..86b0e02736 100644 --- a/partials/crmMailingType/ht.html +++ b/partials/crmMailingType/ht.html @@ -8,7 +8,7 @@

        - +

diff --git a/partials/crmMailingType/mailingList.html b/partials/crmMailingType/mailingList.html index 71506e3cbe..3830127e8e 100644 --- a/partials/crmMailingType/mailingList.html +++ b/partials/crmMailingType/mailingList.html @@ -3,35 +3,35 @@ Controller: mailingListCtrl Required vars: mailingList -->
- All partially completed and completed mail are listed here + All partially completed and completed mail are listed here
- - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + +
Mailing NameCreated ByCreated DateSent ByScheduled
{{mail.name}}{{mail.from_email}}{{mail.created_date}}{{mail.from_email}}{{mail.scheduled_date}}Edit - Delete
Mailing NameCreated ByCreated DateSent ByScheduled
{{mail.name}}{{mail.from_email}}{{mail.created_date}}{{mail.from_email}}{{mail.scheduled_date}}Edit + Delete
diff --git a/partials/crmMailingType/main.html b/partials/crmMailingType/main.html index ce73a15591..346d6df8d1 100644 --- a/partials/crmMailingType/main.html +++ b/partials/crmMailingType/main.html @@ -2,49 +2,49 @@ Controller: MailCtrl Submit Mailing is not functional yet --> -
-
- +
+ -
-
- - - -

-
- -
-
-
- - - - -

-
- -
-
-
- - - - +
+
+ + + +

+
+ +
+
+
+ + + +

-
-
+
+ +
+
+
+ + + + +

+
+
- diff --git a/partials/crmMailingType/plainText.html b/partials/crmMailingType/plainText.html index bb1ccd7be6..537828d681 100644 --- a/partials/crmMailingType/plainText.html +++ b/partials/crmMailingType/plainText.html @@ -10,5 +10,5 @@ Required vars: currentMailing

        - +

diff --git a/partials/crmMailingType/previewMailing.html b/partials/crmMailingType/previewMailing.html index b044b29d97..7b1d265c49 100644 --- a/partials/crmMailingType/previewMailing.html +++ b/partials/crmMailingType/previewMailing.html @@ -5,13 +5,13 @@ The editor has to be added. Currently just a simple text editor -->

diff --git a/partials/crmMailingType/preview_ht.html b/partials/crmMailingType/preview_ht.html index 55c0c70805..0e005c50a1 100644 --- a/partials/crmMailingType/preview_ht.html +++ b/partials/crmMailingType/preview_ht.html @@ -6,16 +6,16 @@ The editor has to be added. Currently just a simple text editor
- - - - + + + + - - - - - + + + + +
Subject:
Subject:
Html:
Html:

- - - - + + + + - - - - - + + + + +
Subject:
Subject:
PlainText:
PlainText:
diff --git a/partials/crmMailingType/recipient.html b/partials/crmMailingType/recipient.html index f7ec651eb7..f9d705a1dc 100644 --- a/partials/crmMailingType/recipient.html +++ b/partials/crmMailingType/recipient.html @@ -6,39 +6,39 @@ Remove duplicates not functional
- - - - - - - + + + - - - - - - - - - + + + + + + + + + + + +
Name your Mailing * - -
- Your name is required. +
Name your Mailing * +
Campaign - -
Remove Duplicates? - -
+ Your name is required. +
Campaign + +
Remove Duplicates? + +
-
- +
+
-
Mailing Recipients
-
+
Mailing Recipients
+
diff --git a/partials/crmMailingType/sched.html b/partials/crmMailingType/sched.html index 9d4f11f7ff..93be2eee30 100644 --- a/partials/crmMailingType/sched.html +++ b/partials/crmMailingType/sched.html @@ -5,32 +5,32 @@ Required vars: currentMailing
- - - - - + + + + + - - - - - + + + - + + + - +
Send Immediately - -
Send Immediately + +
OR
Schedule Mailing - - Time
Schedule Mailing - +
Time + +
Enter the time in the 12:32:45 format where 12 is the hour, 32 the minutes and 45 the seconds.
-
+
diff --git a/partials/crmMailingType/send.html b/partials/crmMailingType/send.html index 8d7c899ba7..76b8e33ca5 100644 --- a/partials/crmMailingType/send.html +++ b/partials/crmMailingType/send.html @@ -4,36 +4,36 @@ Controller: MailCtrl

Preview

-
- -
+
+ +
+
+
+
+
-
-
-
-
- + - +--> + diff --git a/partials/crmMailingType/test.html b/partials/crmMailingType/test.html index e4f1f33e30..6c3a5e136b 100644 --- a/partials/crmMailingType/test.html +++ b/partials/crmMailingType/test.html @@ -4,28 +4,28 @@ Required vars: groupNamesList --> - - - - - - - - + + + + + + + - - - - - - + + + + + + +
Send to address - -
Send to this Group -
Send to address + +
Send to this Group + -
- -
+ +
diff --git a/partials/crmMailingType/trackandRespond.html b/partials/crmMailingType/trackandRespond.html index d6e2b3655b..7de7c61177 100644 --- a/partials/crmMailingType/trackandRespond.html +++ b/partials/crmMailingType/trackandRespond.html @@ -4,97 +4,97 @@ Required vars: currentMailing --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + +
-

Tracking

-
-   Track Click Throughs -
-
- Track the number of times recipients click each link in this mailing. NOTE: When this feature is enabled, all links in the message body will be automaticallly re-written to route through your CiviCRM server prior to redirecting to the target page. -
-
-   Track Opens -
-
- Track the number of times recipients open this mailing in their email software. -
-
-

Responding

-
-   Track Replies -
-
- Recipients' replies are sent to a CiviMail specific address instead of the sender's address so they can be stored within CiviCRM. -
-
-   Forward Replies -
-
- If a recipient replies to this mailing, forward the reply to the FROM Email address specified for the mailing. -
-
-   Auto-Respond to Replies     +
+

Tracking

+
+   Track Click Throughs +
+
+ Track the number of times recipients click each link in this mailing. NOTE: When this feature is enabled, all links in the message body will be automaticallly re-written to route through your CiviCRM server prior to redirecting to the target page. +
+
+   Track Opens +
+
+ Track the number of times recipients open this mailing in their email software. +
+
+

Responding

+
+   Track Replies +
+
+ Recipients' replies are sent to a CiviMail specific address instead of the sender's address so they can be stored within CiviCRM. +
+
+   Forward Replies +
+
+ If a recipient replies to this mailing, forward the reply to the FROM Email address specified for the mailing. +
+
+   Auto-Respond to Replies     -
-
- If a recipient replies to this mailing, send an automated reply using the selected message. -
-
-

Online Publication

-
+
+ If a recipient replies to this mailing, send an automated reply using the selected message. +
+
+

Online Publication

+
- - - - + + + +
Mailing Visibility - -
Mailing Visibility + +
diff --git a/partials/crmMailingType/uploadContent.html b/partials/crmMailingType/uploadContent.html index 3f77bc933a..0f50aeb231 100644 --- a/partials/crmMailingType/uploadContent.html +++ b/partials/crmMailingType/uploadContent.html @@ -1,17 +1,17 @@ - - - +
Upload TEXT Message
+ + - - - + + + - -
Upload TEXT Message - +
Upload HTML Message
Upload HTML Message - +
+ + -- 2.25.1