Skip to content

Commit

Permalink
[Outlook] (event-based activation) Remove platform check from samples (
Browse files Browse the repository at this point in the history
…#846)

* Remove platform check

* Remove additional instance
  • Loading branch information
samantharamon authored Sep 12, 2024
1 parent 6b10ae0 commit 4504ebb
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 76 deletions.
4 changes: 2 additions & 2 deletions Samples/outlook-encrypt-attachments/src/commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function onAppointmentAttendeesChangedHandler(event) {
* Method that fires when an attachment is being added or removed from the compose email or appointment
* @param {Office.AsyncResult} event default: Office.AsyncResult
*/
function onItemAttachmentsChangedHandler(event) {
function onItemAttachmentsChangedHandler(event) {
if (Office.context.platform !== Office.PlatformType.OfficeOnline){
console.warn(`onItemAttachmentsChangedHandler(): Unsupported platform for encrypting/decrypting attachments (${Office.context.platform}); leaving...`);
event.completed();
Expand Down Expand Up @@ -546,7 +546,7 @@ function onAppointmentTimeChangedHandler(event) {
console.error(`onAppointmentTimeChangedHandler(): Action failed with message ${asyncResult.error.message}`);
event.completed();
}
});
});
}

// 1st parameter: FunctionName of LaunchEvent in the manifest; 2nd parameter: Its implementation in this .js file.
Expand Down
1 change: 1 addition & 0 deletions Samples/outlook-spam-reporting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,6 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
| ----- | ----- | ----- |
| 1.0 | March 26, 2024 | Initial release |
| 1.1 | July 1, 2024 | Create separate JavaScript files for supported clients |
| 1.2 | September 11, 2024 | Correct the `Office.actions.associate` call and consolidate the JavaScript files |

<img src="https://pnptelemetry.azurewebsites.net/pnp-officeaddins/samples/outlook-spam-reporting" />
2 changes: 1 addition & 1 deletion Samples/outlook-spam-reporting/manifest-localhost.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
</bt:Images>
<bt:Urls>
<bt:Url id="WebViewRuntime.Url" DefaultValue="https://localhost:3000/src/spamreporting.html"/>
<bt:Url id="JSRuntime.Url" DefaultValue="https://localhost:3000/src/spamreporting_classic.js"/>
<bt:Url id="JSRuntime.Url" DefaultValue="https://localhost:3000/src/spamreporting.js"/>
<bt:Url id="MoreInfo.Url" DefaultValue="https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/spam-reporting"/>
</bt:Urls>
<bt:ShortStrings>
Expand Down
2 changes: 1 addition & 1 deletion Samples/outlook-spam-reporting/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
</bt:Images>
<bt:Urls>
<bt:Url id="WebViewRuntime.Url" DefaultValue="https://officedev.github.io/Office-Add-in-samples/Samples/outlook-spam-reporting/src/spamreporting.html"/>
<bt:Url id="JSRuntime.Url" DefaultValue="https://officedev.github.io/Office-Add-in-samples/Samples/outlook-spam-reporting/src/spamreporting_classic.js"/>
<bt:Url id="JSRuntime.Url" DefaultValue="https://officedev.github.io/Office-Add-in-samples/Samples/outlook-spam-reporting/src/spamreporting.js"/>
<bt:Url id="MoreInfo.Url" DefaultValue="https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/spam-reporting"/>
</bt:Urls>
<bt:ShortStrings>
Expand Down
6 changes: 6 additions & 0 deletions Samples/outlook-spam-reporting/src/spamreporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ function onSpamReport(event) {
}
);
}

/**
* IMPORTANT: To ensure your add-in is supported in Outlook, remember to map the event handler name
* specified in the manifest to its JavaScript counterpart.
*/
Office.actions.associate("onSpamReport", onSpamReport);
52 changes: 0 additions & 52 deletions Samples/outlook-spam-reporting/src/spamreporting_classic.js

This file was deleted.

