From 7811a84b72ab1b4f7d99b2ae31a502a8c36935eb Mon Sep 17 00:00:00 2001 From: aditya-nambiar Date: Sat, 9 Aug 2014 19:11:48 +0530 Subject: [PATCH] Major changes --- CRM/Mailing/Event/BAO/Bounce.php | 9 +- CRM/Mailing/Event/BAO/Delivered.php | 8 +- CRM/Mailing/Event/BAO/Opened.php | 8 +- CRM/Mailing/Event/BAO/TrackableURLOpen.php | 7 +- CRM/Mailing/Event/BAO/Unsubscribe.php | 7 +- api/v3/Mailing.php | 232 +++-- api/v3/MailingAB.php | 72 ++ css/angular-crmMailingAB.css | 2 + js/angular-crmMailingAB.js | 971 ++++++++------------ partials/abtesting/attachments.html | 0 partials/abtesting/composeonScreen.html | 0 partials/abtesting/from_name.html | 288 ++---- partials/abtesting/headerandFooter.html | 25 - partials/abtesting/headerfooter.html | 29 + partials/abtesting/list.html | 0 partials/abtesting/main.html | 46 +- partials/abtesting/modal.html | 0 partials/abtesting/next.html | 0 partials/abtesting/report.html | 0 partials/abtesting/subject_lines.html | 168 +--- partials/abtesting/tab1.html | 38 +- partials/abtesting/tab2.html | 25 +- partials/abtesting/tab3.html | 62 +- partials/abtesting/tab4.html | 147 ++- partials/abtesting/trackandRespond.html | 0 partials/abtesting/two_emails.html | 595 ++++-------- partials/abtesting/uploadContent.html | 0 tests/phpunit/CiviTest/CiviUnitTestCase.php | 12 +- tests/phpunit/api/v3/MailingABTest.php | 10 +- tests/phpunit/api/v3/MailingTest.php | 27 +- 30 files changed, 1110 insertions(+), 1678 deletions(-) mode change 100644 => 100755 CRM/Mailing/Event/BAO/Bounce.php mode change 100644 => 100755 CRM/Mailing/Event/BAO/Delivered.php mode change 100644 => 100755 CRM/Mailing/Event/BAO/Opened.php mode change 100644 => 100755 CRM/Mailing/Event/BAO/TrackableURLOpen.php mode change 100644 => 100755 CRM/Mailing/Event/BAO/Unsubscribe.php mode change 100644 => 100755 api/v3/Mailing.php mode change 100644 => 100755 api/v3/MailingAB.php mode change 100644 => 100755 js/angular-crmMailingAB.js mode change 100644 => 100755 partials/abtesting/attachments.html mode change 100644 => 100755 partials/abtesting/composeonScreen.html mode change 100644 => 100755 partials/abtesting/from_name.html delete mode 100644 partials/abtesting/headerandFooter.html create mode 100755 partials/abtesting/headerfooter.html mode change 100644 => 100755 partials/abtesting/list.html mode change 100644 => 100755 partials/abtesting/main.html mode change 100644 => 100755 partials/abtesting/modal.html mode change 100644 => 100755 partials/abtesting/next.html mode change 100644 => 100755 partials/abtesting/report.html mode change 100644 => 100755 partials/abtesting/subject_lines.html mode change 100644 => 100755 partials/abtesting/tab1.html mode change 100644 => 100755 partials/abtesting/tab2.html mode change 100644 => 100755 partials/abtesting/tab3.html mode change 100644 => 100755 partials/abtesting/tab4.html mode change 100644 => 100755 partials/abtesting/trackandRespond.html mode change 100644 => 100755 partials/abtesting/two_emails.html mode change 100644 => 100755 partials/abtesting/uploadContent.html mode change 100644 => 100755 tests/phpunit/CiviTest/CiviUnitTestCase.php mode change 100644 => 100755 tests/phpunit/api/v3/MailingABTest.php mode change 100644 => 100755 tests/phpunit/api/v3/MailingTest.php diff --git a/CRM/Mailing/Event/BAO/Bounce.php b/CRM/Mailing/Event/BAO/Bounce.php old mode 100644 new mode 100755 index c6f38080af..130acf8e3c --- a/CRM/Mailing/Event/BAO/Bounce.php +++ b/CRM/Mailing/Event/BAO/Bounce.php @@ -129,9 +129,7 @@ class CRM_Mailing_Event_BAO_Bounce extends CRM_Mailing_Event_DAO_Bounce { * @access public * @static */ - public static function getTotalCount($mailing_id, $job_id = NULL, - $is_distinct = FALSE - ) { + public static function getTotalCount($mailing_id, $job_id = NULL, $is_distinct = FALSE, $toDate = NULL) { $dao = new CRM_Core_DAO(); $bounce = self::getTableName(); @@ -150,6 +148,10 @@ class CRM_Mailing_Event_BAO_Bounce extends CRM_Mailing_Event_DAO_Bounce { ON $job.mailing_id = $mailing.id WHERE $mailing.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer'); + if (!empty($toDate)) { + $query .= " AND $bounce.time_stamp <= $toDate"; + } + if (!empty($job_id)) { $query .= " AND $job.id = " . CRM_Utils_Type::escape($job_id, 'Integer'); } @@ -266,4 +268,3 @@ class CRM_Mailing_Event_BAO_Bounce extends CRM_Mailing_Event_DAO_Bounce { return $results; } } - diff --git a/CRM/Mailing/Event/BAO/Delivered.php b/CRM/Mailing/Event/BAO/Delivered.php old mode 100644 new mode 100755 index 86ea913fc8..7c424102ab --- a/CRM/Mailing/Event/BAO/Delivered.php +++ b/CRM/Mailing/Event/BAO/Delivered.php @@ -92,7 +92,7 @@ class CRM_Mailing_Event_BAO_Delivered extends CRM_Mailing_Event_DAO_Delivered { * @access public * @static */ - public static function getTotalCount($mailing_id, $job_id = NULL, $is_distinct = FALSE) { + public static function getTotalCount($mailing_id, $job_id = NULL, $is_distinct = FALSE, $toDate = NULL) { $dao = new CRM_Core_DAO(); $delivered = self::getTableName(); @@ -116,6 +116,10 @@ class CRM_Mailing_Event_BAO_Delivered extends CRM_Mailing_Event_DAO_Delivered { WHERE $bounce.id IS null AND $mailing.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer'); + if (!empty($toDate)) { + $query .= " AND $delivered.time_stamp <= $toDate"; + } + if (!empty($job_id)) { $query .= " AND $job.id = " . CRM_Utils_Type::escape($job_id, 'Integer'); } @@ -149,7 +153,7 @@ class CRM_Mailing_Event_BAO_Delivered extends CRM_Mailing_Event_DAO_Delivered { * @static */ public static function &getRows($mailing_id, $job_id = NULL, - $is_distinct = FALSE, $offset = NULL, $rowCount = NULL, $sort = NULL, $is_test = 0 + $is_distinct = FALSE, $offset = NULL, $rowCount = NULL, $sort = NULL, $is_test = FALSE ) { $dao = new CRM_Core_Dao(); diff --git a/CRM/Mailing/Event/BAO/Opened.php b/CRM/Mailing/Event/BAO/Opened.php old mode 100644 new mode 100755 index 57c94d7a3f..b79a25bd7f --- a/CRM/Mailing/Event/BAO/Opened.php +++ b/CRM/Mailing/Event/BAO/Opened.php @@ -81,7 +81,8 @@ class CRM_Mailing_Event_BAO_Opened extends CRM_Mailing_Event_DAO_Opened { */ public static function getTotalCount($mailing_id, $job_id = NULL, - $is_distinct = FALSE + $is_distinct = FALSE, + $toDate = NULL ) { $dao = new CRM_Core_DAO(); @@ -102,6 +103,10 @@ class CRM_Mailing_Event_BAO_Opened extends CRM_Mailing_Event_DAO_Opened { AND $job.is_test = 0 WHERE $mailing.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer'); + if (!empty($toDate)) { + $query .= " AND $open.time_stamp <= $toDate"; + } + if (!empty($job_id)) { $query .= " AND $job.id = " . CRM_Utils_Type::escape($job_id, 'Integer'); } @@ -297,4 +302,3 @@ class CRM_Mailing_Event_BAO_Opened extends CRM_Mailing_Event_DAO_Opened { return $results; } } - diff --git a/CRM/Mailing/Event/BAO/TrackableURLOpen.php b/CRM/Mailing/Event/BAO/TrackableURLOpen.php old mode 100644 new mode 100755 index 3cc24d70cb..22cad88e73 --- a/CRM/Mailing/Event/BAO/TrackableURLOpen.php +++ b/CRM/Mailing/Event/BAO/TrackableURLOpen.php @@ -108,7 +108,7 @@ class CRM_Mailing_Event_BAO_TrackableURLOpen extends CRM_Mailing_Event_DAO_Track * @static */ public static function getTotalCount($mailing_id, $job_id = NULL, - $is_distinct = FALSE, $url_id = NULL + $is_distinct = FALSE, $url_id = NULL, $toDate = NULL ) { $dao = new CRM_Core_DAO(); @@ -129,6 +129,10 @@ class CRM_Mailing_Event_BAO_TrackableURLOpen extends CRM_Mailing_Event_DAO_Track AND $job.is_test = 0 WHERE $mailing.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer'); + if (!empty($toDate)) { + $query .= " AND $click.time_stamp <= $toDate"; + } + if (!empty($job_id)) { $query .= " AND $job.id = " . CRM_Utils_Type::escape($job_id, 'Integer'); } @@ -338,4 +342,3 @@ class CRM_Mailing_Event_BAO_TrackableURLOpen extends CRM_Mailing_Event_DAO_Track return $results; } } - diff --git a/CRM/Mailing/Event/BAO/Unsubscribe.php b/CRM/Mailing/Event/BAO/Unsubscribe.php old mode 100644 new mode 100755 index 75724efbc2..0e478c9250 --- a/CRM/Mailing/Event/BAO/Unsubscribe.php +++ b/CRM/Mailing/Event/BAO/Unsubscribe.php @@ -418,7 +418,7 @@ WHERE email = %2 * @static */ public static function getTotalCount($mailing_id, $job_id = NULL, - $is_distinct = FALSE, $org_unsubscribe = NULL + $is_distinct = FALSE, $org_unsubscribe = NULL, $toDate = NULL ) { $dao = new CRM_Core_DAO(); @@ -442,6 +442,10 @@ WHERE email = %2 AND $job.is_test = 0 WHERE $mailing.id = " . CRM_Utils_Type::escape($mailing_id, 'Integer'); + if (!empty($toDate)) { + $query .= " AND $unsub.time_stamp <= $toDate"; + } + if (!empty($job_id)) { $query .= " AND $job.id = " . CRM_Utils_Type::escape($job_id, 'Integer'); } @@ -595,4 +599,3 @@ SELECT DISTINCT(civicrm_mailing_event_queue.contact_id) as contact_id, return array($displayName, $email); } } - diff --git a/api/v3/Mailing.php b/api/v3/Mailing.php old mode 100644 new mode 100755 index dfcb41cabb..c550d04c95 --- a/api/v3/Mailing.php +++ b/api/v3/Mailing.php @@ -68,79 +68,6 @@ function _civicrm_api3_mailing_create_spec(&$params) { $params['api.mailing_job.create']['api.default'] = 1; } - - - -function civicrm_api3_mailing_stats($params) { - civicrm_api3_verify_mandatory($params, - 'CRM_Mailing_DAO_MailingJob', - array('mailing_id'), - FALSE - ); - $stats[$params['mailing_id']] = array(); - if (empty($params['job_id'])) { - $params['job_id'] = NULL; - } - foreach (array('Delivered', 'Bounces', 'Unsubscribers', 'Unique Clicks', 'Opened') as $detail) { - switch ($detail) { - case 'Delivered': - $stats[$params['mailing_id']] += array( - $detail => CRM_Mailing_Event_BAO_Delivered::getTotalCount($params['mailing_id'], $params['job_id']) - ); - break; - case 'Bounces': - $stats[$params['mailing_id']] += array( - $detail => CRM_Mailing_Event_BAO_Bounce::getTotalCount($params['mailing_id'], $params['job_id']) - ); - break; - case 'Unsubscribers': - $stats[$params['mailing_id']] += array( - $detail => CRM_Mailing_Event_BAO_Unsubscribe::getTotalCount($params['mailing_id'], $params['job_id']) - ); - break; - case 'Unique Clicks': - $stats[$params['mailing_id']] += array( - $detail => CRM_Mailing_Event_BAO_TrackableURLOpen::getTotalCount($params['mailing_id'], $params['job_id']) - ); - break; - case 'Opened': - $stats[$params['mailing_id']] += array( - $detail => CRM_Mailing_Event_BAO_Opened::getTotalCount($params['mailing_id'], $params['job_id']) - ); - break; - } - } - return civicrm_api3_create_success($stats); -} - - - -function civicrm_api3_mailing_a_b_recipients_update($params) { - civicrm_api3_verify_mandatory($params, - 'CRM_Mailing_DAO_MailingAB', - array('id'), - FALSE - ); - - - $mailingAB = civicrm_api3('MailingAB', 'get', $params); - $mailingAB = $mailingAB['values'][$params['id']]; - - //update mailingC with include/exclude group id(s) provided - civicrm_api3('Mailing', 'create', array('id' => $mailingAB['mailing_id_c'], 'groups' => $params['groups'])); - //update recipients for mailing_id_c - CRM_Mailing_BAO_Mailing::getRecipients($mailingAB['mailing_id_c'], $mailingAB['mailing_id_c'], NULL, NULL, TRUE); - //calulate total number of random recipients for mail C from group_percentage selected - $totalCount = civicrm_api3('MailingRecipients', 'getcount', array('mailing_id' => $mailingAB['mailing_id_c'])); - $totalSelected = round(($totalCount * $mailingAB['group_percentage'])/100); - foreach (array('mailing_id_a', 'mailing_id_b') as $columnName) { - CRM_Mailing_BAO_Recipients::updateRandomRecipients($mailingAB['mailing_id_c'], $mailingAB[$columnName], $totalSelected); - } - return civicrm_api3_create_success(); -} - - - /** * Handle a delete event. * @@ -149,38 +76,6 @@ function civicrm_api3_mailing_a_b_recipients_update($params) { * * @return array API Success Array */ - -function civicrm_api3_mailing_preview($params) { - civicrm_api3_verify_mandatory($params, - 'CRM_Mailing_DAO_Mailing', - array('id'), - FALSE - ); - $fromEmail = NULL; - if (!empty($params['from_email'])) { - $fromEmail = $params['from_email']; - } - $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->getFlattenedToken()); - $mime = &$mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, - TRUE, $details[0][$contactID], $attachments - ); - return civicrm_api3_create_success(array('html' => $mime->getHTMLBody(), 'text' => $mime->getTXTBody())); -} - - function civicrm_api3_mailing_delete($params, $ids = array()) { return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); } @@ -374,17 +269,42 @@ function civicrm_api3_mailing_event_open($params) { return civicrm_api3_create_success($params); } -/** - * Fix the reset dates on the email record based on when a mail was last delivered - * We only consider mailings that were completed and finished in the last 3 to 7 days - * 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) +function civicrm_api3_mailing_preview($params) { + civicrm_api3_verify_mandatory($params, + 'CRM_Mailing_DAO_Mailing', + array('id'), + FALSE ); - return civicrm_api3_create_success(); + + $fromEmail = NULL; + if (!empty($params['from_email'])) { + $fromEmail = $params['from_email']; + } + + $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->getFlattenedToken()); + + $mime = &$mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail, + TRUE, $details[0][$contactID], $attachments + ); + + return civicrm_api3_create_success(array('subject' => $mime->_headers['Subject'], 'html' => $mime->getHTMLBody(), 'text' => $mime->getTXTBody())); } function civicrm_api3_mailing_send_test($params) { @@ -396,8 +316,10 @@ function civicrm_api3_mailing_send_test($params) { array('mailing_id'), FALSE ); + $testEmailParams = _civicrm_api3_generic_replace_base_params($params); - $job = civicrm_api3('MailingJob', 'create', array('mailing_id' => $testEmailParams['mailing_id'], 'is_test' => 1)); + $testEmailParams['is_test'] = 1; + $job = civicrm_api3('MailingJob', 'create', $testEmailParams); $testEmailParams['job_id'] = $job['id']; $testEmailParams['emails'] = explode(',', $testEmailParams['test_email']); if (!empty($params['test_email'])) { @@ -449,11 +371,87 @@ ORDER BY e.is_bulkmail DESC, e.is_primary DESC ); } } + $isComplete = FALSE; while (!$isComplete) { $isComplete = CRM_Mailing_BAO_MailingJob::runJobs($testEmailParams); } - return $isComplete; + + //return delivered mail info + $mailDelivered = CRM_Mailing_Event_BAO_Delivered::getRows($params['mailing_id'], $job['id'], TRUE, NULL, NULL, NULL, TRUE); + + return civicrm_api3_create_success($mailDelivered); } +/** + * Adjust Metadata for send_mail action + * + * The metadata is used for setting defaults, documentation & validation + * @param array $params array or parameters determined by getfields + */ +function _civicrm_api3_mailing_stats_spec(&$params) { + $params['date']['api.default'] = 'now'; +} +function civicrm_api3_mailing_stats($params) { + civicrm_api3_verify_mandatory($params, + 'CRM_Mailing_DAO_MailingJob', + array('mailing_id'), + FALSE + ); + + if ($params['date'] == 'now') { + $params['date'] = date('YmdHis'); + } + else { + $params['date'] = CRM_Utils_Date::processDate($params['date'] . ' ' . $params['date_time']); + } + + $stats[$params['mailing_id']] = array(); + if (empty($params['job_id'])) { + $params['job_id'] = NULL; + } + foreach (array('Delivered', 'Bounces', 'Unsubscribers', 'Unique Clicks', 'Opened') as $detail) { + switch ($detail) { + case 'Delivered': + $stats[$params['mailing_id']] += array( + $detail => CRM_Mailing_Event_BAO_Delivered::getTotalCount($params['mailing_id'], $params['job_id'], FALSE, $params['date']) + ); + break; + case 'Bounces': + $stats[$params['mailing_id']] += array( + $detail => CRM_Mailing_Event_BAO_Bounce::getTotalCount($params['mailing_id'], $params['job_id'], FALSE, $params['date']) + ); + break; + case 'Unsubscribers': + $stats[$params['mailing_id']] += array( + $detail => CRM_Mailing_Event_BAO_Unsubscribe::getTotalCount($params['mailing_id'], $params['job_id'], FALSE, NULL, $params['date']) + ); + break; + case 'Unique Clicks': + $stats[$params['mailing_id']] += array( + $detail => CRM_Mailing_Event_BAO_TrackableURLOpen::getTotalCount($params['mailing_id'], $params['job_id'], FALSE, NULL, $params['date']) + ); + break; + case 'Opened': + $stats[$params['mailing_id']] += array( + $detail => CRM_Mailing_Event_BAO_Opened::getTotalCount($params['mailing_id'], $params['job_id'], FALSE, $params['date']) + ); + break; + } + } + return civicrm_api3_create_success($stats); +} + +/** + * Fix the reset dates on the email record based on when a mail was last delivered + * We only consider mailings that were completed and finished in the last 3 to 7 days + * 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(); +} diff --git a/api/v3/MailingAB.php b/api/v3/MailingAB.php old mode 100644 new mode 100755 index f853209bbe..af225dca96 --- a/api/v3/MailingAB.php +++ b/api/v3/MailingAB.php @@ -76,3 +76,75 @@ function civicrm_api3_mailing_a_b_get($params) { } +/** + * Update recipients of A/B mail randomly based on group percentage selected. + * + * @param array $params + * @return array + */ +function civicrm_api3_mailing_a_b_recipients_update($params) { +civicrm_api3_verify_mandatory($params, + 'CRM_Mailing_DAO_MailingAB', + array('id'), + FALSE + ); + + $mailingAB = civicrm_api3('MailingAB', 'get', $params); + $mailingAB = $mailingAB['values'][$params['id']]; + + //update mailingC with include/exclude group id(s) provided + civicrm_api3('Mailing', 'create', array('id' => $mailingAB['mailing_id_c'], 'groups' => $params['groups'])); + //update recipients for mailing_id_c + CRM_Mailing_BAO_Mailing::getRecipients($mailingAB['mailing_id_c'], $mailingAB['mailing_id_c'], NULL, NULL, TRUE); + + //calulate total number of random recipients for mail C from group_percentage selected + $totalCount = civicrm_api3('MailingRecipients', 'getcount', array('mailing_id' => $mailingAB['mailing_id_c'])); + $totalSelected = round(($totalCount * $mailingAB['group_percentage'])/200); + + foreach (array('mailing_id_a', 'mailing_id_b') as $columnName) { + CRM_Mailing_BAO_Recipients::updateRandomRecipients($mailingAB['mailing_id_c'], $mailingAB[$columnName], $totalSelected); + } + + return civicrm_api3_create_success(); +} + +/** + * Adjust Metadata for send_mail action + * + * The metadata is used for setting defaults, documentation & validation + * @param array $params array or parameters determined by getfields + */ +function _civicrm_api3_mailing_a_b_send_mail_spec(&$params) { + $params['scheduled_date']['api.default'] = 'now'; +} + +/** + * Send A/B mail to A/B recipients respectively + * + * @param array $params + * @return array + */ +function civicrm_api3_mailing_a_b_send_mail($params) { + civicrm_api3_verify_mandatory($params, + 'CRM_Mailing_DAO_MailingAB', + array('id'), + FALSE + ); + + if ($params['scheduled_date'] == 'now') { + $params['scheduled_date'] = date('YmdHis'); + } + else { + $params['scheduled_date'] = CRM_Utils_Date::processDate($params['scheduled_date'] . ' ' . $params['scheduled_date_time']); + } + + + $mailingAB = civicrm_api3('MailingAB', 'get', array('id' => $params['id'])); + $mailingAB = $mailingAB['values'][$params['id']]; + + foreach (array('mailing_id_a', 'mailing_id_b') as $columnName) { + civicrm_api3('Mailing', 'create', $params + array('id' => $mailingAB[$columnName])); + } + + return civicrm_api3_create_success(); +} \ No newline at end of file diff --git a/css/angular-crmMailingAB.css b/css/angular-crmMailingAB.css index b97db241bf..5b83681400 100644 --- a/css/angular-crmMailingAB.css +++ b/css/angular-crmMailingAB.css @@ -42,6 +42,8 @@ div#frag1 { height:500px; width:800px; overflow: auto; + position: relative; + } div#frag2 { diff --git a/js/angular-crmMailingAB.js b/js/angular-crmMailingAB.js old mode 100644 new mode 100755 index 47bd50f1ec..dc9bcd5ba7 --- a/js/angular-crmMailingAB.js +++ b/js/angular-crmMailingAB.js @@ -1,15 +1,13 @@ /** * Created by aditya on 6/12/14. */ - - (function (angular, $, _) { var partialUrl = function (relPath) { return CRM.resourceUrls['civicrm'] + '/partials/abtesting/' + relPath; }; - var crmMailingAB = angular.module('crmMailingAB', ['ngRoute', 'ui.utils','ngSanitize']); + var crmMailingAB = angular.module('crmMailingAB', ['ngRoute', 'ui.utils', 'ngSanitize']); var mltokens = []; crmMailingAB.run(function ($rootScope, $templateCache) { $rootScope.$on('$viewContentLoaded', function () { @@ -32,26 +30,24 @@ templateUrl: partialUrl('report.html'), controller: 'ReportCtrl', resolve: { - selectedABTest: function($route, crmApi) { - return crmApi('MailingAB', 'getsingle', {id: $route.current.params.id}); - + selectedABTest: function ($route, crmApi) { + return crmApi('MailingAB', 'getsingle', {id: $route.current.params.id}); } } - }); $routeProvider.when('/mailing/abtesting/:id', { templateUrl: partialUrl('main.html'), - controller: 'TabsDemoCtrl', + controller: 'crmABTestingTabsCtrl', resolve: { - selectedABTest: function($route, crmApi) { - if ( $route.current.params.id !== 'new') { + selectedABTest: function ($route, crmApi) { + if ($route.current.params.id !== 'new') { return crmApi('MailingAB', 'getsingle', {id: $route.current.params.id}); } else { console.log("created"); //created_id has been set to my id. Does not save without created_id. Needs to made generic based on the user - return { just_created:"1" + return { just_created: "1" }; } } @@ -65,129 +61,122 @@ // Ex: crmMailingAB.controller('ABListingCtrl', function ($scope, crmApi) { $scope.abmailList = CRM.crmMailing.mailingabNames; - console.log($scope.abmailList); - - }); - crmMailingAB.controller('ReportCtrl', function ($scope, crmApi,selectedABTest) { - - - $scope.graph_data = [{ - time: 1, - x: 3, - y: 4 - }, { - time: 2, - x: 6, - y: 8, - }, { - time: 3, - x: 10, - y: 9, - }, { - time: 4, - x: 13, - y: 11, - }] + + crmMailingAB.controller('ReportCtrl', function ($scope, crmApi, selectedABTest) { + $scope.graph_data = [ + { + time: 1, + x: 3, + y: 4 + }, + { + time: 2, + x: 6, + y: 8, + }, + { + time: 3, + x: 10, + y: 9, + }, + { + time: 4, + x: 13, + y: 11, + } + ] console.log(selectedABTest); - if(selectedABTest.winner_criteria_id==1){ + if (selectedABTest.winner_criteria_id == 1) { $scope.winner_criteria = "Open"; } - else if(selectedABTest.winner_criteria_id ==2){ - $scope.winner_criteria ="Total Unique Clicks"; - } - else if(selectedABTest.winner_criteria_id ==3){ - $scope.winner_criteria ="Total Clicks on a particular link"; - + else { + if (selectedABTest.winner_criteria_id == 2) { + $scope.winner_criteria = "Total Unique Clicks"; } + else { + if (selectedABTest.winner_criteria_id == 3) { + $scope.winner_criteria = "Total Clicks on a particular link"; + } + } + } + }); - - - }) - crmMailingAB.controller('TabsDemoCtrl', function ($scope, crmApi,selectedABTest,$sce) { + crmMailingAB.controller('crmABTestingTabsCtrl', function ($scope, crmApi, selectedABTest, $sce) { $scope.partialUrl = partialUrl; $scope.abId = ""; - $scope.whatnext=2; - $scope.currentABTest=selectedABTest + $scope.whatnext = 2; + $scope.currentABTest = selectedABTest; $scope.groups = CRM.crmMailing.groupNames; $scope.mailList = CRM.crmMailing.civiMails; $scope.eMailing = CRM.crmMailing.emailAdd; $scope.tmpList = CRM.crmMailing.mesTemplate; $scope.headerfooter = CRM.crmMailing.headerfooterList; - - if($scope.currentABTest.declare_winning_time != null){ - $scope.ans= $scope.currentABTest.declare_winning_time.split(" "); - $scope.currentABTest.date=$scope.ans[0]; - $scope.currentABTest.time=$scope.ans[1]; - + $scope.emailadd = ""; + if ($scope.currentABTest.declare_winning_time != null) { + $scope.ans = $scope.currentABTest.declare_winning_time.split(" "); + $scope.currentABTest.date = $scope.ans[0]; + $scope.currentABTest.time = $scope.ans[1]; } + if ($scope.currentABTest.just_created != 1) { + $scope.abId = $scope.currentABTest.id; + var abmailA = crmApi('Mailing', 'getsingle', {id: $scope.currentABTest.mailing_id_a}); + var abmailB = crmApi('Mailing', 'getsingle', {id: $scope.currentABTest.mailing_id_b}); + var abmailC = crmApi('Mailing', 'getsingle', {id: $scope.currentABTest.mailing_id_c}); + abmailA.success(function (data) { + if (data.is_error == 0) { + $scope.mailA = data; + } + }); + abmailB.success(function (data) { + if (data.is_error == 0) { + $scope.mailB = data; + } + }); + abmailC.success(function (data) { + if (data.is_error == 0) { + $scope.mailC = data; + } + }); + } + else { + $scope.mailA = {}; + $scope.mailB = {}; + $scope.mailC = {}; + } - if($scope.currentABTest.just_created != 1){ - console.log("Prithvi"); - console.log($scope.currentABTest); - console.log($scope.currentABTest.mailing_id_a); - - $scope.abId = $scope.currentABTest.id; - var abmailA = crmApi('Mailing','getsingle',{id:$scope.currentABTest.mailing_id_a}); - var abmailB= crmApi('Mailing','getsingle',{id:$scope.currentABTest.mailing_id_b}); - var abmailC = crmApi('Mailing','getsingle',{id:$scope.currentABTest.mailing_id_c}); - abmailA.success(function (data) { - if (data.is_error == 0) { - $scope.mailA = data; - - }; - }); - abmailB.success(function(data) { - if (data.is_error == 0) { - $scope.mailB = data; - - }; - }); - abmailC.success(function(data) { - if (data.is_error == 0) { - $scope.mailC = data; - - }; - }); - } - else{ - console.log("Prithvila"); - console.log($scope.currentABTest); - $scope.mailA = {}; - $scope.mailB = {}; - $scope.mailC = {}; - } - - $scope.sendtest=false; - if(typeof $scope.mailA == 'undefined')$scope.mailA={}; - if(typeof $scope.mailB == 'undefined')$scope.mailB={}; - if(typeof $scope.mailB == 'undefined')$scope.mailC={}; + $scope.sendtest = false; + if (typeof $scope.mailA == 'undefined') { + $scope.mailA = {}; + } + if (typeof $scope.mailB == 'undefined') { + $scope.mailB = {}; + } + if (typeof $scope.mailB == 'undefined') { + $scope.mailC = {}; + } $scope.templates = [ - { name: 'Subject Lines', url: partialUrl('subject_lines.html'),val: 1}, - { name: 'From Name', url: partialUrl('from_name.html'),val:2}, - {name: 'Two different Emails', url: partialUrl('two_emails.html'),val:3} + { name: 'Subject Lines', url: partialUrl('subject_lines.html'), val: 1}, + { name: 'From Name', url: partialUrl('from_name.html'), val: 2}, + { name: 'Two different Emails', url: partialUrl('two_emails.html'), val: 3} ]; - if($scope.currentABTest.just_created != 1){ - console.log("adit "+$scope.currentABTest.testing_criteria_id); - - $scope.template=$scope.templates[$scope.currentABTest.testing_criteria_id-1]; - console.log($scope.template.val); - } - else{ - console.log("adi"); + if ($scope.currentABTest.just_created != 1) { + $scope.template = $scope.templates[$scope.currentABTest.testing_criteria_id - 1]; + } + else { $scope.template = $scope.templates[0]; } mltokens = CRM.crmMailing.mailTokens; - $scope.deliberatelyTrustDangerousSnippeta = function() { + $scope.deliberatelyTrustDangerousSnippeta = function () { return $sce.trustAsHtml($scope.previewa); }; - $scope.deliberatelyTrustDangerousSnippetb = function() { + $scope.deliberatelyTrustDangerousSnippetb = function () { return $sce.trustAsHtml($scope.previewb); }; @@ -199,7 +188,7 @@ } }; - $scope.winner_criteria=""; + $scope.winner_criteria = ""; $scope.compose_clicked = function () { if ($scope.max_tab >= 1) { $scope.tab_val = 1; @@ -215,6 +204,7 @@ $scope.tab_val = 3; } }; + $scope.preview = false; $scope.slide_value = 0; @@ -227,118 +217,121 @@ } }; - $scope.reply = function(){ - if($scope.trackreplies==0){ - $scope.trackreplies=1; + $scope.reply = function () { + if ($scope.trackreplies == 0) { + $scope.trackreplies = 1; } - else{ - $scope.trackreplies=0; - $scope.currentMailing.forward_replies=0; - $scope.currentMailing.auto_responder=0; + else { + $scope.trackreplies = 0; + $scope.currentMailing.forward_replies = 0; + $scope.currentMailing.auto_responder = 0; } } - $scope.isAuto= function(au){ + $scope.isAuto = function (au) { return au.component_type == "Reply"; }; - $scope.trackr= function(trackreplies){ - if(trackreplies=="1"){ + $scope.trackr = function (trackreplies) { + if (trackreplies == "1") { return true; } - else + else { return false; + } } - $scope.sen = function(){ - $scope.sendtest=true; + $scope.sendTestMailing = function () { + $scope.sendtest = true; } - $scope.isHeader= function(hf){ + $scope.isHeader = function (hf) { return hf.component_type == "Header"; }; //filter so we only get footers from mailing component - $scope.isFooter= function(f){ + $scope.isFooter = function (f) { return f.component_type == "Footer"; }; $scope.send_date = "01/01/2000"; - $scope.dt = ""; - $scope.savea = function (dat) { var result = crmApi('Mailing', 'create', dat, true); console.log(result); - result.success(function(data) { + result.success(function (data) { if (data.is_error == 0) { $scope.mailA.id = data.id; - $scope.currentABTest.mailing_id_a=$scope.mailA.id; - console.log("Mail a Id "+ $scope.mailA.id); + $scope.currentABTest.mailing_id_a = $scope.mailA.id; + console.log("Mail a Id " + $scope.mailA.id); } }); }; - $scope.append_mails = function(){ - crmApi('MailingAB','create',{id:$scope.abId,mailing_id_a:$scope.mailA.id,mailing_id_b:$scope.mailB.id,mailing_id_c:$scope.mailC.id}); - $scope.currentABTest.id= $scope.abId; + $scope.append_mails = function () { + crmApi('MailingAB', 'create', {id: $scope.abId, mailing_id_a: $scope.mailA.id, mailing_id_b: $scope.mailB.id, mailing_id_c: $scope.mailC.id}); + $scope.currentABTest.id = $scope.abId; }; $scope.saveb = function (dat) { - var flag =0; + var flag = 0; var result = crmApi('Mailing', 'create', dat, true); console.log(result); - result.success(function(data) { + result.success(function (data) { if (data.is_error == 0) { $scope.mailB.id = data.id; - console.log("Mail b Id "+ $scope.mailB.id); - $scope.currentABTest.mailing_id_b=$scope.mailB.id; - + console.log("Mail b Id " + $scope.mailB.id); + $scope.currentABTest.mailing_id_b = $scope.mailB.id; $scope.append_mails(); - - } }); - }; $scope.savec = function (dat) { - var flag =0; + var flag = 0; console.log("C is called"); var result = crmApi('Mailing', 'create', dat, true); console.log(result); - result.success(function(data) { + result.success(function (data) { if (data.is_error == 0) { $scope.mailC.id = data.id; - console.log("Mail C Id "+ $scope.mailC.id); - $scope.currentABTest.mailing_id_c=$scope.mailC.id; - + console.log("Mail C Id " + $scope.mailC.id); + $scope.currentABTest.mailing_id_c = $scope.mailC.id; $scope.append_mails(); - - } }); - }; - $scope.previewa=""; - $scope.pre= function(){ - $scope.preview=true; + $scope.previewa = ""; + $scope.pre = function () { + $scope.preview = true; } - $scope.init = function (par) { + $scope.init = function (par) { + if (par == "3") { + $scope.template.url = partialUrl('from_name.html'); + } + else { + if (par == "2") { + $scope.template.url = partialUrl('subject_lines.html'); + } + else { + $scope.template.url = partialUrl('two_emails.html'); + } + } $scope.whatnext = par.toString() }; - $scope.tab_upd = function(){ + + $scope.tab_upd = function () { $scope.tab_val = $scope.tab_val + 1; - $scope.max_tab=Math.max($scope.tab_val, $scope.max_tab); + $scope.max_tab = Math.max($scope.tab_val, $scope.max_tab); + } - }; - $scope.tab_upd_dec = function(){ + $scope.tab_upd_dec = function () { $scope.tab_val = $scope.tab_val - 1; - } + $scope.setdate = function (par) { console.log("called") console.log("av " + par) @@ -347,169 +340,194 @@ $scope.apply(); }; - $scope.testmailid =""; + $scope.testmailid = ""; $scope.incGroup = []; $scope.excGroup = []; - $scope.incGroupids =[]; - $scope.excGroupids =[]; + $scope.incGroupids = []; + $scope.excGroupids = []; $scope.tp1 = {}; - $scope.create_abtest = function(){ + $scope.create_abtest = function () { var result; - $scope.currentABTest.testing_criteria_id=$scope.template.val; - - if($scope.abId =="" ) - result= crmApi('MailingAB','create',{name: $scope.currentABTest.name,testing_criteria_id: $scope.template.val}); - else{ - if (typeof $scope.currentABTest.mailing_id_a == 'undefined') - result= crmApi('MailingAB','create',{id:$scope.abId,testing_criteria_id: $scope.template.val}); - else{ - result= crmApi('MailingAB','create',{id:$scope.abId,testing_criteria_id: $scope.template.val,mailing_id_a:$scope.currentABTest.mailing_id_a,mailing_id_b:$scope.currentABTest.mailing_id_b} ); + $scope.currentABTest.testing_criteria_id = $scope.template.val; + if ($scope.abId == "") { + result = crmApi('MailingAB', 'create', {name: $scope.currentABTest.name, testing_criteria_id: $scope.template.val}); + } + else { + if (typeof $scope.currentABTest.mailing_id_a == 'undefined') { + result = crmApi('MailingAB', 'create', {id: $scope.abId, testing_criteria_id: $scope.template.val}); + } + else { + result = crmApi('MailingAB', 'create', {id: $scope.abId, testing_criteria_id: $scope.template.val, mailing_id_a: $scope.currentABTest.mailing_id_a, mailing_id_b: $scope.currentABTest.mailing_id_b}); } - } - - result.success(function(data) { + result.success(function (data) { if (data.is_error == 0) { $scope.abId = data.id; - console.log("ID "+$scope.abId); + console.log("ID " + $scope.abId); } }); }; - - - $scope.a_b_update = function(){ - - $scope.tp1.include =$scope.incGroupids; - $scope.tp1.exclude=$scope.excGroupids; + $scope.a_b_update = function () { + $scope.tp1.include = $scope.incGroupids; + $scope.tp1.exclude = $scope.excGroupids; console.log($scope.tp1); console.log($scope.currentABTest.id); console.log("--------"); - var result= crmApi('Mailing','a_b_recipients_update',{ - id:$scope.currentABTest.id, + var result = crmApi('Mailing', 'a_b_recipients_update', { + id: $scope.currentABTest.id, groups: $scope.tp1 }); - var resulta =crmApi('Mailing','preview',{id:$scope.currentABTest.mailing_id_a}); + var resulta = crmApi('Mailing', 'preview', {id: $scope.currentABTest.mailing_id_a}); - resulta.success(function(data) { + resulta.success(function (data) { if (data.is_error == 0) { console.log("came"); - - $scope.previewa=data.values.html; - - - + $scope.previewa = data.values.html; } }); - resulta =crmApi('Mailing','preview',{id:$scope.currentABTest.mailing_id_b}); + resulta = crmApi('Mailing', 'preview', {id: $scope.currentABTest.mailing_id_b}); - resulta.success(function(data) { + resulta.success(function (data) { if (data.is_error == 0) { console.log("came"); console.log(data.values.html); - $scope.previewb=data.values.html; - - + $scope.previewb = data.values.html; } }); } - $scope.update_abtest = function(){ - - $scope.currentABTest.declare_winning_time= $scope.currentABTest.date + " " + $scope.currentABTest.time ; - - result= crmApi('MailingAB','create',{id:$scope.abId, - testing_criteria_id: $scope.template.val, - mailing_id_a:$scope.currentABTest.mailing_id_a, - mailing_id_b:$scope.currentABTest.mailing_id_b, - mailing_id_c:$scope.currentABTest.mailing_id_c, - winner_criteria_id : $scope.currentABTest.winner_criteria_id, - group_percentage: $scope.currentABTest.group_percentage, - declare_winning_time: $scope.currentABTest.declare_winning_time - } ); - - - + $scope.update_abtest = function () { + $scope.currentABTest.declare_winning_time = $scope.currentABTest.date + " " + $scope.currentABTest.time; + result = crmApi('MailingAB', 'create', {id: $scope.abId, + testing_criteria_id: $scope.template.val, + mailing_id_a: $scope.currentABTest.mailing_id_a, + mailing_id_b: $scope.currentABTest.mailing_id_b, + mailing_id_c: $scope.currentABTest.mailing_id_c, + winner_criteria_id: $scope.currentABTest.winner_criteria_id, + group_percentage: $scope.currentABTest.group_percentage, + declare_winning_time: $scope.currentABTest.declare_winning_time + }); }; - - - - - - - $scope.tmp = function (tst,aorb){ - if(aorb==1){ - $scope.mailA.msg_template_id=tst; - console.log($scope.mailA.msg_template_id+ "sasas"); - if($scope.mailA.msg_template_id == null){ - $scope.mailA.body_html=""; + $scope.tmp = function (tst, aorb) { + if (aorb == 1) { + $scope.mailA.msg_template_id = tst; + console.log($scope.mailA.msg_template_id + "sasas"); + if ($scope.mailA.msg_template_id == null) { + $scope.mailA.body_html = ""; } - else{ - for(var a in $scope.tmpList){ - - if($scope.tmpList[a].id==$scope.mailA.msg_template_id){ - $scope.mailA.body_html=$scope.tmpList[a].msg_html; + else { + for (var a in $scope.tmpList) { + if ($scope.tmpList[a].id == $scope.mailA.msg_template_id) { + $scope.mailA.body_html = $scope.tmpList[a].msg_html; } } } } - else if(aorb==2){ - - $scope.mailB.msg_template_id=tst; - console.log($scope.mailB.msg_template_id+ "sasas"); - if($scope.mailB.msg_template_id == null){ - $scope.mailB.body_html=""; - } - else{ - for(var a in $scope.tmpList){ - - if($scope.tmpList[a].id==$scope.mailB.msg_template_id){ - $scope.mailB.body_html=$scope.tmpList[a].msg_html; + else { + if (aorb == 2) { + $scope.mailB.msg_template_id = tst; + console.log($scope.mailB.msg_template_id + "sasas"); + if ($scope.mailB.msg_template_id == null) { + $scope.mailB.body_html = ""; + } + else { + for (var a in $scope.tmpList) { + if ($scope.tmpList[a].id == $scope.mailB.msg_template_id) { + $scope.mailB.body_html = $scope.tmpList[a].msg_html; + } } } } - - } - else { - - $scope.mailA.msg_template_id=tst; - console.log($scope.mailA.msg_template_id+ "sasas"); - if($scope.mailA.msg_template_id == null){ - $scope.mailA.body_html=""; - } - else{ - for(var a in $scope.tmpList){ - - if($scope.tmpList[a].id==$scope.mailA.msg_template_id){ - $scope.mailA.body_html=$scope.tmpList[a].msg_html; + else { + $scope.mailA.msg_template_id = tst; + console.log($scope.mailA.msg_template_id + "sasas"); + if ($scope.mailA.msg_template_id == null) { + $scope.mailA.body_html = ""; + } + else { + for (var a in $scope.tmpList) { + if ($scope.tmpList[a].id == $scope.mailA.msg_template_id) { + $scope.mailA.body_html = $scope.tmpList[a].msg_html; + } } } - } - - $scope.mailB.msg_template_id=tst; - console.log($scope.mailB.msg_template_id+ "sasas"); - if($scope.mailB.msg_template_id == null){ - $scope.mailB.body_html=""; - } - else{ - for(var a in $scope.tmpList){ - if($scope.tmpList[a].id==$scope.mailB.msg_template_id){ - $scope.mailB.body_html=$scope.tmpList[a].msg_html; + $scope.mailB.msg_template_id = tst; + console.log($scope.mailB.msg_template_id + "sasas"); + if ($scope.mailB.msg_template_id == null) { + $scope.mailB.body_html = ""; + } + else { + for (var a in $scope.tmpList) { + if ($scope.tmpList[a].id == $scope.mailB.msg_template_id) { + $scope.mailB.body_html = $scope.tmpList[a].msg_html; + } } } } + } + } - + $scope.$watch('preview', function () { + console.log("dsfdfsfds"); + if ($scope.preview == true) { + $('#prevmail').dialog({ + title: 'Preview Mailing', + width: 1080, + height: 800, + closed: false, + cache: false, + modal: true, + close: function () { + console.log("close"); + $scope.preview = false; + $scope.$apply(); + } + }); } - }; + }, true); + + $scope.$watch('sendtest', function () { + if ($scope.sendtest == true) { + $('#sendtest').dialog({ + title: 'Send Test Mails', + width: 380, + height: 200, + closed: false, + cache: false, + modal: true, + buttons: { + 'Send': function () { + var result = crmApi('Mailing','send_test',{ + mailing_id : $scope.currentABTest.mailing_id_a, + test_email : $scope.emailadd + }); + + var result = crmApi('Mailing','send_test',{ + mailing_id : $scope.currentABTest.mailing_id_b, + test_email : $scope.emailadd + }) + console.log($scope.emailadd); + scope.sendtest = false; + $('#sendtest').dialog("close"); + } + }, + close: function () { + console.log("close"); + scope.sendtest = false; + $scope.$apply() + } + }); + } + }); }); @@ -517,48 +535,50 @@ return { // Restrict it to be an attribute in this case restrict: 'A', - priority: 500, // responsible for registering DOM listeners as well as updating the DOM link: function (scope, element, attrs) { - $(element).parent().parent().parent().parent().parent().parent().tabs(scope.$eval(attrs.nexttab)); + var tabselector = $(".crmABTestingAllTabs"); + tabselector.tabs(scope.$eval(attrs.nexttab)); var myarr = new Array(1, 2, 3) - $(element).parent().parent().parent().parent().parent().parent().tabs({disabled: myarr}); + + // disable remaining tabs + tabselector.tabs({disabled: myarr}); $(element).on("click", function () { - if(scope.tab_val==0){ + if (scope.tab_val == 0) { scope.create_abtest(); } - else if(scope.tab_val == 2){ - scope.update_abtest(); - if(scope.currentABTest.winner_criteria_id==1){ - scope.winner_criteria="Open"; - } - else if(scope.currentABTest.winner_criteria_id==2){ - scope.winner_criteria=" Total Unique Clicks"; - } - else if(scope.currentABTest.winner_criteria_id==3){ - scope.winner_criteria="Total Clicks on a particular link"; + else { + if (scope.tab_val == 2) { + scope.update_abtest(); + if (scope.currentABTest.winner_criteria_id == 1) { + scope.winner_criteria = "Open"; } - - - scope.a_b_update(); - + else { + if (scope.currentABTest.winner_criteria_id == 2) { + scope.winner_criteria = " Total Unique Clicks"; + } + else { + if (scope.currentABTest.winner_criteria_id == 3) { + scope.winner_criteria = "Total Clicks on a particular link"; + } + } + } + scope.a_b_update(); + } } scope.tab_upd(); - console.log("kurund "+scope.tab_val); - var myArray1 = new Array(); for (var i = scope.max_tab + 1; i < 4; i++) { myArray1.push(i); } - $(element).parent().parent().parent().parent().parent().parent().tabs("option", "disabled", myArray1); - $(element).parent().parent().parent().parent().parent().parent().tabs("option", "active", scope.tab_val); + tabselector.tabs("option", "disabled", myArray1); + tabselector.tabs("option", "active", scope.tab_val); scope.$apply(); - console.log("Adir"); }); } }; @@ -571,22 +591,15 @@ priority: 500, // responsible for registering DOM listeners as well as updating the DOM link: function (scope, element, attrs) { - - $(element).on("click", function () { var temp = scope.tab_val - 1; scope.tab_upd_dec(); scope.$apply(); console.log(temp); - if (temp == 3) { - - } - else { - $(element).parent().parent().parent().parent().parent().parent().tabs("option", "active", temp); + if (temp != 3) { + $(".crmABTestingAllTabs").tabs("option", "active", temp); } - scope.$apply(); - }); } }; @@ -658,13 +671,13 @@ if (e.val.split(" ")[2] == "exclude") { var index = scope.excGroup.indexOf(e.val.split(" ")[3]); scope.excGroup.splice(index, 1); - scope.excGroupids.splice(index,1); + scope.excGroupids.splice(index, 1); scope.$apply(); } else { var index = scope.incGroup.indexOf(e.val.split(" ")[3]); scope.incGroup.splice(index, 1); - scope.incGroupids.splice(index,1); + scope.incGroupids.splice(index, 1); scope.$apply(); } }); @@ -673,15 +686,16 @@ }); - crmMailingAB.directive('groupselect',function(){ + crmMailingAB.directive('groupselect', function () { return { - restrict : 'AE', - link: function(scope,element, attrs){ - $(element).select2({width:"200px", data: mltokens, placeholder:"Insert Token"}); + 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); + $(element).on('select2-selecting', function (e) { + scope.$evalAsync('_resetSelection()'); + console.log(mltokens); /* if(scope.currentMailing.body_html == null){ scope.currentMailing.body_html = e.val; } @@ -691,14 +705,14 @@ var msg = document.getElementById("body_html").value; var cursorlen = document.getElementById("body_html").selectionStart; console.log(cursorlen); - var textlen = msg.length; + var textlen = msg.length; document.getElementById("body_html").value = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); scope.currentMailing.body_html = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); console.log(document.getElementById("body_html").value); console.log(scope.currentMailing.body_html); var cursorPos = (cursorlen + e.val.length); document.getElementById("body_html").selectionStart = cursorPos; - document.getElementById("body_html").selectionEnd = cursorPos; + document.getElementById("body_html").selectionEnd = cursorPos; document.getElementById("body_html").focus(); scope.$apply(); e.preventDefault(); @@ -713,9 +727,9 @@ return{ restrict: 'AE', link: function (scope, element, attrs) { - if(typeof scope.currentABTest.group_percentage != 'undefined'){ + if (typeof scope.currentABTest.group_percentage != 'undefined') { console.log("Yay"); - $(element).slider({value:scope.currentABTest.group_percentage}); + $(element).slider({value: scope.currentABTest.group_percentage}); } $(element).slider({min: 1}); $(element).slider({ @@ -728,137 +742,18 @@ }; }); - crmMailingAB.directive('tpmax', function () { - return { - restrict: 'E', - link: function (scope, element, attr) { - scope.$watch('automated', function (val) { - if (val == "Yes") { - $(element).dialog({ - title: 'Automated A/B Testing', - width: 800, - height: 600, - closed: false, - cache: false, - modal: true - }); - } - }); - - $(element).find("#closebutton").on("click", function () { - $(element).dialog("close"); - }); - } - }; - }); - - crmMailingAB.directive('previewmail', function () { - return { - // Restrict it to be an attribute in this case - restrict: 'AE', - - priority: 500, - // responsible for registering DOM listeners as well as updating the DOM - link: function (scope, element, attrs) { - - scope.$watch('preview', function () { - if(scope.preview == true){ - - $(element).dialog({ - title: 'Preview Mailing', - width: 1080, - height: 800, - closed: false, - cache: false, - modal: true, - - close :function(){console.log("close"); - scope.preview = false;scope.$apply()} - - - });} - - }); - - - $(element).find("#closebutton").on("click", function () { - console.log("close"); - scope.preview = false; - $(element).dialog("close"); - }); - } - }; - }); - - crmMailingAB.directive('sendmailtest', function () { - return { - // Restrict it to be an attribute in this case - restrict: 'AE', - - link: function (scope, element, attrs) { - - scope.$watch('sendtest', function () { - if(scope.sendtest == true){ - - $(element).dialog({ - title: 'Send Test Mails', - width: 1080, - height: 800, - closed: false, - cache: false, - modal: true, - button:{ - 'Send': function() { - /* Do stuff */ - $(this).dialog('close'); - } - }, - close :function(){console.log("close"); - scope.sendtest = false;scope.$apply()} - - - }); - } - - }); - - - $(element).find("#closebutton").on("click", function () { - console.log("close"); - scope.preview = false; - $(element).dialog("close"); - }); - } - }; - }); - - crmMailingAB.directive('numbar', function () { - return{ - restrict: 'AE', - link: function (scope, element, attrs) { - $(element).spinner({max: attrs.numbar, min: 0}); - } - }; - }); - crmMailingAB.directive('datepick', function () { 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); - } - - }); } }; @@ -870,15 +765,14 @@ priority: 1000, link: function (scope, element, attrs) { $(element).on("click", function () { - console.log("clicked"); scope.savea({ id: scope.mailA.id, - name: "Aditya Nambiar", - visibility: scope.mailA.visibility, + name: "mailing a", + visibility: scope.mailA.visibility, created_id: 1, subject: scope.mailA.subject, - msg_template_id: scope.mailA.msg_template_id==null ? "" : scope.mailA.msg_template_id, + msg_template_id: scope.mailA.msg_template_id == null ? "" : scope.mailA.msg_template_id, open_tracking: scope.mailA.open_tracking, url_tracking: scope.mailA.url_tracking, forward_replies: scope.mailA.forward_replies, @@ -892,78 +786,69 @@ body_text: scope.mailA.body_text, scheduled_date: scope.mailA.scheduled_date, scheduled_id: scope.mailA.scheduled_id, - campaign_id: scope.mailA.campaign_id==null ? "" : scope.mailA.campaign_id, - header_id: scope.mailA.header_id, + campaign_id: scope.mailA.campaign_id == null ? "" : scope.mailA.campaign_id, + header_id: scope.mailA.header_id, footer_id: scope.mailA.footer_id, - is_completed: scope.mailA.is_completed }); - console.log("Truth " + scope.whatnext) - if (scope.whatnext == "3") { console.log("sdf"); - - scope.mailB.name= scope.mailA.name; - scope.mailB.visibility= scope.mailA.visibility; - scope.mailB.created_id= scope.mailA.created_id; - scope.mailB.subject= scope.mailA.subject; - scope.mailB.msg_template_id= scope.mailA.msg_template_id==null ? "" : scope.mailA.msg_template_id; - scope.mailB.open_tracking= scope.mailA.open_tracking; - scope.mailB.url_tracking= scope.mailA.url_tracking; - scope.mailB.forward_replies= scope.mailA.forward_replies; - scope.mailB.auto_responder= scope.mailA.auto_responder; - scope.mailB.from_name= scope.mailA.from_name; - scope.mailB.replyto_email= scope.mailA.replyto_email; - scope.mailB.unsubscribe_id= scope.mailA.unsubscribe_id; - scope.mailB.resubscribe_id= scope.mailA.resubscribe_id; - scope.mailB.body_html= scope.mailA.body_html; - scope.mailB.body_text= scope.mailA.body_text; - scope.mailB.scheduled_date= scope.mailA.scheduled_date; - scope.mailB.scheduled_id= scope.mailA.scheduled_id; - scope.mailB.campaign_id= scope.mailA.campaign_id==null ? "" : scope.mailA.campaign_id; - scope.mailB.header_id= scope.mailA.header_id; - scope.mailB.footer_id= scope.mailA.footer_id; - - scope.mailB.is_completed= scope.mailA.is_completed; - + scope.mailB.name = scope.mailA.name; + scope.mailB.visibility = scope.mailA.visibility; + scope.mailB.created_id = scope.mailA.created_id; + scope.mailB.subject = scope.mailA.subject; + scope.mailB.msg_template_id = scope.mailA.msg_template_id == null ? "" : scope.mailA.msg_template_id; + scope.mailB.open_tracking = scope.mailA.open_tracking; + scope.mailB.url_tracking = scope.mailA.url_tracking; + scope.mailB.forward_replies = scope.mailA.forward_replies; + scope.mailB.auto_responder = scope.mailA.auto_responder; + scope.mailB.from_name = scope.mailA.from_name; + scope.mailB.replyto_email = scope.mailA.replyto_email; + scope.mailB.unsubscribe_id = scope.mailA.unsubscribe_id; + scope.mailB.resubscribe_id = scope.mailA.resubscribe_id; + scope.mailB.body_html = scope.mailA.body_html; + scope.mailB.body_text = scope.mailA.body_text; + scope.mailB.scheduled_date = scope.mailA.scheduled_date; + scope.mailB.scheduled_id = scope.mailA.scheduled_id; + scope.mailB.campaign_id = scope.mailA.campaign_id == null ? "" : scope.mailA.campaign_id; + scope.mailB.header_id = scope.mailA.header_id; + scope.mailB.footer_id = scope.mailA.footer_id; + scope.mailB.is_completed = scope.mailA.is_completed; } else { if (scope.whatnext == "2") { scope.mailB.fromEmail = scope.mailA.fromEmail; - scope.mailB.name= scope.mailA.name; - scope.mailB.visibility= scope.mailA.visibility; - scope.mailB.created_id= scope.mailA.created_id; - scope.mailB.msg_template_id= scope.mailA.msg_template_id==null ? "" : scope.mailA.msg_template_id; - scope.mailB.open_tracking= scope.mailA.open_tracking; - scope.mailB.url_tracking= scope.mailA.url_tracking; - scope.mailB.forward_replies= scope.mailA.forward_replies; - scope.mailB.auto_responder= scope.mailA.auto_responder; - scope.mailB.from_name= scope.mailA.from_name; - scope.mailB.replyto_email= scope.mailA.replyto_email; - scope.mailB.unsubscribe_id= scope.mailA.unsubscribe_id; - scope.mailB.resubscribe_id= scope.mailA.resubscribe_id; - scope.mailB.body_html= scope.mailA.body_html; - scope.mailB.body_text= scope.mailA.body_text; - scope.mailB.scheduled_date= scope.mailA.scheduled_date; - scope.mailB.scheduled_id= scope.mailA.scheduled_id; - scope.mailB.campaign_id= scope.mailA.campaign_id==null ? "" : scope.mailA.campaign_id; - scope.mailB.header_id= scope.mailA.header_id; - scope.mailB.footer_id= scope.mailA.footer_id; - - scope.mailB.is_completed= scope.mailA.is_completed; - + scope.mailB.name = scope.mailA.name; + scope.mailB.visibility = scope.mailA.visibility; + scope.mailB.created_id = scope.mailA.created_id; + scope.mailB.msg_template_id = scope.mailA.msg_template_id == null ? "" : scope.mailA.msg_template_id; + scope.mailB.open_tracking = scope.mailA.open_tracking; + scope.mailB.url_tracking = scope.mailA.url_tracking; + scope.mailB.forward_replies = scope.mailA.forward_replies; + scope.mailB.auto_responder = scope.mailA.auto_responder; + scope.mailB.from_name = scope.mailA.from_name; + scope.mailB.replyto_email = scope.mailA.replyto_email; + scope.mailB.unsubscribe_id = scope.mailA.unsubscribe_id; + scope.mailB.resubscribe_id = scope.mailA.resubscribe_id; + scope.mailB.body_html = scope.mailA.body_html; + scope.mailB.body_text = scope.mailA.body_text; + scope.mailB.scheduled_date = scope.mailA.scheduled_date; + scope.mailB.scheduled_id = scope.mailA.scheduled_id; + scope.mailB.campaign_id = scope.mailA.campaign_id == null ? "" : scope.mailA.campaign_id; + scope.mailB.header_id = scope.mailA.header_id; + scope.mailB.footer_id = scope.mailA.footer_id; + scope.mailB.is_completed = scope.mailA.is_completed; } } console.log("call B"); scope.saveb({ - id: scope.mailB.id, - name: "Aditya Nambiar", - visibility: scope.mailB.visibility, + name: "mailing b", + visibility: scope.mailB.visibility, created_id: 1, subject: scope.mailB.subject, - msg_template_id: scope.mailB.msg_template_id==null ? "" : scope.mailB.msg_template_id, + msg_template_id: scope.mailB.msg_template_id == null ? "" : scope.mailB.msg_template_id, open_tracking: scope.mailB.open_tracking, url_tracking: scope.mailB.url_tracking, forward_replies: scope.mailB.forward_replies, @@ -977,21 +862,20 @@ body_text: scope.mailB.body_text, scheduled_date: scope.mailB.scheduled_date, scheduled_id: scope.mailB.scheduled_id, - campaign_id: scope.mailB.campaign_id==null ? "" : scope.mailB.campaign_id, - header_id: scope.mailB.header_id, - footer_id: scope.mailB.footer_id, - + campaign_id: scope.mailB.campaign_id == null ? "" : scope.mailB.campaign_id, + header_id: scope.mailB.header_id, + footer_id: scope.mailB.footer_id, is_completed: scope.mailA.is_completed - }); + console.log("call C"); scope.savec({ id: scope.mailC.id, - name: "Aditya Nambiar", - visibility: scope.mailB.visibility, + name: "mailing c", + visibility: scope.mailB.visibility, created_id: 1, subject: scope.mailB.subject, - msg_template_id: scope.mailB.msg_template_id==null ? "" : scope.mailB.msg_template_id, + msg_template_id: scope.mailB.msg_template_id == null ? "" : scope.mailB.msg_template_id, open_tracking: scope.mailB.open_tracking, url_tracking: scope.mailB.url_tracking, forward_replies: scope.mailB.forward_replies, @@ -1003,55 +887,25 @@ resubscribe_id: scope.mailB.resubscribe_id, body_html: scope.mailB.body_html, body_text: scope.mailB.body_text, - campaign_id: scope.mailB.campaign_id==null ? "" : scope.mailB.campaign_id, - header_id: scope.mailB.header_id, - footer_id: scope.mailB.footer_id, - + campaign_id: scope.mailB.campaign_id == null ? "" : scope.mailB.campaign_id, + header_id: scope.mailB.header_id, + footer_id: scope.mailB.footer_id, is_completed: scope.mailA.is_completed }); - - }); } }; - }); - - - crmMailingAB.directive('nextbutton', function () { + crmMailingAB.directive('chsdate', function () { return { restrict: 'AE', - replace: 'true', - template: '
' + - '
' + - '' + - '
' - - }; - }); - - crmMailingAB.directive('cancelbutton', function () { - return { - restrict: 'AE', - replace: 'true', - template: '
' + - '
' + - '' + - '
' - - }; - }); - - crmMailingAB.directive('chsdate',function(){ - return { - restrict: 'AE', - link: function(scope,element,attrs){ + link: function (scope, element, attrs) { $(element).datepicker({ dateFormat: "yy-mm-dd", - onSelect: function(date) { + onSelect: function (date) { $(".ui-datepicker a").removeAttr("href"); - scope.currentABTest.date=date.toString(); + scope.currentABTest.date = date.toString(); scope.$apply(); console.log(scope.currentABTest.date); } @@ -1068,21 +922,14 @@ '
' + '' + '
' - }; }); - crmMailingAB.directive('linegraph',function(){ + crmMailingAB.directive('linegraph', function () { return { restrict: 'AE', - link: function(scope,element,attrs){ - console.log("try"); - var data= scope.graph_data; - - // see wht it looks like in the console - console.log("Data"); - console.log(data); - + link: function (scope, element, attrs) { + var data = scope.graph_data; // set up a colour variable var color = d3.scale.category10(); @@ -1092,24 +939,23 @@ console.log("Key"); console.log(d3.keys(data[0])); - color.domain(d3.keys(data[0]).filter(function(key) { + color.domain(d3.keys(data[0]).filter(function (key) { return key !== "time"; })); // create a nested series for passing to the line generator // it's best understood by console logging the data - var series = color.domain().map(function(name) { + var series = color.domain().map(function (name) { console.log(name); return { name: name, - values: data.map(function(d) { + values: data.map(function (d) { console.log("------"); console.log(d); return { time: d.time, score: +d[name] - }; }) }; @@ -1130,7 +976,7 @@ // Set the ranges //var x = d3.time.scale().range([0, width]).domain([0,10]); - var x = d3.scale.linear().range([0,width]); + var x = d3.scale.linear().range([0, width]); var y = d3.scale.linear().range([height, 0]); // Define the axes @@ -1143,14 +989,13 @@ // Define the line // Note you plot the time / score pair from each key you created ealier var valueline = d3.svg.line() - .x(function(d) { + .x(function (d) { return x(d.time); }) - .y(function(d) { + .y(function (d) { return y(d.score); }); - // Adds the svg canvas var svg = d3.select(element[0]) .append("svg") @@ -1160,36 +1005,36 @@ .attr("transform", "translate(" + margin.left + "," + margin.top + ")"); // Scale the range of the data - x.domain(d3.extent(data, function(d) { + x.domain(d3.extent(data, function (d) { return d.time; })); // note the nested nature of this you need to dig an additional level y.domain([ - d3.min(series, function(c) { - return d3.min(c.values, function(v) { + d3.min(series, function (c) { + return d3.min(c.values, function (v) { return v.score; }); }), - d3.max(series, function(c) { - return d3.max(c.values, function(v) { + d3.max(series, function (c) { + return d3.max(c.values, function (v) { return v.score; }); }) ]); svg.append("text") // text label for the x axis - .attr("x", width / 2 ) - .attr("y", height + margin.bottom ) + .attr("x", width / 2) + .attr("y", height + margin.bottom) .style("text-anchor", "middle") .text("Time"); svg.append("text") // text label for the x axis .style("text-anchor", "middle") - .text(scope.winner_criteria).attr("transform", function(d) { + .text(scope.winner_criteria).attr("transform",function (d) { return "rotate(-90)" - }).attr("x", -height/2 ) - .attr("y", -30 ); + }).attr("x", -height / 2) + .attr("y", -30); ; // create a variable called series and bind the date // for each series append a g element and class it as series for css styling @@ -1202,11 +1047,11 @@ // pass each object called x, y nad z to the lne generator series.append("path") .attr("class", "line") - .attr("d", function(d) { + .attr("d", function (d) { console.log(d); // to see how d3 iterates through series return valueline(d.values); }) - .style("stroke", function(d) { + .style("stroke", function (d) { return color(d.name); }); @@ -1220,12 +1065,8 @@ svg.append("g") // Add the Y Axis .attr("class", "y axis") .call(yAxis); - - } - } - }); })(angular, CRM.$, CRM._); diff --git a/partials/abtesting/attachments.html b/partials/abtesting/attachments.html old mode 100644 new mode 100755 diff --git a/partials/abtesting/composeonScreen.html b/partials/abtesting/composeonScreen.html old mode 100644 new mode 100755 diff --git a/partials/abtesting/from_name.html b/partials/abtesting/from_name.html old mode 100644 new mode 100755 index db46d4fbb0..3f75e6999a --- a/partials/abtesting/from_name.html +++ b/partials/abtesting/from_name.html @@ -1,219 +1,89 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
From E-mail Address A - -
From E-mail Address B - -
Reply to E-mail Address - -
Mailing Subject - -
- Mailing subject required. -
Use Template - -
I want toCompose on screenUpload Content
From E-mail Address A + +
From E-mail Address B + +
Reply to E-mail Address + +
Mailing Subject + +
+ Mailing subject required. +
Use Template + +
I want toCompose on screenUpload Content

-