forked from OfficeDev/outlook-add-in-command-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AllProps.js
139 lines (114 loc) · 4.53 KB
/
AllProps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE.txt in the project root for license information.
/// <reference path="../App.js" />
(function () {
"use strict";
// The Office initialize function must be run each time a new page is loaded
Office.initialize = function (reason) {
$(document).ready(function () {
app.initialize();
if (isPersistenceSupported()) {
// Set up ItemChanged event
Office.context.mailbox.addHandlerAsync(Office.EventType.ItemChanged, loadNewItem);
}
loadProps(Office.context.mailbox.item);
});
};
function isPersistenceSupported() {
// This feature is part of the preview 1.5 req set
// Since 1.5 isn't fully implemented, just check that the
// method is defined.
// Once 1.5 is implemented, we can replace this with
// Office.context.requirements.isSetSupported('Mailbox', 1.5)
return Office.context.mailbox.addHandlerAsync !== undefined;
};
function loadNewItem(eventArgs) {
loadProps(Office.context.mailbox.item);
};
// Take an array of AttachmentDetails objects and
// build a list of attachment names, separated by a line-break
function buildAttachmentsString(attachments) {
if (attachments && attachments.length > 0) {
var returnString = "";
for (var i = 0; i < attachments.length; i++) {
if (i > 0) {
returnString = returnString + "<br/>";
}
returnString = returnString + attachments[i].name;
}
return returnString;
}
return "None";
}
// Format an EmailAddressDetails object as
// GivenName Surname <emailaddress>
function buildEmailAddressString(address) {
return address.displayName + " <" + address.emailAddress + ">";
}
// Take an array of EmailAddressDetails objects and
// build a list of formatted strings, separated by a line-break
function buildEmailAddressesString(addresses) {
if (addresses && addresses.length > 0) {
var returnString = "";
for (var i = 0; i < addresses.length; i++) {
if (i > 0) {
returnString = returnString + "<br/>";
}
returnString = returnString + buildEmailAddressString(addresses[i]);
}
return returnString;
}
return "None";
}
// Load properties from a Message object
function loadMessageProps(item) {
$('#message-props').show();
$('#attachments').html(buildAttachmentsString(item.attachments));
$('#cc').html(buildEmailAddressesString(item.cc));
$('#conversationId').text(item.conversationId);
$('#from').html(buildEmailAddressString(item.from));
$('#internetMessageId').text(item.internetMessageId);
$('#normalizedSubject').text(item.normalizedSubject);
$('#sender').html(buildEmailAddressString(item.sender));
$('#subject').text(item.subject);
$('#to').html(buildEmailAddressesString(item.to));
}
// Load properties from an Appointment object
function loadAppointmentProps(item) {
$('#appointment-props').show();
$('#appt-attachments').html(buildAttachmentsString(item.attachments));
$('#end').text(item.end.toLocaleString());
$('#location').text(item.location);
$('#appt-normalizedSubject').text(item.normalizedSubject);
$('#optionalAttendees').html(buildEmailAddressesString(item.optionalAttendees));
$('#organizer').html(buildEmailAddressString(item.organizer));
$('#requiredAttendees').html(buildEmailAddressesString(item.requiredAttendees));
$('#resources').html(buildEmailAddressesString(item.resources));
$('#start').text(item.start.toLocaleString());
$('#appt-subject').text(item.subject);
}
// Load properties from the Item base object, then load the
// type-specific properties.
function loadProps(item) {
$('#dateTimeCreated').text(item.dateTimeCreated.toLocaleString());
$('#dateTimeModified').text(item.dateTimeModified.toLocaleString());
$('#itemClass').text(item.itemClass);
$('#itemId').text(item.itemId);
$('#itemType').text(item.itemType);
item.body.getAsync('html', function(result){
if (result.status === 'succeeded') {
$('#bodyHtml').text(result.value);
}
});
item.body.getAsync('text', function(result){
if (result.status === 'succeeded') {
$('#bodyText').text(result.value);
}
});
if (item.itemType == Office.MailboxEnums.ItemType.Message){
loadMessageProps(item);
}
else {
loadAppointmentProps(item);
}
}
})();