-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskpane.js
More file actions
70 lines (60 loc) · 2.22 KB
/
taskpane.js
File metadata and controls
70 lines (60 loc) · 2.22 KB
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
Office.onReady(async (info) => {
if (info.host === Office.HostType.Outlook) {
document.getElementById('create-task').onclick = createPlannerTask;
await loadPlannerLists();
await loadRelatedTasks();
}
});
async function loadPlannerLists() {
const plannerLists = await graphAPI('/me/planner/plans');
const dropdown = document.getElementById('planner-list');
plannerLists.value.forEach(plan => {
const option = document.createElement('option');
option.value = plan.id;
option.textContent = plan.title;
dropdown.appendChild(option);
});
}
async function createPlannerTask() {
const planId = document.getElementById('planner-list').value;
const email = Office.context.mailbox.item;
const task = {
planId: planId,
title: email.subject,
assignments: {},
details: {
description: `Von E-Mail: ${email.internetMessageId}`
}
};
const createdTask = await graphAPI(`/planner/tasks`, 'POST', task);
email.body.setAsync(`<p>Planner Task ID: ${createdTask.id}</p>`, { coercionType: Office.CoercionType.Html });
alert(`Aufgabe erstellt: ${createdTask.title}`);
}
async function loadRelatedTasks() {
const email = Office.context.mailbox.item;
const tasks = await graphAPI('/me/planner/tasks');
const relatedTasks = tasks.value.filter(task => task.details.description.includes(email.internetMessageId));
const list = document.getElementById('related-tasks');
list.innerHTML = '';
relatedTasks.forEach(task => {
const li = document.createElement('li');
li.textContent = task.title;
list.appendChild(li);
});
}
async function graphAPI(endpoint, method = 'GET', body = null) {
const token = await Office.context.auth.getAccessTokenAsync();
const headers = {
'Authorization': `Bearer ${token.value}`,
'Content-Type': 'application/json'
};
const response = await fetch(`https://graph.microsoft.com/v1.0${endpoint}`, {
method,
headers,
body: body ? JSON.stringify(body) : null
});
if (!response.ok) {
throw new Error(`Graph API call failed: ${response.statusText}`);
}
return response.json();
}