forked from OfficeDev/outlook-add-in-command-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskPane.js
143 lines (117 loc) · 4.98 KB
/
TaskPane.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
140
141
142
143
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file.
/// <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();
loadProps();
});
};
// 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() {
var item = Office.context.mailbox.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);
}
}
})();
// MIT License:
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// ""Software""), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.