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();
});
}
};
<div class="crm-block crm-form-block crmABTesting">
<h3>Select the groups you would like to add</h3><br>
 <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"/>