Fixes
authoraditya-nambiar <aditya.nambiar007@gmail.com>
Sun, 17 Aug 2014 13:40:50 +0000 (19:10 +0530)
committeraditya-nambiar <aditya.nambiar007@gmail.com>
Sun, 17 Aug 2014 13:40:50 +0000 (19:10 +0530)
CRM/Mailing/Info.php
api/v3/MailingGroup.php
js/angular-crmMailingAB.js
partials/abtesting/main.html
partials/abtesting/tab3.html

index 548e8cdaac845411aa53f0f83e57343f0897a681..a86fb74f2867ce90e50353ed56b7561391890ec7 100644 (file)
@@ -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'])
       ),
     ));
 
index c042a393cf9b19100f8966c34b7b1c1583974998..b5ba210b47fb1f48f0574cb268733d065c0fca30 100644 (file)
@@ -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();
index 2d5455ecadcc2ee292021e1c9ee3eda85ced28d0..d468f9bd16aa68b5ac22779b912df2ae5a2ee911 100755 (executable)
@@ -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();
     $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(" ");
       $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});
       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;
       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});
         }
       }
 
           }
           // return item template
           var a = item.id.split(" ");
-          if (a[1] == "group" && a[2] == "include") {
+          if (a[1] == "civicrm_group" && a[2] == "include") {
             return "<img src='../../sites/all/modules/civicrm/i/include.jpeg' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/group.png' height=12 width=12/>" + item.text;
           }
-          if (a[1] == "group" && a[2] == "exclude") {
+          if (a[1] == "civicrm_group" && a[2] == "exclude") {
             return "<img src='../../sites/all/modules/civicrm/i/Error.gif' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/group.png' height=12 width=12/>" + item.text;
           }
-          if (a[1] == "mail" && a[2] == "include") {
+          if (a[1] == "civicrm_mailing" && a[2] == "include") {
             return "<img src='../../sites/all/modules/civicrm/i/include.jpeg' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/EnvelopeIn.gif' height=12 width=12/>" + item.text;
           }
-          if (a[1] == "mail" && a[2] == "exclude") {
+          if (a[1] == "civicrm_mailing" && a[2] == "exclude") {
             return "<img src='../../sites/all/modules/civicrm/i/Error.gif' height=12 width=12/>" + " " + "<img src='../../sites/all/modules/civicrm/i/EnvelopeIn.gif' height=12 width=12/>" + item.text;
           }
         }
 
+
         $(element).select2({
           width: "400px",
           placeholder: "Select the groups you wish to include",
           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 = "";
             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) {
             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();
         });
       }
     };
index 6e12dd33fc0347c488e6ca1e22abca857cf8712b..2445181bc58775fa79f08ebaa014bef90cad7260 100755 (executable)
@@ -1,5 +1,6 @@
 {{tab_val}}<br>
-  {{winnercriteria}}
+  {{winnercriteria}}<br>
+  {{sparestuff.allgroups}}
 <div ui-jq="tabs" class="crmABTestingAllTabs" ui-options="{show: true, hide: true, collapsible: true}">
   <ul>
     <li><a href="#tabs-1" ng-click="campaign_clicked();">Campaign</a></li>
index d3ba72301e4a633a0b76b6eef12af3da5a1bd723..57c74d6c64bbd7ef309ba60d2008fe7e186d4d26 100755 (executable)
@@ -2,12 +2,12 @@
   <div class="crm-block crm-form-block crmABTesting">
     <h3>Select the groups you would like to add</h3><br>
     &nbsp<br>
-    <select multiple chsgroup required>
-      <option id="1" ng-repeat="grp in groups" value="{{grp.id}} group include {{grp.title}}"> {{grp.title}}
+    <select multiple chsgroup ng-model="sparestuff.allgroups" required>
+      <option id="1" ng-repeat="grp in groups" value="{{grp.id}} civicrm_group include {{grp.title}}"> {{grp.title}}
       </option>
-      <option ng-repeat="grp in groups" value="{{grp.id}} group exclude {{grp.title}}"> {{grp.title}}</option>
-      <option ng-repeat="ml in mailList" value="{{ml.id}} mail include {{ml.title}}"> {{ml.name}}</option>
-      <option ng-repeat="ml in mailList" value="{{ml.id}} mail exclude {{ml.title}}"> {{ml.name}}</option>
+      <option ng-repeat="grp in groups" value="{{grp.id}} civicrm_group exclude {{grp.title}}"> {{grp.title}}</option>
+      <option ng-repeat="ml in mailList" value="{{ml.id}} civicrm_mailing include {{ml.title}}"> {{ml.name}}</option>
+      <option ng-repeat="ml in mailList" value="{{ml.id}} civicrm_mailing exclude {{ml.title}}"> {{ml.name}}</option>
     </select>
     <br> <br><br><br>
 
     <br>
     <div class="crm-submit-buttons">
       <span class="crm-button">
-        <input type="submit" ng-click="tab3Form.$setPristine();update_abtest();" value="Previous" prevtab/>
+        <input type="submit" ng-click="tab3Form.$setPristine();" value="Previous" prevtab/>
       </span>
       <span class="crm-button">
-        <input type="submit" ng-click="tab3Form.$setPristine();update_abtest();" ng-disabled="tab3Form.$invalid" value="Next" nexttab="{{tab_val}}"/>
+        <input type="submit" ng-click="tab3Form.$setPristine();" ng-disabled="tab3Form.$invalid" value="Next" nexttab="{{tab_val}}"/>
       </span>
       <span class="crm-button">
         <input type="submit" ng-click="tab3Form.$setPristine(); goto('mailing/abtesting');" value="Cancel"/>