fixed editable variables in textAngular editor
This commit is contained in:
parent
72b3e31819
commit
15d023c133
|
@ -1,7 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
const constants = require('./constants');
|
||||
|
||||
module.exports = {
|
||||
send: function(emailSettings, emailTemplateVars, smtpTransport, varFormat, cb){
|
||||
var parsedTemplate = this.parseTemplate(emailSettings.htmlTemplate, emailTemplateVars, varFormat);
|
||||
|
@ -14,7 +12,11 @@ module.exports = {
|
|||
html: parsedTemplate
|
||||
};
|
||||
|
||||
smtpTransport.sendMail(mailOptions, cb);
|
||||
console.log('HERE');
|
||||
smtpTransport.sendMail(mailOptions, function(){
|
||||
console.log('THERE');
|
||||
cb();
|
||||
});
|
||||
},
|
||||
|
||||
parseTemplate: function(emailTemplate, emailAttrs, varFormat){
|
||||
|
|
|
@ -3,35 +3,37 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var emailNotifications = require('../../libs/send-email-notifications'),
|
||||
constants = require('../../libs/constants');
|
||||
const emailNotifications = require('../../libs/send-email-notifications'),
|
||||
constants = require('../../libs/constants'),
|
||||
mockTransport = require("nodemailer").createTransport("Stub"),
|
||||
config = require('../../../config/config');
|
||||
|
||||
/**
|
||||
* Globals
|
||||
*/
|
||||
var validFormFields = [
|
||||
const validFormFields = [
|
||||
{fieldType:'textfield', title:'First Name', fieldValue: 'John Smith', deletePreserved: false, globalId:'56340745f59a6fc9e22028e9'},
|
||||
{fieldType:'link', title:'Your Website', fieldValue: 'https://johnsmith.me', deletePreserved: false, globalId:'5c9e22028e907634f45f59a6'},
|
||||
{fieldType:'number', title:'Your Age', fieldValue: 45, deletePreserved: false, globalId:'56e90745f5934fc9e22028a6'}
|
||||
];
|
||||
|
||||
var validFieldDict = {
|
||||
const validFieldDict = {
|
||||
'56340745f59a6fc9e22028e9': 'John Smith',
|
||||
'5c9e22028e907634f45f59a6': 'https://johnsmith.me',
|
||||
'56e90745f5934fc9e22028a6': 45
|
||||
};
|
||||
|
||||
var invalidFormFields = [
|
||||
const invalidFormFields = [
|
||||
{fieldType:'textfield', title:'First Name', fieldValue: 'John Smith', deletePreserved: false},
|
||||
{fieldType:'link', title:'Your Website', deletePreserved: false, _id:'5c9e22028e907634f45f59a6'},
|
||||
{fieldType:'number', title:'Your Age'}
|
||||
];
|
||||
|
||||
var htmlTemplate = '<p><var class="tag" id="field:56340745f59a6fc9e22028e9">First Name</var> \
|
||||
const htmlTemplate = '<p><var class="tag" id="field:56340745f59a6fc9e22028e9">First Name</var> \
|
||||
<br><var class="tag" id="field:5c9e22028e907634f45f59a6">Your Website</var> \
|
||||
<br><var class="tag" id="field:56e90745f5934fc9e22028a6">Your Age</var></p>';
|
||||
|
||||
var renderedTemplate = '<p>John Smith \
|
||||
const renderedTemplate = '<p>John Smith \
|
||||
<br>https://johnsmith.me \
|
||||
<br>45</p>';
|
||||
|
||||
|
@ -53,14 +55,14 @@ describe('Send Email Notification Unit Tests', function() {
|
|||
});
|
||||
|
||||
describe('Method parseTemplate', function(){
|
||||
it('should be properly render a template given a valid field dict', function() {
|
||||
it('should properly render a template given a valid field dict', function() {
|
||||
var actualRenderedTemplate = emailNotifications.parseTemplate(htmlTemplate, validFieldDict, constants.varFormat).replace((/ |\r\n|\n|\r|\t/gm),'');
|
||||
actualRenderedTemplate.should.equal(renderedTemplate.replace((/ |\r\n|\n|\r|\t/gm),''));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Method replaceTemplateVal', function() {
|
||||
it('should be properly replace a template var in a valid template', function() {
|
||||
it('should properly replace a template var in a valid template', function() {
|
||||
var expectedHtml = '<p>John Smith \
|
||||
<br><var class="tag" id="field:5c9e22028e907634f45f59a6">Your Website</var> \
|
||||
<br><var class="tag" id="field:56e90745f5934fc9e22028a6">Your Age</var></p>';
|
||||
|
@ -71,5 +73,22 @@ describe('Send Email Notification Unit Tests', function() {
|
|||
});
|
||||
|
||||
describe('Method send', function() {
|
||||
this.timeout(10000);
|
||||
const emailSettings = {
|
||||
fromEmails: 'somewhere@somewhere.com',
|
||||
toEmails: 'there@there.com',
|
||||
subject: 'Hello <var class="tag" id="field:56340745f59a6fc9e22028e9">First Name</var>!',
|
||||
htmlTemplate: htmlTemplate
|
||||
};
|
||||
|
||||
const emailTemplateVars = validFieldDict;
|
||||
const varFormat = constants.varFormat;
|
||||
|
||||
it('should properly replace a template var in a valid template', function(done) {
|
||||
emailNotifications.send(emailSettings, emailTemplateVars, mockTransport, varFormat, function(err){
|
||||
should.not.exist(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
12851
package-lock.json
generated
Normal file
12851
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -42,7 +42,7 @@
|
|||
"express": "~4.13.3",
|
||||
"express-session": "~1.12.1",
|
||||
"glob": "^7.0.3",
|
||||
"grunt": "~0.4.1",
|
||||
"grunt": "^0.4.5",
|
||||
"grunt-concurrent": "~2.3.0",
|
||||
"grunt-contrib-csslint": "~1.0.0",
|
||||
"grunt-contrib-cssmin": "~1.0.1",
|
||||
|
|
2
public/dist/application.js
vendored
2
public/dist/application.js
vendored
|
@ -890,8 +890,6 @@ angular.module('view-form').directive('submitFormDirective', ["$http", "TimeCoun
|
|||
};
|
||||
|
||||
$rootScope.prevField = $scope.prevField = function(){
|
||||
console.log('prevField');
|
||||
console.log($scope.selected);
|
||||
var selected_index = $scope.selected.index - 1;
|
||||
if($scope.selected.index > 0){
|
||||
$scope.setActiveField(null, selected_index, true);
|
||||
|
|
4
public/dist/application.min.css
vendored
4
public/dist/application.min.css
vendored
File diff suppressed because one or more lines are too long
2
public/dist/application.min.js
vendored
2
public/dist/application.min.js
vendored
File diff suppressed because one or more lines are too long
31
public/dist/vendor.min.js
vendored
31
public/dist/vendor.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -14,6 +14,10 @@ angular.module('forms').directive('configureFormDirective', ['$rootScope', '$fil
|
|||
$scope.resetForm = $rootScope.resetForm;
|
||||
$scope.update = $rootScope.update;
|
||||
|
||||
$scope.$evalAsync(function() {
|
||||
angular.element('.tag')
|
||||
});
|
||||
|
||||
$scope.languages = ['en', 'fr', 'es', 'it', 'de'];
|
||||
|
||||
$scope.langCodeToWord = {
|
||||
|
|
|
@ -59,7 +59,9 @@
|
|||
<h5>{{ 'EMAIL_SUBJECT' | translate }}:</h5>
|
||||
</div>
|
||||
<div class="col-sm-12 field-input">
|
||||
<text-angular class="email-subject" ng-model="myform.respondentNotifications.subject" ta-toolbar="[['insertField']]" ta-default-wrap="n"></text-angular>
|
||||
<text-angular class="email-subject" ng-model="myform.respondentNotifications.subject" ta-toolbar="[['insertField']]" ta-default-wrap="n"
|
||||
ta-default-tag-attributes="{ var: {contenteditable:'true'}" ta-unsafe-sanitizer="true">
|
||||
</text-angular>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -69,7 +71,9 @@
|
|||
</div>
|
||||
|
||||
<div class="col-sm-12 field-input">
|
||||
<text-angular class="email-subject" ng-model="myform.respondentNotifications.htmlTemplate" ta-toolbar="[['bold','italics', 'insertField']]"></text-angular>
|
||||
<text-angular class="email-subject" ng-model="myform.respondentNotifications.htmlTemplate" ta-toolbar="[['bold','italics', 'insertField']]"
|
||||
ta-default-tag-attributes="{ var: {contenteditable:'true'}" ta-unsafe-sanitizer="true"
|
||||
></text-angular>
|
||||
<div ng-bind="myform.respondentNotifications.htmlTemplate"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -56,7 +56,8 @@
|
|||
</div>
|
||||
|
||||
<div class="col-sm-12 field-input">
|
||||
<text-angular class="email-subject" ng-model="myform.selfNotifications.subject" ta-toolbar="[['insertField']]" ta-default-wrap="n"></text-angular>
|
||||
<text-angular class="email-subject" ng-model="myform.selfNotifications.subject" ta-toolbar="[['insertField']]"
|
||||
ta-default-tag-attributes="{ var: {contenteditable:'true'}" ta-unsafe-sanitizer=true"ta-default-wrap="n"></text-angular>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -66,7 +67,7 @@
|
|||
</div>
|
||||
|
||||
<div class="col-sm-12 field-input">
|
||||
<text-angular ng-model="myform.selfNotifications.htmlTemplate" ta-toolbar="[['bold','italics', 'insertField']]"></text-angular>
|
||||
<text-angular ng-model="myform.selfNotifications.htmlTemplate" ta-toolbar="[['bold','italics', 'insertField']]" ta-default-tag-attributes="{ var: {contenteditable:'true'}" ta-unsafe-sanitizer="true"></text-angular>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -70,12 +70,16 @@ angular.module('forms').run(['Menus',
|
|||
</ul>\
|
||||
</div>',
|
||||
onClickField: function(field_id, field_name){
|
||||
this.$editor().wrapSelection('insertHTML', '<var class="tag" contenteditable="false" ta-readonly="true" id="field:' + field_id + '">' + field_name + '</var>', false);
|
||||
this.$editor().wrapSelection('insertHTML', '<var class="tag" contenteditable="false" id="field:' + field_id + '">' + field_name + '</var>', false);
|
||||
},
|
||||
action: function(){
|
||||
}
|
||||
});
|
||||
|
||||
taOptions.defaultTagAttributes['var'] = {
|
||||
'contenteditable': 'false'
|
||||
};
|
||||
|
||||
return taOptions;
|
||||
}]);
|
||||
}]);
|
|
@ -12,7 +12,6 @@ angular.module('forms').factory('GetForms', ['$resource', 'FORM_URL',
|
|||
},
|
||||
'get' : {
|
||||
method: 'GET',
|
||||
isArray: true,
|
||||
transformResponse: function(data, header) {
|
||||
var form = angular.fromJson(data);
|
||||
|
||||
|
|
Loading…
Reference in a new issue