X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fangular-crmMailingAB.js;h=d7a8b299fceb0234aee8ab791e3bba84e6ef361a;hb=5c691259e0df1eb30e5be9cd4327e09282500923;hp=e554ead476376e95c75b85d1f5782c143a9c29b6;hpb=08346fd9ae64a607101c6081b5002f6bbff308b3;p=civicrm-core.git diff --git a/js/angular-crmMailingAB.js b/js/angular-crmMailingAB.js index e554ead476..d7a8b299fc 100644 --- a/js/angular-crmMailingAB.js +++ b/js/angular-crmMailingAB.js @@ -3,240 +3,421 @@ */ -(function(angular, $, _) { - - var partialUrl = function(relPath) { - return CRM.resourceUrls['civicrm'] + '/partials/abtesting/' + relPath; - }; - - var crmMailingAB = angular.module('crmMailingAB', ['ngRoute', 'ui.utils']); - - -//------------------------------------------------------------------------------------------------------- - crmMailingAB.config(['$routeProvider', - function($routeProvider) { - $routeProvider.when('/mailing', { - template: '

sdfs

', - controller: 'mailingListCtrl', - resolve: { - mailingList: function($route, crmApi) { - return crmApi('Mailing', 'get', {}); - } - } - }); - - - $routeProvider.when('/mailing/abtesting', { - - templateUrl: partialUrl('helloworld.html'), - controller: 'TabsDemoCtrl', - resolve: { - mailingList: function($route, crmApi) { - return crmApi('Mailing', 'get', {}); - } - } - - - }); - } - ]); +(function (angular, $, _) { + + var partialUrl = function (relPath) { + return CRM.resourceUrls['civicrm'] + '/partials/abtesting/' + relPath; + }; + + var crmMailingAB = angular.module('crmMailingAB', ['ngRoute', 'ui.utils']); + + crmMailingAB.run(function ($rootScope, $templateCache) { + $rootScope.$on('$viewContentLoaded', function () { + $templateCache.removeAll(); + }); + }); + + crmMailingAB.config([ + '$routeProvider', + function ($routeProvider) { +// $routeProvider.when('/mailing', { +// template: '

sdfs

', +// controller: 'mailingListCtrl', +// resolve: { +// mailingList: function ($route, crmApi) { +// return crmApi('Mailing', 'get', {}); +// } +// } +// }); + + $routeProvider.when('/mailing/abtesting', { + templateUrl: partialUrl('main.html'), + controller: 'TabsDemoCtrl', + resolve: { + mailingList: function ($route, crmApi) { + return crmApi('Mailing', 'get', {}); + } + } + }); + } + ]); //----------------------------------------- - // Add a new record by name. - // Ex: - - crmMailingAB.controller('TabsDemoCtrl', function($scope, crmApi, mailingList) { - - $scope.adi=0; - $scope.campaign_clicked= function(){ - if($scope.adi >= 0 ){ - $scope.adi =0; - } - }; - $scope.compose_clicked=function(){ - if($scope.adi >=1){ - $scope.adi =1; - } - }; - $scope.rec_clicked=function(){ - if($scope.adi >=2){ - $scope.adi =2; - } - }; - $scope.preview_clicked=function(){ - if($scope.adi>=3){ - $scope.adi=3; - } - }; - $scope.templates = - [ { name: 'subjectlines', url: partialUrl('subject_lines.html')}, - { name: 'fromname', url: partialUrl('from_name.html')}, - {name:'2emails',url: partialUrl('two_emails.html')} ]; - $scope.template = $scope.templates[0]; - - $scope.slide_value = 0; - - $scope.$watch("automated", function() { - - console.log("Smsdd"); - - }); - - $scope.setifyes= function(val){ - if(val ==1) { - $scope.ifyes = true; - } - else - $scope.ifyes=false; - }; - - $scope.closebox="open"; - - }); - - crmMailingAB.directive('nexttab', function() { - return { - // Restrict it to be an attribute in this case - restrict: 'A', - // responsible for registering DOM listeners as well as updating the DOM - link: function(scope, element, attrs) { - - $(element).parent().parent().parent().tabs(scope.$eval(attrs.nexttab)); - var myarr = new Array(1,2,3) - $(element).parent().parent().parent().tabs({disabled:myarr}); - //$(element).parent().parent().parent().tabs({"enable":1}); - - $(element).on("click",function() { - scope.adi=scope.adi +1; - var myArray1 = new Array( ); - for ( var i = scope.adi+1; i < 4; i++ ) { - myArray1.push(i); - console.log( "try " + i ); - } - $(element).parent().parent().parent().tabs( "option", "disabled", myArray1 ); - $(element).parent().parent().parent().tabs({active:scope.adi}); - console.log("adiroxxx"); - }); - } - }; - }); - - crmMailingAB.directive('groupselect',function(){ - return { - - restrict : 'AE', - - link: function(scope,element, attrs){ - - $(document).ready(function() { $(element).select2({width:"400px",placeholder: "Select the groups you wish to include"}); - - }); - - } - }; - - }); - - crmMailingAB.directive('sliderbar',function(){ - return{ - - restrict: 'AE', - - link: function(scope,element, attrs){ - - $(element).slider(); - $(element).slider({ - slide: function( event, ui ) { - scope.slide_value = ui.value; - scope.$apply(); - - } - }); - - } - - }; - - }); - - - - crmMailingAB.directive('tpmax',function(){ - return { - - restrict: 'E', - - - - link: function(scope,element,attr){ - - - - scope.$watch('automated', function(val) { - if(val=="yes") { - console.log("yo"); - - $(element).dialog({ - title: 'Automated A/B Testing', - width: 800, - height: 600, - closed: false, - cache: false, - modal: true - - }); - - - - - - } - - }); - - $(element).find("#closebutton").on("click",function(){ - console.log("you can do it"); - $(element).dialog("close"); - - }); - - - - - - } - - }; - - - - }); - - crmMailingAB.directive('numbar',function(){ - return{ - - restrict: 'AE', - - link: function(scope,element, attrs){ - - $(element).spinner({max:attrs.numbar,min:0}); - - - - } - - }; - - }); - - - - - - - - - - - + // Add a new record by name. + // Ex: + + crmMailingAB.controller('TabsDemoCtrl', function ($scope, crmApi) { + + $scope.groups = CRM.crmMailing.groupNames; + $scope.mailList = CRM.crmMailing.civiMails; + + $scope.tab_val = 0; + $scope.max_tab = 0; + $scope.campaign_clicked = function () { + if ($scope.max_tab >= 0) { + $scope.tab_val = 0; + } + }; + $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')}, + { name: 'From Name', url: partialUrl('from_name.html')}, + {name: 'Two different Emails', url: partialUrl('two_emails.html')} + ]; + $scope.template = $scope.templates[0]; + + $scope.slide_value = 0; + + $scope.setifyes = function (val) { + if (val == 1) { + $scope.ifyes = true; + } + else { + $scope.ifyes = false; + } + }; + + $scope.send_date = "01/01/2000"; + + $scope.dt = ""; + + $scope.mailA = {}; + + $scope.mailB = {}; + $scope.save = function (dat) { + + var result = crmApi('Mailing', 'create', dat, true); + console.log("Ac " + result); + }; + + $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.scheddate = {}; + $scope.scheddate.date = "6"; + $scope.scheddate.time = ""; + $scope.incGroup = []; + $scope.excGroup = []; + + + }); + + 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) { + + $(element).parent().parent().parent().parent().tabs(scope.$eval(attrs.nexttab)); + var myarr = new Array(1, 2, 3) + $(element).parent().parent().parent().parent().tabs({disabled: myarr}); + + $(element).on("click", function () { + scope.tab_val = scope.tab_val + 1; + + scope.max_tab = Math.max(scope.tab_val, scope.max_tab); + var myArray1 = new Array(); + for (var i = scope.max_tab + 1; i < 4; i++) { + myArray1.push(i); + } + $(element).parent().parent().parent().parent().parent().tabs("option", "disabled", myArray1); + $(element).parent().parent().parent().parent().parent().tabs("option", "active", scope.tab_val); + scope.$apply(); + console.log("Adir"); + }); + } + }; + }); + + 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_val = scope.tab_val - 1; + + console.log(temp); + if (temp == 3) { + + } + else { + $(element).parent().parent().parent().parent().parent().tabs("option", "active", temp); + } + + scope.$apply(); + + }); + } + }; + }); + + crmMailingAB.directive('groupselect', 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] == "group" && a[2] == "include") { + return "" + " " + "" + item.text; + } + if (a[1] == "group" && a[2] == "exclude") { + return "" + " " + "" + item.text; + } + if (a[1] == "mail" && a[2] == "include") { + return "" + " " + "" + item.text; + } + if (a[1] == "mail" && a[2] == "exclude") { + return "" + " " + "" + item.text; + } + } + + $(element).select2({ + width: "400px", + placeholder: "Select the groups you wish to include", + formatResult: format, + formatSelection: format, + escapeMarkup: function (m) { + return m; + } + }); + + $(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.$apply(); + } + + else { + var str = ""; + for (i = 3; i < l; i++) { + str += a[i]; + str += " "; + } + + scope.excGroup.push(str); + scope.$apply(); + } + + }); + $(element).on("select2-removed", function (e) { + if (e.val.split(" ")[2] == "exclude") { + var index = scope.excGroup.indexOf(e.val.split(" ")[3]); + scope.excGroup.splice(index, 1); + scope.$apply(); + } + else { + var index = scope.incGroup.indexOf(e.val.split(" ")[3]); + scope.incGroup.splice(index, 1); + scope.$apply(); + } + }); + } + }; + + }); + + crmMailingAB.directive('sliderbar', function () { + return{ + restrict: 'AE', + link: function (scope, element, attrs) { + $(element).slider({min: 1}); + $(element).slider({ + slide: function (event, ui) { + scope.slide_value = ui.value; + scope.$apply(); + } + }); + } + }; + }); + + crmMailingAB.directive('tpmax', function () { + return { + restrict: 'E', + link: function (scope, element, attr) { + scope.$watch('automated', function (val) { + if (val == "Yes") { + $(element).dialog({ + title: 'Automated A/B Testing', + width: 800, + height: 600, + closed: false, + cache: false, + modal: true + }); + } + }); + + $(element).find("#closebutton").on("click", function () { + $(element).dialog("close"); + }); + } + }; + }); + + crmMailingAB.directive('numbar', function () { + return{ + restrict: 'AE', + link: function (scope, element, attrs) { + $(element).spinner({max: attrs.numbar, min: 0}); + } + }; + }); + + crmMailingAB.directive('datepick', function () { + return { + + + restrict: 'AE', + link: function (scope, element, attrs) { + $(element).datepicker({ + dateFormat: "yy-mm-dd", + onSelect: function (date) { + $(".ui-datepicker a").removeAttr("href"); + + scope.scheddate.date = date.toString(); + scope.$apply(); + console.log(scope.scheddate.date); + + } + + + }); + } + }; + }); + + crmMailingAB.directive('submitform', function () { + return { + restrict: 'A', + priority: 1000, + link: function (scope, element, attrs) { + $(element).on("click", function () { + + console.log("clicked"); + scope.save({ + "sequential": 1, + "name": "Aditya Nambiar", + "subject": scope.mailA.subj, + "created_id": "2", + "from_email": scope.mailA.fromEmail, + "body_text": scope.mailA.body + + }); + console.log("Truth " + scope.whatnext) + + if (scope.whatnext == "3") { + console.log("sdf"); + scope.mailB.subj = scope.mailA.subj; + scope.mailB.body = scope.mailA.body; + + } + else { + if (scope.whatnext == "2") { + scope.mailB.fromEmail = scope.mailA.fromEmail; + scope.mailB.body = scope.mailA.body; + + } + } + + + scope.save({ + "sequential": 1, + "name": "Aditya Nambiar", + "subject": scope.mailB.subj, + "created_id": "2", + "from_email": scope.mailB.fromEmail, + "body_text": scope.mailB.body + + }); + + }); + } + }; + + }); + + crmMailingAB.directive('nextbutton', function () { + return { + restrict: 'AE', + replace: 'true', + template: '
' + + '
' + + '' + + '
' + + }; + }); + + crmMailingAB.directive('cancelbutton', function () { + return { + restrict: 'AE', + replace: 'true', + template: '
' + + '
' + + '' + + '
' + + }; + }); + + crmMailingAB.directive('prevbutton', function () { + return { + restrict: 'AE', + replace: 'true', + template: '
' + + '
' + + '' + + '
' + + }; + }); + + +})(angular, CRM.$, CRM._); -})(angular, CRM.$, CRM._); \ No newline at end of file