13 changes: 5 additions & 8 deletions Samples/outlook-verify-sensitivity-label/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,15 @@ The **\<LaunchEvents\>** element maps the three events that activate the add-in

### Configure the event handlers

The event object is passed to its respective handler in the **commands.js** file for processing. To ensure that the event-based add-in runs in classic Outlook on Windows, the JavaScript file that contains your handlers (in this case, **commands.js**) must call `Office.actions.associate`. This method maps the function ID specified in the manifest to its respective event handler in the JavaScript file.
The event object is passed to its respective handler in the **commands.js** file for processing. To ensure that the event-based add-in runs in Outlook, the JavaScript file that contains your handlers (in this case, **commands.js**) must call `Office.actions.associate`. This method maps the function ID specified in the manifest to its respective event handler in the JavaScript file.

```javascript
/**
* Maps the event handler name specified in the manifest's LaunchEvent element to its JavaScript counterpart.
* This ensures support in classic Outlook on Windows.
* Maps the event handler name specified in the manifest to its JavaScript counterpart.
*/
if (Office.context.platform === Office.PlatformType.PC || Office.context.platform == null) {
Office.actions.associate("onMessageRecipientsChangedHandler", onMessageRecipientsChangedHandler);
Office.actions.associate("onMessageSendHandler", onMessageSendHandler);
Office.actions.associate("onSensitivityLabelChangedHandler", onSensitivityLabelChangedHandler);
}
Office.actions.associate("onMessageRecipientsChangedHandler", onMessageRecipientsChangedHandler);
Office.actions.associate("onMessageSendHandler", onMessageSendHandler);
Office.actions.associate("onSensitivityLabelChangedHandler", onSensitivityLabelChangedHandler);
```

The handler calls the [event.completed](https://learn.microsoft.com/javascript/api/outlook/office.mailboxevent#outlook-office-mailboxevent-completed-member(1)) method to signify when it completes processing an event. In the `onMessageSendHandler` function, the `event.completed` call specifies the [allowEvent](https://learn.microsoft.com/javascript/api/outlook/office.smartalertseventcompletedoptions#outlook-office-smartalertseventcompletedoptions-allowevent-member) property to indicate whether the event can continue to execute or must terminate. It also specifies the [errorMessage](https://learn.microsoft.com/javascript/api/outlook/office.smartalertseventcompletedoptions#outlook-office-smartalertseventcompletedoptions-errormessage-member) property to display the Smart Alerts dialog to indicate that the sensitivity label was updated.
Expand Down
21 changes: 9 additions & 12 deletions Samples/outlook-verify-sensitivity-label/src/commands/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@
/**
* Ensures the Office.js library is loaded.
*/
Office.onReady((info) => {
/**
* Maps the event handler name specified in the manifest's LaunchEvent element to its JavaScript counterpart.
* This ensures support in Outlook on Windows.
*/
if (Office.context.platform === Office.PlatformType.PC || Office.context.platform == null) {
Office.actions.associate("onMessageRecipientsChangedHandler", onMessageRecipientsChangedHandler);
Office.actions.associate("onMessageSendHandler", onMessageSendHandler);
Office.actions.associate("onSensitivityLabelChangedHandler", onSensitivityLabelChangedHandler);
}
});
Office.onReady();

/**
* The legal hold email account of the fictitious company, Fabrikam. It's added to the Bcc field of a
Expand Down Expand Up @@ -334,4 +324,11 @@ function containsLegalTeamMember(recipients) {
}

return false;
}
}

/**
* Maps the event handler name specified in the manifest to its JavaScript counterpart.
*/
Office.actions.associate("onMessageRecipientsChangedHandler", onMessageRecipientsChangedHandler);
Office.actions.associate("onMessageSendHandler", onMessageSendHandler);
Office.actions.associate("onSensitivityLabelChangedHandler", onSensitivityLabelChangedHandler);

0 comments on commit 4504ebb

Please sign in to comment.