From f27a0a8e8ff7c02a47bae27b3973faa8edfab4fa Mon Sep 17 00:00:00 2001 From: aditya-nambiar Date: Sun, 17 Aug 2014 19:10:50 +0530 Subject: [PATCH] Fixes --- CRM/Mailing/Info.php | 3 +- api/v3/MailingGroup.php | 9 ++++ js/angular-crmMailingAB.js | 85 +++++++++++++++++++++++++++++++++--- partials/abtesting/main.html | 3 +- partials/abtesting/tab3.html | 14 +++--- 5 files changed, 98 insertions(+), 16 deletions(-) diff --git a/CRM/Mailing/Info.php b/CRM/Mailing/Info.php index 548e8cdaac..a86fb74f28 100644 --- a/CRM/Mailing/Info.php +++ b/CRM/Mailing/Info.php @@ -76,7 +76,7 @@ class CRM_Mailing_Info extends CRM_Core_Component_Info { 'id' => array('>' => 58), )); $mailTokens = civicrm_api3('Mailing', 'get_token', array( 'usage' => 'Mailing')); - + $mailGrp = civicrm_api3('MailingGroup','get', array()); CRM_Core_Resources::singleton()->addSetting(array( 'crmMailing' => array( 'mailingabNames'=>array_values($mailingabNames['values']), @@ -88,6 +88,7 @@ class CRM_Mailing_Info extends CRM_Core_Component_Info { 'mesTemplate' => array_values($mesTemplate['values']), 'emailAdd' => array_values($emailAdd['values']), 'mailTokens' => array_values($mailTokens), + 'mailGrp' => array_values($mailGrp['values']) ), )); diff --git a/api/v3/MailingGroup.php b/api/v3/MailingGroup.php index c042a393cf..b5ba210b47 100644 --- a/api/v3/MailingGroup.php +++ b/api/v3/MailingGroup.php @@ -91,6 +91,15 @@ 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); +} + + +function civicrm_api3_mailing_group_delete($params, $ids = array()) { + 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(); diff --git a/js/angular-crmMailingAB.js b/js/angular-crmMailingAB.js index 2d5455ecad..d468f9bd16 100755 --- a/js/angular-crmMailingAB.js +++ b/js/angular-crmMailingAB.js @@ -9,6 +9,9 @@ var mltokens = []; var crmMailingAB = angular.module('crmMailingAB', ['ngRoute', 'ui.utils', 'ngSanitize']); var mltokens = []; + var chck = []; //to fill the group variable $scope.incGroup + var chck2= []; // to get id and text in the required format + var chck3= []; crmMailingAB.run(function ($rootScope, $templateCache) { $rootScope.$on('$viewContentLoaded', function () { $templateCache.removeAll(); @@ -147,11 +150,14 @@ $scope.mailList = CRM.crmMailing.civiMails; $scope.eMailing = CRM.crmMailing.emailAdd; $scope.tmpList = CRM.crmMailing.mesTemplate; + $scope.mailingGrp = CRM.crmMailing.mailGrp; $scope.headerfooter = CRM.crmMailing.headerfooterList; $scope.sparestuff ={}; $scope.sparestuff.emailadd = ""; $scope.sparestuff.winnercriteria = ""; $scope.sparestuff.isnew = false; + $scope.sparestuff.allgroups = ""; + $scope.mailid = []; mltokens = CRM.crmMailing.mailTokens; if ($scope.currentABTest.declare_winning_time != null) { $scope.ans = $scope.currentABTest.declare_winning_time.split(" "); @@ -159,10 +165,13 @@ $scope.currentABTest.time = $scope.ans[1]; } $scope.token = []; - + chck = []; + chck2 = []; + chck3=[]; if ($scope.currentABTest.just_created != 1) { $scope.abId = $scope.currentABTest.id; $scope.sparestuff.isnew = false; + 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}); @@ -179,8 +188,52 @@ abmailC.success(function (data) { if (data.is_error == 0) { $scope.mailC = data; + for(var a in $scope.mailingGrp){ + console.log("youuo"); + if($scope.mailingGrp[a].mailing_id==$scope.mailC.id){ + console.log($scope.mailingGrp[a]); + 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); + } + } + 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.groups){ + if($scope.groups[c].id==splt[0]){ + b.text = $scope.groups[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; + } + } + } + chck2.push(b); + } + for(var a in chck2){ + var b =chck2[a]; + + chck3.push(b.id+" "+ b.text); + } + console.log("yooyo"); + console.log(chck); + console.log(chck2); + console.log(chck3); + $scope.sparestuff.allgroups = chck3; + } }); + + } else { $scope.sparestuff.isnew = true; @@ -398,10 +451,10 @@ else { console.log("aa"); if (typeof $scope.currentABTest.mailing_id_a == 'undefined') { - result = crmApi('MailingAB', 'create', {id: $scope.abId, testing_criteria_id: $scope.sparestuff.template.val}); + result = crmApi('MailingAB', 'create', {name: $scope.currentABTest.name,id: $scope.abId, testing_criteria_id: $scope.sparestuff.template.val}); } else { - result = crmApi('MailingAB', 'create', {id: $scope.abId, testing_criteria_id: $scope.sparestuff.template.val, mailing_id_a: $scope.currentABTest.mailing_id_a, mailing_id_b: $scope.currentABTest.mailing_id_b}); + result = crmApi('MailingAB', 'create', {name: $scope.currentABTest.name,id: $scope.abId, testing_criteria_id: $scope.sparestuff.template.val, mailing_id_a: $scope.currentABTest.mailing_id_a, mailing_id_b: $scope.currentABTest.mailing_id_b}); } } @@ -739,20 +792,21 @@ } // return item template var a = item.id.split(" "); - if (a[1] == "group" && a[2] == "include") { + if (a[1] == "civicrm_group" && a[2] == "include") { return "" + " " + "" + item.text; } - if (a[1] == "group" && a[2] == "exclude") { + if (a[1] == "civicrm_group" && a[2] == "exclude") { return "" + " " + "" + item.text; } - if (a[1] == "mail" && a[2] == "include") { + if (a[1] == "civicrm_mailing" && a[2] == "include") { return "" + " " + "" + item.text; } - if (a[1] == "mail" && a[2] == "exclude") { + if (a[1] == "civicrm_mailing" && a[2] == "exclude") { return "" + " " + "" + item.text; } } + $(element).select2({ width: "400px", placeholder: "Select the groups you wish to include", @@ -761,10 +815,18 @@ escapeMarkup: function (m) { return m; } + }).select2("data", scope.sparestuff.allgroups); + + $(element).on("select2-opening", function() + { scope.sparestuff.allgroups=chck3; + + scope.$apply(); + }); $(element).on('select2-selecting', function (e) { var a = e.val.split(" "); + console.log(e); var l = a.length; if (a[2] == "include") { var str = ""; @@ -788,6 +850,10 @@ scope.excGroupids.push(a[0]); scope.$apply(); } + chck3.push(e.val); + scope.sparestuff.allgroups=chck3; + scope.$apply(); + // console.log(scope.incGroup); }); $(element).on("select2-removed", function (e) { @@ -803,6 +869,11 @@ scope.incGroupids.splice(index, 1); scope.$apply(); } + var index = chck3.indexOf(e.val); + chck3.splice(index, 1); + scope.sparestuff.allgroups=chck3; + // console.log(scope.incGroup); + scope.$apply(); }); } }; diff --git a/partials/abtesting/main.html b/partials/abtesting/main.html index 6e12dd33fc..2445181bc5 100755 --- a/partials/abtesting/main.html +++ b/partials/abtesting/main.html @@ -1,5 +1,6 @@ {{tab_val}}
- {{winnercriteria}} + {{winnercriteria}}
+ {{sparestuff.allgroups}}