(js) New sgCompile directive to render mail parts
parent
9ed65e34ad
commit
f27544c72c
|
@ -107,9 +107,9 @@
|
||||||
<div class="msg-date sg-md-body-multi">
|
<div class="msg-date sg-md-body-multi">
|
||||||
<time datetime="message.date" ng-bind="message.date"><!-- date --></time>
|
<time datetime="message.date" ng-bind="message.date"><!-- date --></time>
|
||||||
</div>
|
</div>
|
||||||
<div class="mailer_mailcontent">
|
<div class="mailer_mailcontent" ng-repeat="part in message.$content()">
|
||||||
<div ng-repeat="part in message.$content()"
|
<div ng-if="part.html" ng-bind-html="part.content"><!-- msg --></div>
|
||||||
ng-bind-html="part.content"><!-- msg --></div>
|
<div ng-if="part.compile" sg-compile="part.content"><!-- msg --></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</md-content>
|
</md-content>
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* sgCompile - Assign an expression to a DOM element and compile it.
|
||||||
|
* @memberof SOGo.Common
|
||||||
|
* @restrict attribute
|
||||||
|
* @param {object} sgCompile - the expression to compile
|
||||||
|
* @ngInject
|
||||||
|
* @example:
|
||||||
|
|
||||||
|
<div sg-compile="part.content"><!-- msg --></div>
|
||||||
|
*/
|
||||||
|
sgCompile.$inject = ['$compile'];
|
||||||
|
function sgCompile($compile) {
|
||||||
|
return {
|
||||||
|
restrict: 'A',
|
||||||
|
link: sgCompileLink
|
||||||
|
};
|
||||||
|
|
||||||
|
function sgCompileLink(scope, element, attrs) {
|
||||||
|
var ensureCompileRunsOnce = scope.$watch(
|
||||||
|
function(scope) {
|
||||||
|
// Watch the sg-compile expression for changes
|
||||||
|
return scope.$eval(attrs.sgCompile);
|
||||||
|
},
|
||||||
|
function(value) {
|
||||||
|
// When the sg-compile expression changes, assign it into the current DOM
|
||||||
|
element.html(value);
|
||||||
|
|
||||||
|
// Compile the new DOM and link it to the current scope.
|
||||||
|
// NOTE: we only compile .childNodes so that we don't get into infinite loop compiling ourselves
|
||||||
|
$compile(element.contents())(scope);
|
||||||
|
|
||||||
|
// Use un-watch feature to ensure compilation happens only once.
|
||||||
|
ensureCompileRunsOnce();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
angular
|
||||||
|
.module('SOGo.Common')
|
||||||
|
.directive('sgCompile', sgCompile);
|
||||||
|
})();
|
|
@ -166,7 +166,7 @@
|
||||||
var _this = this,
|
var _this = this,
|
||||||
parts = [],
|
parts = [],
|
||||||
_visit = function(part) {
|
_visit = function(part) {
|
||||||
if (part.type == "UIxMailPartAlternativeViewer") {
|
if (part.type == 'UIxMailPartAlternativeViewer') {
|
||||||
_visit(_.find(part.content, function(alternatePart) {
|
_visit(_.find(part.content, function(alternatePart) {
|
||||||
return part.preferredPart == alternatePart.contentType;
|
return part.preferredPart == alternatePart.contentType;
|
||||||
}));
|
}));
|
||||||
|
@ -182,7 +182,8 @@
|
||||||
part.safeContent = part.content;
|
part.safeContent = part.content;
|
||||||
_this.$hasUnsafeContent = (part.safeContent.indexOf(' unsafe-') > -1);
|
_this.$hasUnsafeContent = (part.safeContent.indexOf(' unsafe-') > -1);
|
||||||
}
|
}
|
||||||
if (part.type == "UIxMailPartHTMLViewer") {
|
if (part.type == 'UIxMailPartHTMLViewer') {
|
||||||
|
part.html = true;
|
||||||
if (_this.$loadUnsafeContent) {
|
if (_this.$loadUnsafeContent) {
|
||||||
if (angular.isUndefined(part.unsafeContent)) {
|
if (angular.isUndefined(part.unsafeContent)) {
|
||||||
part.unsafeContent = document.createElement('div');
|
part.unsafeContent = document.createElement('div');
|
||||||
|
@ -207,7 +208,14 @@
|
||||||
}
|
}
|
||||||
parts.push(part);
|
parts.push(part);
|
||||||
}
|
}
|
||||||
|
else if (part.type == 'UIxMailPartICalViewer' ||
|
||||||
|
part.type == 'UIxMailPartLinkViewer') {
|
||||||
|
// Trusted content that can be compiled (Angularly-speaking)
|
||||||
|
part.compile = true;
|
||||||
|
parts.push(part);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
|
part.html = true;
|
||||||
part.content = Message.$sce.trustAs('html', part.safeContent);
|
part.content = Message.$sce.trustAs('html', part.safeContent);
|
||||||
parts.push(part);
|
parts.push(part);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue