- }
- ]);
-
-//-----------------------------------------
- // Add a new record by name.
- // Ex: <crmAddName crm-options="['Alpha','Beta','Gamma']" crm-var="newItem" crm-on-add="callMyCreateFunction(newItem)" />
- crmMailingAB.controller('ListingCtrl', function ($scope, crmApi) {
- $scope.mailList = CRM.crmMailing.civiMails;
-
- })
- crmMailingAB.controller('TabsDemoCtrl', function ($scope, crmApi,selectedABTest) {
- $scope.abId="";
- $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];
-
- }
-
- 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});
- abmailA.success(function (data) {
- if (data.is_error == 0) {
- $scope.mailA = data;
-
- };
- });
- abmailB.success(function(data) {
- if (data.is_error == 0) {
- $scope.mailB = data;
-
- };
- });
- }
- else{
- console.log("Prithvila");
- console.log($scope.currentABTest);
- $scope.mailA = {};
- $scope.mailB = {};
- }
-
-
- mltokens = CRM.crmMailing.mailTokens;
-
- $scope.tab_val = 0;
- $scope.max_tab = 0;
- $scope.campaign_clicked = function () {
- if ($scope.max_tab >= 0) {
- $scope.tab_val = 0;
- }
- };
-
- $scope.winner_criteria="";
- $scope.compose_clicked = function () {
- if ($scope.max_tab >= 1) {
- $scope.tab_val = 1;
- }
- };
- $scope.rec_clicked = function () {
- if ($scope.max_tab >= 2) {
- $scope.tab_val = 2;
- }
- };
- $scope.preview_clicked = function () {
- if ($scope.max_tab >= 3) {
- $scope.tab_val = 3;
- }
- };
- $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}
- ];
- $scope.template = $scope.templates[0];
-
- $scope.slide_value = 0;
-
- $scope.setifyes = function (val) {
- if (val == 1) {
- $scope.ifyes = true;
- }
- else {
- $scope.ifyes = false;
- }
- };
-
- $scope.reply = function(){
- if($scope.trackreplies==0){
- $scope.trackreplies=1;
- }
- else{
- $scope.trackreplies=0;
- $scope.currentMailing.forward_replies=0;
- $scope.currentMailing.auto_responder=0;
- }
- }
-
- $scope.isAuto= function(au){
- return au.component_type == "Reply";
- };
-
- $scope.trackr= function(trackreplies){
- if(trackreplies=="1"){
- return true;
- }
- else
- return false;
- }
-
-
-
- $scope.isHeader= function(hf){
- return hf.component_type == "Header";
- };
- //filter so we only get footers from mailing component
- $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) {
- if (data.is_error == 0) {
- $scope.mailA.id = data.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});
- };
-
- $scope.saveb = function (dat) {
- var flag =0;
- var result = crmApi('Mailing', 'create', dat, true);
- console.log(result);
- result.success(function(data) {
- if (data.is_error == 0) {
- $scope.mailB.id = data.id;
- console.log("Mail b Id "+ $scope.mailB.id);
- $scope.append_mails();
-
-
- }
- });
-
- };
-
- $scope.init = function (par) {
-
- $scope.whatnext = par.toString()
- };
-
- $scope.setdate = function (par) {
- console.log("called")
- console.log("av " + par)
- $scope.send_date = par;
- $scope.dt = par;
- $scope.apply();
- };
-
-
- $scope.incGroup = [];
- $scope.excGroup = [];
-
- $scope.create_abtest = function(){
- var result;
- $scope.currentABTest.testing_criteria_id=$scope.template.val;
-
- if($scope.abId =="" )
- result= crmApi('MailingAB','create',{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) {
- if (data.is_error == 0) {
- $scope.abId = data.id;
- console.log("ID "+$scope.abId);
- }
- });
- };
-
- $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,
- 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="";
- }
- 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 {
-
- $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;
- }