forked from OfficeDev/outlook-add-in-command-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NoCommands.js
57 lines (47 loc) · 1.72 KB
/
NoCommands.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
// 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 initialize function must be run each time a new page is loaded
Office.initialize = function (reason) {
$(document).ready(function () {
app.initialize();
$('#insertDefault').click(insertDefault);
$('#insertMsg1').click(insertMsg1);
$('#insertMsg2').click(insertMsg2);
$('#insertMsg3').click(insertMsg3);
$('#insertCustom').click(insertCustom);
});
};
function insertText(textToInsert) {
// Insert as plain text (CoercionType.Text)
Office.context.mailbox.item.body.setSelectedDataAsync(
textToInsert,
{ coercionType: Office.CoercionType.Text },
function (asyncResult) {
// Display the result to the user
if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
app.showNotification("Success", "\"" + textToInsert + "\" inserted successfully.");
}
else {
app.showNotification("Error", "Failed to insert \"" + textToInsert + "\": " + asyncResult.error.message);
}
});
}
function insertDefault() {
insertText("Inserted by the Add-in Command Demo add-in.");
}
function insertMsg1() {
insertText("Hello World!");
}
function insertMsg2() {
insertText("Add-in commands are cool!");
}
function insertMsg3() {
insertText("Visit https://developer.microsoft.com/en-us/outlook/ today for all of your add-in development needs.");
}
function insertCustom() {
var textToInsert = $('#textToInsert').val();
insertText(textToInsert);
}
})();