92 lines
4.0 KiB
JavaScript
92 lines
4.0 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('myitsmApp')
|
|
.factory('emailModel', ['attachmentService', 'feedModel', 'userModel', 'systemAlertService', function (attachmentService, feedModel, userModel, systemAlertService) {
|
|
var emailModel = {
|
|
emailInstances: []
|
|
};
|
|
emailModel.createEmail = function (ticketData, recipients) {
|
|
var emailWindow = emailModel.createEmailWindowInstance(ticketData, recipients);
|
|
emailModel.emailInstances.push(emailWindow);
|
|
};
|
|
emailModel.createEmailWindowInstance = function (ticketData, recipients) {
|
|
var emailWindow = new EmailWindowVO(), buildData = {};
|
|
if (ticketData) {
|
|
buildData.ticketData = ticketData;
|
|
if (recipients) {
|
|
buildData.senderList = recipients;
|
|
}
|
|
emailWindow.build(buildData);
|
|
}
|
|
return emailWindow;
|
|
};
|
|
emailModel.deleteEmailWindow = function (emailWindow) {
|
|
var index = emailModel.emailInstances.indexOf(emailWindow);
|
|
if (index >= 0) {
|
|
emailModel.emailInstances.splice(index, 1);
|
|
}
|
|
};
|
|
emailModel.addAttachment = function (fileInput) {
|
|
return attachmentService.prepareFileToUpload({ fileInput: fileInput });
|
|
};
|
|
emailModel.sendEmail = function (email, internalRecip, externalRecip) {
|
|
var entity, request = {
|
|
worknote: email.messageBody,
|
|
access: true,
|
|
'Email.From.Person': {
|
|
email: userModel.userFullData.email,
|
|
fullName: userModel.userFullData.fullName,
|
|
loginId: userModel.userFullData.loginId
|
|
},
|
|
'Email.Subject': email.subjectText,
|
|
'Email.Body': email.messageBody
|
|
};
|
|
if (email.attachment) {
|
|
request.attachments = [email.attachment];
|
|
}
|
|
if (externalRecip) {
|
|
var externalEmailsList = _.map(externalRecip, 'email');
|
|
request['Email.To.InternetEmail'] = externalEmailsList.join(';');
|
|
}
|
|
if (internalRecip && internalRecip.length) {
|
|
internalRecip = _.map(internalRecip, function (recip) {
|
|
return { email: recip.email, loginId: recip.loginId, fullName: recip.fullName };
|
|
});
|
|
request['Email.To.Person'] = internalRecip;
|
|
}
|
|
if (email.kba) {
|
|
request.articleId = email.kba.id;
|
|
request.articleDisplayId = email.kba.displayId;
|
|
request.attachmentType = "pdf";
|
|
}
|
|
if (email.ticketList) {
|
|
if (email.attachment) {
|
|
_.forEach(email.ticketList, function (ticket) {
|
|
ticket.workNoteType = FeedItemVO.WORK_INFO_TYPES[ticket.type];
|
|
});
|
|
}
|
|
request.ticketList = email.ticketList;
|
|
var promise = feedModel.saveNoteBulk(request);
|
|
promise.catch(function (err) {
|
|
systemAlertService.error({
|
|
text: err.data.error,
|
|
clear: false
|
|
});
|
|
});
|
|
return promise;
|
|
}
|
|
else {
|
|
entity = {
|
|
type: email.ticketType,
|
|
id: email.ticketId
|
|
};
|
|
request.workInfoType = FeedItemVO.WORK_INFO_TYPES[email.ticketType];
|
|
return feedModel.saveNote(entity, request);
|
|
}
|
|
};
|
|
return emailModel;
|
|
}
|
|
]);
|
|
}());
|