From 30d1144df48d75243643c79eacaee827ddf044e0 Mon Sep 17 00:00:00 2001 From: Siddhant Rajagopalan Date: Sat, 9 Aug 2014 11:34:26 +0530 Subject: [PATCH] Preview working --- CRM/Mailing/Info.php | 6 +- js/angular-newMailing.js | 231 ++++++++++++++++-- js/angularsanitize.js | 15 ++ partials/crmMailingType/content.html | 8 +- partials/crmMailingType/ht.html | 5 +- partials/crmMailingType/mailingList.html | 14 +- partials/crmMailingType/main.html | 12 +- partials/crmMailingType/plainText.html | 9 +- partials/crmMailingType/previewMailing.html | 2 +- partials/crmMailingType/preview_ht.html | 6 +- .../crmMailingType/preview_plaintext.html | 2 +- partials/crmMailingType/send.html | 17 +- 12 files changed, 275 insertions(+), 52 deletions(-) create mode 100644 js/angularsanitize.js diff --git a/CRM/Mailing/Info.php b/CRM/Mailing/Info.php index feeb4eab06..87f0348ba3 100644 --- a/CRM/Mailing/Info.php +++ b/CRM/Mailing/Info.php @@ -59,7 +59,7 @@ class CRM_Mailing_Info extends CRM_Core_Component_Info { $result = array(); $result['crmMailing'] = array( 'ext' => 'civicrm', - 'js' => array('js/angular-newMailing.js'), + 'js' => array('js/angular-newMailing.js' , 'js/angularsanitize.js'), ); $civiMails = civicrm_api3('Mailing', 'get', array()); @@ -73,8 +73,8 @@ class CRM_Mailing_Info extends CRM_Core_Component_Info { 'contact_id' => 202, )); $mesTemplate = civicrm_api3('MessageTemplate', 'get', array( 'sequential' => 1, - 'return' => array("msg_html", "id", "msg_title"), - 'id' => array('>' => 58), + 'return' => array("msg_html", "id", "msg_title", "msg_subject"), + 'workflow_id' => array('IS NULL' => ""), )); $mailGrp = civicrm_api3('MailingGroup','get', array()); $mailTokens = civicrm_api3('Mailing', 'get_token', array( 'usage' => 'Mailing')); diff --git a/js/angular-newMailing.js b/js/angular-newMailing.js index 49502a4bee..6595a15f4c 100644 --- a/js/angular-newMailing.js +++ b/js/angular-newMailing.js @@ -4,7 +4,7 @@ return CRM.resourceUrls['civicrm'] + '/partials/crmMailingType/' + relPath; }; - var crmMailing = angular.module('crmMailing', ['ngRoute', 'ui.utils']); + var crmMailing = angular.module('crmMailing', ['ngRoute', 'ui.utils','ngSanitize']); var chck = []; //to fill the group variable $scope.incGroup var chck2= []; // to get id and text in the required format var mltokens = []; @@ -46,7 +46,7 @@ //This controller is used in creating new mail and editing current mails - crmMailing.controller('mailingCtrl', function($scope, crmApi, selectedMail, $location) { + crmMailing.controller('mailingCtrl', function($scope, crmApi, selectedMail, $location,$route, $sce) { //Making some dummy api to see if my from email, reply to email works. To see if all options come in select box $scope.cool_api= [ @@ -73,9 +73,24 @@ $scope.mailingGrp = CRM.crmMailing.mailGrp; $scope.currentMailing = selectedMail; mltokens = CRM.crmMailing.mailTokens; + $scope.preview = false; + $scope.settrue = function() { + $scope.preview = true; + console.log($scope.preview); + }; + $scope.seepreview = function() { + if($scope.preview == true) + return true; + else + return false; + console.log($scope.preview); + }; + console.log(mltokens); $scope.testGroup = ""; window.ct = $scope.currentMailing; + $scope.previewbody_html = ""; + $scope.previewbody_text = ""; $scope.param = {}; $scope.tst=""; $scope.token = ""; @@ -145,6 +160,7 @@ $scope.back = function (){ $location.path( "mailing" ); + $route.reload(); }; $scope.tmp = function (tst){ @@ -152,12 +168,16 @@ 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); } } } @@ -192,15 +212,21 @@ } $scope.recclicked = function(){ - $scope.acttab=0; + if($scope.acttab >=0){ + $scope.acttab =0; + } }; $scope.conclicked = function(){ - $scope.acttab=1; + if($scope.acttab >=1){ + $scope.acttab =1; + } }; $scope.schedclicked = function(){ - $scope.acttab=2; + if($scope.acttab >=2){ + $scope.acttab =2; + } }; //to split the value of selectedMail.scheduled_date into the date and time separately @@ -273,8 +299,38 @@ console.log($scope.param.file_3); }; + $scope.preview_update = function(){ + console.log("Opened"); + + var resulta =crmApi('Mailing','preview',{id:$scope.currentMailing.id}); + resulta.success(function(data) { + if (data.is_error == 0) { + console.log("came"); + console.log(data); + $scope.previewbody_html=data.values.html; + $scope.previewbody_text=data.values.text; + } + }); + }; + + + $scope.isBody_text = function(){ + if($scope.currentMailing.body_text == null || $scope.currentMailing.body_text == "" ) + return false; + else + return true; + }; + + $scope.deliberatelyTrustDangerousSnippet = function() { + return $sce.trustAsHtml($scope.previewbody_html); + }; + + $scope.deliberatelyTrustDangerousSnippet2 = function() { + return $sce.trustAsHtml($scope.previewbody_text); + }; - $scope.save = function() { + + $scope.save_next = function() { console.log($scope.currentMailing.msg_template_id); console.log($scope.scheddate.date); $scope.incGrp=[]; @@ -366,17 +422,51 @@ exclude: $scope.excMail }, is_completed: $scope.currentMailing.is_completed, + approver_id: $scope.currentMailing.approver_id, + approval_status_id: $scope.currentMailing.approval_status_id, + approval_date: $scope.currentMailing.approval_date, }, true); //var result = crmApi('Mailing', 'create', $scope.currentMailing, true); result.success(function(data) { if (data.is_error == 0) { $scope.currentMailing.id = data.id; + console.log("the id is " + $scope.currentMailing.id ); console.log("OK"); } console.log("OK2"); }); }; + + + $scope.save = function() { + $scope.save_next(); + $scope.back(); + }; + + + $scope.submitButton= function(){ + $scope.currentMailing.approval_status_id = "1"; + $scope.currentMailing.approver_id = "202"; + var currentdate = new Date(); + var yyyy = currentdate.getFullYear(); + var mm = currentdate.getMonth() + 1; + mm = mm<10 ? '0' + mm : mm; + var dd = currentdate.getDate(); + dd = dd<10 ? '0' + dd : dd; + var hh = currentdate.getHours(); + hh = hh<10 ? '0' + hh : hh; + var min = currentdate.getMinutes(); + min = min<10 ? '0' + min : min; + var sec = currentdate.getSeconds(); + sec = sec<10 ? '0' + sec : sec; + $scope.currentMailing.approval_date = yyyy + "/"+ mm + + "/" + dd + " " + + hh + ":" + + min + ":" + sec; + console.log($scope.currentMailing.approval_date); + $scope.save(); + }; }); @@ -386,8 +476,16 @@ restrict: 'A', link: function(scope, element, attrs) { $(element).parent().parent().tabs(); + var myarr = new Array(1,2); + $(element).parent().parent().tabs({disabled:myarr}); $(element).on("click",function() { scope.acttab=scope.acttab +1; + var myArray1 = new Array( ); + for ( var i = 0; i < 3; i++ ) { + if(scope.acttab!=i) + myArray1.push(i); + } + $(element).parent().parent().tabs( "option", "disabled", myArray1 ); $(element).parent().parent().tabs({active:scope.acttab}); console.log("sid"); }); @@ -401,8 +499,16 @@ restrict: 'A', link: function(scope, element, attrs) { $(element).parent().parent().tabs(); + var myarr = new Array(1,2); + $(element).parent().parent().tabs({disabled:myarr}); $(element).on("click",function() { scope.acttab=scope.acttab -1; + var myArray1 = new Array( ); + for ( var i = 0; i < 3; i++ ) { + if(scope.acttab!=i) + myArray1.push(i); + } + $(element).parent().parent().tabs( "option", "disabled", myArray1 ); $(element).parent().parent().tabs({active:scope.acttab}); console.log("sid"); }); @@ -410,7 +516,7 @@ }; }); - // Select 2 Widget for selecting the group + // Select 2 Widget for selecting the included group crmMailing.directive('chsgroup',function(){ return { restrict : 'AE', @@ -477,32 +583,89 @@ $(element).on('select2-selecting', function(e) { scope.$evalAsync('_resetSelection()');console.log(mltokens); - /* if(scope.currentMailing.body_html == null){ - scope.currentMailing.body_html = e.val; + var a = $(element).attr('id'); + if(a=="htgroup"){ + var msg = document.getElementById("body_html").value; + var cursorlen = document.getElementById("body_html").selectionStart; + console.log(cursorlen); + var textlen = msg.length; + document.getElementById("body_html").value = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); + scope.currentMailing.body_html = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); + console.log(document.getElementById("body_html").value); + console.log(scope.currentMailing.body_html); + var cursorPos = (cursorlen + e.val.length); + document.getElementById("body_html").selectionStart = cursorPos; + document.getElementById("body_html").selectionEnd = cursorPos; + document.getElementById("body_html").focus(); } - else - scope.currentMailing.body_html = scope.currentMailing.body_html + e.val; -*/ - var msg = document.getElementById("body_html").value; - var cursorlen = document.getElementById("body_html").selectionStart; - console.log(cursorlen); - var textlen = msg.length; - document.getElementById("body_html").value = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); - scope.currentMailing.body_html = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); - console.log(document.getElementById("body_html").value); - console.log(scope.currentMailing.body_html); - var cursorPos = (cursorlen + e.val.length); - document.getElementById("body_html").selectionStart = cursorPos; - document.getElementById("body_html").selectionEnd = cursorPos; - document.getElementById("body_html").focus(); + else if(a=="subgroup"){ + var msg = document.getElementById("sub").value; + var cursorlen = document.getElementById("sub").selectionStart; + console.log(cursorlen); + var textlen = msg.length; + document.getElementById("sub").value = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); + scope.currentMailing.subject = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); + console.log(document.getElementById("sub").value); + console.log(scope.currentMailing.subject); + var cursorPos = (cursorlen + e.val.length); + document.getElementById("sub").selectionStart = cursorPos; + document.getElementById("sub").selectionEnd = cursorPos; + document.getElementById("sub").focus(); + } + else if(a=="textgroup"){ + var msg = document.getElementById("body_text").value; + var cursorlen = document.getElementById("body_text").selectionStart; + console.log(cursorlen); + var textlen = msg.length; + document.getElementById("body_text").value = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); + scope.currentMailing.body_text = msg.substring(0, cursorlen) + e.val + msg.substring(cursorlen, textlen); + console.log(document.getElementById("body_text").value); + console.log(scope.currentMailing.body_text); + var cursorPos = (cursorlen + e.val.length); + document.getElementById("body_text").selectionStart = cursorPos; + document.getElementById("body_text").selectionEnd = cursorPos; + document.getElementById("body_text").focus(); + } scope.$apply(); e.preventDefault(); }) - } }; }); + + /*crmMailing.directive('previewmail', function () { + return { + // Restrict it to be an attribute in this case + restrict: 'AE', + priority: 500, + // responsible for registering DOM listeners as well as updating the DOM + link: function (scope, element, attrs) { + // $(element).children(id= 'tabs') + // .tabs() + // .addClass('ui-tabs-vertical ui-helper-clearfix'); + scope.$watch('preview', function () { + console.log("asdas"); + if(scope.preview == true){ + $(element).dialog({ + title: 'Preview Mailing', + width: 800, + height: 500, + closed: false, + cache: false, + modal: true, + close :function(){console.log("close"); + scope.preview = false;scope.$apply()} + });} + }); + $(element).on("click", function () { + scope.preview_update(); + scope.$apply(); + }); + } + }; + });*/ + // Used for the select date option. This is used for giving scheduled_date its date value crmMailing.directive('chsdate',function(){ @@ -541,9 +704,23 @@ //This controller is used for creating the mailing list. Simply gets all the mailing data from civiAPI - crmMailing.controller('mailingListCtrl', function($scope, crmApi, mailingList) { + crmMailing.controller('mailingListCtrl', function($scope, crmApi, mailingList,$route) { $scope.mailingList = mailingList.values; - $scope.mailStatus = _.pluck(CRM.crmMailing.mailStatus, 'status'); + $scope.deleteMail = function (mail) { + crmApi('Mailing', 'delete', {id: mail.id}, { + error: function (data) { + CRM.alert(data.error_message, ts('Error')); + } + }) + .then(function (data) { + if (!data.is_error) { + delete mail.values[mail.id]; + $scope.$digest(); + } + }); + $route.reload(); + }; + }); })(angular, CRM.$, CRM._); diff --git a/js/angularsanitize.js b/js/angularsanitize.js new file mode 100644 index 0000000000..652d8a572a --- /dev/null +++ b/js/angularsanitize.js @@ -0,0 +1,15 @@ +/* +AngularJS v1.3.0-build.3033+sha.a001a41 +(c) 2010-2014 Google, Inc. http://angularjs.org +License: MIT +*/ +(function(q,g,r){'use strict';function F(a){var d=[];t(d,g.noop).chars(a);return d.join("")}function m(a){var d={};a=a.split(",");var c;for(c=0;c=c;e--)d.end&&d.end(f[e]);f.length=c}}"string"!==typeof a&&(a=null===a||"undefined"===typeof a?"":""+a);var b,l,f=[],n=a,h;for(f.last=function(){return f[f.length-1]};a;){h="";l=!0;if(f.last()&&y[f.last()])a=a.replace(RegExp("(.*)<\\s*\\/\\s*"+f.last()+"[^>]*>","i"),function(a,b){b=b.replace(I,"$1").replace(J,"$1");d.chars&&d.chars(s(b));return""}),e("",f.last());else{if(0===a.indexOf("\x3c!--"))b=a.indexOf("--",4),0<=b&&a.lastIndexOf("--\x3e",b)===b&&(d.comment&&d.comment(a.substring(4, +b)),a=a.substring(b+3),l=!1);else if(z.test(a)){if(b=a.match(z))a=a.replace(b[0],""),l=!1}else if(K.test(a)){if(b=a.match(A))a=a.substring(b[0].length),b[0].replace(A,e),l=!1}else L.test(a)&&((b=a.match(B))?(b[4]&&(a=a.substring(b[0].length),b[0].replace(B,c)),l=!1):(h+="<",a=a.substring(1)));l&&(b=a.indexOf("<"),h+=0>b?a:a.substring(0,b),a=0>b?"":a.substring(b),d.chars&&d.chars(s(h)))}if(a==n)throw M("badparse",a);n=a}e()}function s(a){if(!a)return"";var d=N.exec(a);a=d[1];var c=d[3];if(d=d[2])p.innerHTML= +d.replace(//g,">")}function t(a,d){var c=!1,e=g.bind(a,a.push);return{start:function(a,l,f){a=g.lowercase(a);!c&&y[a]&&(c=a);c||!0!==D[a]||(e("<"),e(a),g.forEach(l,function(c,f){var k= +g.lowercase(f),l="img"===a&&"src"===k||"background"===k;!0!==Q[k]||!0===E[k]&&!d(c,l)||(e(" "),e(f),e('="'),e(C(c)),e('"'))}),e(f?"/>":">"))},end:function(a){a=g.lowercase(a);c||!0!==D[a]||(e(""));a==c&&(c=!1)},chars:function(a){c||e(C(a))}}}var M=g.$$minErr("$sanitize"),B=/^<((?:[a-zA-Z])[\w:-]*)((?:\s+[\w:-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)\s*(>?)/,A=/^<\/\s*([\w:-]+)[^>]*>/,H=/([\w:-]+)(?:\s*=\s*(?:(?:"((?:[^"])*)")|(?:'((?:[^'])*)')|([^>\s]+)))?/g,L=/^]*?)>/i,J=/]/,c=/^mailto:/;return function(e,b){function l(a){a&&k.push(F(a))}function f(a,c){k.push("');l(c);k.push("")} +if(!e)return e;for(var n,h=e,k=[],m,p;n=h.match(d);)m=n[0],n[2]==n[3]&&(m="mailto:"+m),p=n.index,l(h.substr(0,p)),f(m,n[0].replace(c,"")),h=h.substring(p+n[0].length);l(h);return a(k.join(""))}}])})(window,window.angular); +//# sourceMappingURL=angular-sanitize.min.js.map diff --git a/partials/crmMailingType/content.html b/partials/crmMailingType/content.html index 0b1ab97db4..389e332c3c 100644 --- a/partials/crmMailingType/content.html +++ b/partials/crmMailingType/content.html @@ -25,13 +25,19 @@ Required Variables: cool_api and currentMailing and eMailing Mailing Subject - + Mailing subject required. + + + Mailing Subject Token + + + Use Template diff --git a/partials/crmMailingType/ht.html b/partials/crmMailingType/ht.html index e69b9c3bcf..a4413744e5 100644 --- a/partials/crmMailingType/ht.html +++ b/partials/crmMailingType/ht.html @@ -5,8 +5,11 @@                                                                                 - +

       

