MailHog/mailhog/templates/js/controllers.go

87 lines
1.9 KiB
Go
Raw Normal View History

2014-04-20 14:35:59 +00:00
package js
func Controllers() string {
return `
var mailhogApp = angular.module('mailhogApp', []);
2014-04-21 21:32:34 +00:00
mailhogApp.controller('MailCtrl', function ($scope, $http, $sce) {
2014-04-20 14:35:59 +00:00
$scope.refresh = function() {
$http.get('/api/v1/messages').success(function(data) {
$scope.messages = data;
});
}
$scope.refresh();
2014-04-21 21:32:34 +00:00
$scope.getMessagePlain = function(message) {
var part;
if(message.MIME) {
for(var p in message.MIME.Parts) {
if(message.MIME.Parts[p].Headers["Content-Type"][0] == "text/plain") {
part = message.MIME.Parts[p];
break;
}
}
}
if(!part) part = message.Content;
return part.Body;
}
$scope.getMessageHTML = function(message) {
var part;
if(message.MIME) {
for(var p in message.MIME.Parts) {
if(message.MIME.Parts[p].Headers["Content-Type"][0] == "text/html") {
part = message.MIME.Parts[p];
break;
}
}
}
if(!part) part = message.Content;
return part.Body;
}
2014-04-20 14:35:59 +00:00
$scope.date = function(timestamp) {
return (new Date(timestamp)).toString();
};
$scope.selectMessage = function(message) {
2014-04-21 21:32:34 +00:00
$scope.previewHTML = $sce.trustAsHtml($scope.getMessageHTML(message));
2014-04-20 14:35:59 +00:00
$scope.preview = message;
}
$scope.deleteAll = function() {
$('#confirm-delete-all').modal('show');
}
2014-04-20 19:13:39 +00:00
$scope.getSource = function(message) {
var source = "";
$.each(message.Content.Headers, function(k, v) {
source += k + ": " + v + "\n";
});
source += "\n";
source += message.Content.Body;
return source;
}
2014-04-20 14:35:59 +00:00
$scope.deleteAllConfirm = function() {
$('#confirm-delete-all').modal('hide');
$http.post('/api/v1/messages/delete').success(function() {
$scope.refresh();
$scope.preview = null;
});
}
$scope.deleteOne = function(message) {
2014-04-20 16:09:06 +00:00
$http.post('/api/v1/messages/' + message.Id + '/delete').success(function() {
2014-04-20 14:35:59 +00:00
if($scope.preview._id == message._id) $scope.preview = null;
$scope.refresh();
});
}
});
`;
}