- $scope.preview = false;
- $scope.slide_value = 0;
-
- $scope.setifyes = function (val) {
- $scope.ifyes = val == 1;
- };
-
- /* $scope.reply = function () {
- if ($scope.trackreplies == 0) {
- $scope.trackreplies = 1;
- }
- else {
- $scope.trackreplies = 0;
- $scope.mailA.forward_replies = 0;
- $scope.mailA.auto_responder = 0;
- }
- }
- */
- $scope.isAuto = function (au) {
- return au.component_type == "Reply";
- };
-
- $scope.trackr = function (trackreplies) {
- return trackreplies == "1";
- };
-
- $scope.sendTestMailing = function () {
- $scope.sendtest = true;
- };
-
- $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);
- result.success(function (data) {
- if (data.is_error == 0) {
- $scope.mailA.id = data.id;
- $scope.currentABTest.mailing_id_a = $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.saveb = function (dat) {
- var result = crmApi('Mailing', 'create', dat, true);
- result.success(function (data) {
- if (data.is_error == 0) {
- $scope.mailB.id = data.id;
- $scope.currentABTest.mailing_id_b = $scope.mailB.id;
- //$scope.append_mails();
- }
- });
- };
-
- $scope.savec = function (dat) {
- var result = crmApi('Mailing', 'create', dat, true);
-
- result.success(function (data) {
- if (data.is_error == 0) {
- $scope.mailC.id = data.id;
- $scope.currentABTest.mailing_id_c = $scope.mailC.id;
- $scope.append_mails();
- }
- });
- };
-
- $scope.sparestuff.previewa = "";
- $scope.pre = function () {
- $scope.preview = true;
- };
-
- $scope.init = function (par) {
- if (par == "3") {
- $scope.sparestuff.template.url = partialUrl('from_name.html');
- }
- else {
- if (par == "2") {
- $scope.sparestuff.template.url = partialUrl('subject_lines.html');
- }
- else {
- $scope.sparestuff.template.url = partialUrl('two_emails.html');
- }
- }
- $scope.whatnext = par.toString();
- };
-
- $scope.tab_upd = function () {
- $scope.tab_val = $scope.tab_val + 1;
- $scope.max_tab = Math.max($scope.tab_val, $scope.max_tab);
- };
-
- $scope.tab_upd_dec = function () {
- $scope.tab_val = $scope.tab_val - 1;
- };
-
- $scope.setdate = function (par) {
- $scope.send_date = par;
- $scope.dt = par;
- $scope.apply();
- };
-
- $scope.testmailid = "";
- $scope.incGroup = [];
- $scope.excGroup = [];
- $scope.incGroupids = [];
- $scope.excGroupids = [];
- $scope.tp1 = {};
- $scope.create_abtest = function () {
- var result;
- $scope.currentABTest.testing_criteria_id = $scope.sparestuff.template.val;
-
- if ($scope.abId == "") {
- result = crmApi('MailingAB', 'create', {name: $scope.currentABTest.name, testing_criteria_id: $scope.sparestuff.template.val});
- }
- else {
- if (typeof $scope.currentABTest.mailing_id_a == 'undefined') {
- result = crmApi('MailingAB', 'create', {name: $scope.currentABTest.name, id: $scope.abId, testing_criteria_id: $scope.sparestuff.template.val});
- }
- else {
- 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});
- }
- }
-
- result.success(function (data) {
- if (data.is_error == 0) {
- $scope.abId = data.id;
- }
- });
- };
- $scope.tokenfunc = function (elem, e, chng) {
- var msg = document.getElementById(elem).value;
- var cursorlen = document.getElementById(elem).selectionStart;
- var textlen = msg.length;
- document.getElementById(elem).value = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen);
- chng = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen);
- var cursorPos = (cursorlen + e.val.length);
- document.getElementById(elem).selectionStart = cursorPos;
- document.getElementById(elem).selectionEnd = cursorPos;
- document.getElementById(elem).focus();
- };
-
- $scope.sparestuff.ingrps = "";
- $scope.sparestuff.excgrps = "";
- $scope.a_b_update = function () {
- $scope.tp1.include = $scope.incGroupids;
- $scope.tp1.exclude = $scope.excGroupids;
- console.log($scope.tp1);
- crmApi('MailingAB', 'recipients_update', {
- id: $scope.currentABTest.id,
- groups: $scope.tp1
- });
-
- var resulta = crmApi('Mailing', 'preview', {id: $scope.currentABTest.mailing_id_a});
-
- resulta.success(function (data) {
- if (data.is_error == 0) {
- $scope.sparestuff.previewa = data.values.html;
- }
- });
-
- resulta = crmApi('Mailing', 'preview', {id: $scope.currentABTest.mailing_id_b});
-
- resulta.success(function (data) {
- if (data.is_error == 0) {
- $scope.sparestuff.previewb = data.values.html;
- }
- });
-
- $scope.startabtest = function () {
- if (typeof $scope.sparestuff.date == 'undefined') {
- $scope.sparestuff.date = 'now';
- }
- crmApi('MailingAB', 'send_mail', {id: $scope.abId,
- scheduled_date: $scope.sparestuff.date, scheduled_date_time: $scope.currentABTest.latertime});
- };
-
- angular.forEach($scope.incGroup, function (value) {
- $scope.sparestuff.ingrps += value.toString() + ", ";
- });
- angular.forEach($scope.excGroup, function (value) {
- $scope.sparestuff.excgrps += value.toString() + ", ";
- });
- if ($scope.sparestuff.ingrps.length != 0) {
- $scope.sparestuff.ingrps = $scope.sparestuff.ingrps.substr(0, $scope.sparestuff.ingrps.length - 2);
- }
- if ($scope.sparestuff.excgrps.length != 0) {
- $scope.sparestuff.excgrps = $scope.sparestuff.excgrps.substr(0, $scope.sparestuff.excgrps.length - 2);
- }
- };
-
- $scope.update_abtest = function () {
- $scope.currentABTest.declare_winning_time = $scope.currentABTest.date + " " + $scope.currentABTest.time;
- 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,
- mailing_id_c: $scope.currentABTest.mailing_id_c,
- specific_url: $scope.currentABTest.acturl,
- winner_criteria_id: $scope.currentABTest.winner_criteria_id,
- group_percentage: $scope.currentABTest.group_percentage,
- declare_winning_time: $scope.currentABTest.declare_winning_time
- });
- };
- $scope.currentABTest.latertime = "";
- $scope.tmp = function (tst, aorb) {
- if (aorb == 1) {
- $scope.mailA.msg_template_id = tst;
- if ($scope.mailA.msg_template_id == null) {
- $scope.mailA.body_html = "";
- $scope.mailA.subject = "";
- }
- 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;
- if (typeof $scope.mailA.subject == 'undefined' || $scope.mailA.subject.length == 0) {
- $scope.mailA.subject = $scope.tmpList[a].msg_subject;
- }
- }
- }
- }
- }
- else {
- if (aorb == 2) {
- $scope.mailB.msg_template_id = tst;
- if ($scope.mailB.msg_template_id == null) {
- $scope.mailB.body_html = "";
- $scope.mailB.subject = "";
- }
- 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;
- if (typeof $scope.mailB.subject == 'undefined' || $scope.mailB.subject.length == 0) {
- $scope.mailB.subject = $scope.tmpList[a].msg_subject;
- }
-
- }
- }
- }
- }
- else {
- $scope.mailA.msg_template_id = tst;
- if ($scope.mailA.msg_template_id == null) {
- $scope.mailA.body_html = "";
- $scope.mailA.subject = "";
- }
- 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;
- if (typeof $scope.mailA.subject == 'undefined' || $scope.mailA.subject.length == 0) {
- $scope.mailA.subject = $scope.tmpList[a].msg_subject;
- }
- }
- }
- }
-
- $scope.mailB.msg_template_id = tst;
- if ($scope.mailB.msg_template_id == null) {
- $scope.mailB.body_html = "";
- $scope.mailB.subject = "";
-
- }
- 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;
- if (typeof $scope.mailB.subject == 'undefined' || $scope.mailB.subject.length == 0) {
- $scope.mailB.subject = $scope.tmpList[a].msg_subject;
- }
-
- }
- }
- }
- }
- }
- };
-
- /*$scope.tmp = function (tst){
- $scope.currentMailing.msg_template_id=tst;
- console.log($scope.currentMailing.msg_template_id+ "sasas");
- if($scope.currentMailing.msg_template_id == null){
- $scope.currentMailing.body_html="";
- $scope.currentMailing.subject="";
- }
- else{
- for(var a in $scope.tmpList){
-
- if($scope.tmpList[a].id==$scope.currentMailing.msg_template_id){
- $scope.currentMailing.body_html=$scope.tmpList[a].msg_html;
- console.log($scope.tmpList[a].msg_subject);
- $scope.currentMailing.subject=$scope.tmpList[a].msg_subject;
- console.log($scope.currentMailing.subject);
- }
- }
- }
- };*/
-
-
- $scope.$watch('preview', function () {
- if ($scope.preview == true) {
- $('#prevmail').dialog({
- title: 'Preview Mailing',
- width: 1000,
- height: 500,
- closed: false,
- cache: false,
- modal: true,
- position: {
- my: 'left',
- at: 'top',
- of: $(".crmABTestingAllTabs")
- },
-
- close: function () {
- $scope.preview = false;
- $scope.$apply();
- }
- });
-
- $("#prevmail").dialog('option', 'position', [300, 50]);
- }
-
- }, true);
-
- $scope.call = function () {
- $scope.$apply();
- crmApi('Mailing', 'send_test', {
- mailing_id: $scope.currentABTest.mailing_id_a,
- test_email: $scope.sparestuff.emailadd
- });
-
- crmApi('Mailing', 'send_test', {
- mailing_id: $scope.currentABTest.mailing_id_b,
- test_email: $scope.sparestuff.emailadd
- })
- };
-
- $scope.$watch('sendtest', function () {
- if ($scope.sendtest == true) {
- $('#sendtest').dialog({
- title: 'Send Test Mails',
- width: 300,
- height: 150,
- closed: false,
- cache: false,
- modal: true,
- buttons: {
- 'Send': function () {
- $scope.call();
- $scope.sendtest = false;
- $('#sendtest').dialog("close");
-
- }
- },
- close: function () {
- $scope.sendtest = false;
- $scope.$apply()
- }
- });
- }
- });
- });
-
-
- crmMailingAB.directive('nexttab', function () {
- 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) {
-
- var tabselector = $(".crmABTestingAllTabs");
- tabselector.tabs(scope.$eval(attrs.nexttab));
-
- // disable remaining tabs
- if (scope.sparestuff.isnew == true) {
- tabselector.tabs({disabled: [1, 2, 3]});
- }
-
- $(element).on("click", function () {
- 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.sparestuff.winnercriteria = "Open";
- scope.$apply();
- }
- else {
- if (scope.currentABTest.winner_criteria_id == 2) {
- scope.sparestuff.winnercriteria = " Total Unique Clicks";
- scope.$apply();
- }
- else {
- if (scope.currentABTest.winner_criteria_id == 3) {
- scope.sparestuff.winnercriteria = "Total Clicks on a particular link";
- scope.$apply();
- }
- }
- }
- scope.a_b_update();
- }
- }
- scope.tab_upd();
-
- var myArray1 = [];
- for (var i = scope.max_tab + 1; i < 4; i++) {
- myArray1.push(i);
- }
- tabselector.tabs("option", "disabled", myArray1);
- tabselector.tabs("option", "active", scope.tab_val);
- scope.$apply();
- });
- }
- };
- });
-
- crmMailingAB.directive('prevtab', function () {
- 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).on("click", function () {
- var temp = scope.tab_val - 1;
- scope.tab_upd_dec();
- scope.$apply();
- if (temp != 3) {
- $(".crmABTestingAllTabs").tabs("option", "active", temp);
- }
- scope.$apply();
- });
- }
- };
- });
-
- crmMailingAB.directive('chsgroup', function () {
- return {
- restrict: 'AE',
- link: function (scope, element, attrs) {
- function format(item) {
- if (!item.id) {
- // return `text` for optgroup
- return item.text;
- }
- // return item template
- var a = item.id.split(" ");
- 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] == "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] == "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] == "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",
- formatResult: format,
- formatSelection: format,
- escapeMarkup: function (m) {
- return m;
- }
- }).select2("data", scope.sparestuff.allgroups);
-
-
- $(element).on('select2-selecting', function (e) {
- var a = e.val.split(" ");
- var l = a.length;
- if (a[2] == "include") {
- var str = "";
- for (i = 3; i < l; i++) {
- str += a[i];
- str += " ";
- }
- scope.incGroup.push(str);
- scope.incGroupids.push(a[0]);
- scope.$apply();
- }
-
- else {
- var str = "";
- for (i = 3; i < l; i++) {
- str += a[i];
- str += " ";
- }
-
- scope.excGroup.push(str);
- scope.excGroupids.push(a[0]);
- scope.$apply();
- }
-
- scope.$apply();
-
- });
- $(element).on("select2-removed", function (e) {
- if (e.val.split(" ")[2] == "exclude") {
- var excIndex = scope.excGroup.indexOf(e.val.split(" ")[3]);
- scope.excGroup.splice(excIndex, 1);
- scope.excGroupids.splice(excIndex, 1);
- scope.$apply();
- }
- else {
- var incIndex = scope.incGroup.indexOf(e.val.split(" ")[3]);
- scope.incGroup.splice(incIndex, 1);
- scope.incGroupids.splice(incIndex, 1);
- scope.$apply();
- }
-
- scope.$apply();
- });
- }
- };