+ + + diff --git a/partials/crmMailingType/mailingList.html b/partials/crmMailingType/mailingList.html index 845c3a8527..be033fb79d 100644 --- a/partials/crmMailingType/mailingList.html +++ b/partials/crmMailingType/mailingList.html @@ -6,7 +6,7 @@ Required vars: mailingList All partially completed and completed mail are listed here - +
@@ -14,19 +14,23 @@ Required vars: mailingList + + - + - +
Mailing NameCreated By Created Date Sent ByScheduled
{{mail.name}} {{mail.from_email}} {{mail.created_date}} {{mail.from_email}}Edit + {{mail.scheduled_date}}Edit + Delete
- + diff --git a/partials/crmMailingType/main.html b/partials/crmMailingType/main.html index 73559110b8..b8c4f2ab8a 100644 --- a/partials/crmMailingType/main.html +++ b/partials/crmMailingType/main.html @@ -20,7 +20,7 @@ Submit Mailing is not functional yet
- +

@@ -29,8 +29,8 @@ Submit Mailing is not functional yet

- - + +

@@ -39,10 +39,12 @@ Submit Mailing is not functional yet

- - + +

+ diff --git a/partials/crmMailingType/plainText.html b/partials/crmMailingType/plainText.html index 0fc4087116..bb1ccd7be6 100644 --- a/partials/crmMailingType/plainText.html +++ b/partials/crmMailingType/plainText.html @@ -2,8 +2,13 @@ Controller: MailCtrl Required vars: currentMailing --> -
+                                                +                                                +                                + + +

        - +

diff --git a/partials/crmMailingType/previewMailing.html b/partials/crmMailingType/previewMailing.html index 1da937dfbd..b0e8f9730f 100644 --- a/partials/crmMailingType/previewMailing.html +++ b/partials/crmMailingType/previewMailing.html @@ -9,7 +9,7 @@ The editor has to be added. Currently just a simple text editor
-