From 40508581810709e57989f2c613444b95257779c8 Mon Sep 17 00:00:00 2001 From: Jason Johnston Date: Mon, 6 Feb 2017 14:32:13 -0500 Subject: [PATCH] Added iOS view of the REST pane --- RestCaller/RestCaller.html | 170 +++++++++---------- RestCaller/mobile/RestCaller-ios.css | 23 +++ RestCaller/mobile/RestCaller-ios.html | 155 +++++++++++++++++ RestCaller/mobile/RestCaller-ios.js | 214 ++++++++++++++++++++++++ RestCaller/mobile/RestCallerMobile.html | 38 +++++ RestCaller/mobile/RestCallerMobile.js | 11 ++ command-demo-manifest.xml | 3 +- package.json | 11 +- 8 files changed, 535 insertions(+), 90 deletions(-) create mode 100644 RestCaller/mobile/RestCaller-ios.css create mode 100644 RestCaller/mobile/RestCaller-ios.html create mode 100644 RestCaller/mobile/RestCaller-ios.js create mode 100644 RestCaller/mobile/RestCallerMobile.html create mode 100644 RestCaller/mobile/RestCallerMobile.js diff --git a/RestCaller/RestCaller.html b/RestCaller/RestCaller.html index 139ed0a..a2c3bb3 100644 --- a/RestCaller/RestCaller.html +++ b/RestCaller/RestCaller.html @@ -35,103 +35,103 @@ REST details -
-
-
-
- -
-
-
-
- Loading... -
+
+
+
+
+ +
+
+
+
+ Loading...
-
+
-
-
-
-
-
- - - -
-
-
Choose a change...
-
-
-
-
- -
-
-
-
- Loading... -
+
+
+
+
+
+
+ + + +
+
+
Choose a change...
+
+
+
+
+ +
+
+
+
+ Loading...
-
+
-
-
- - - - - - - - - - - - - - - - - - - - -
Diagnostic fieldValue
hostName
hostVersion
OWAView
+
+
+
+ + + + + + + + + + + + + + + + + + + + +
Diagnostic fieldValue
hostName
hostVersion
OWAView
+
+
+
Access Token
+
+ Parse token + +
-
-
Access Token
-
- Parse token - - -
-
-
loading...
-
+
+
loading...
-
-
REST URL to item
-
-
loading...
-
+
+
+
REST URL to item
+
+
loading...
+
diff --git a/RestCaller/mobile/RestCaller-ios.css b/RestCaller/mobile/RestCaller-ios.css new file mode 100644 index 0000000..b9d2740 --- /dev/null +++ b/RestCaller/mobile/RestCaller-ios.css @@ -0,0 +1,23 @@ +.content-main { + padding: 10px; +} + +.code-box > pre { + background-color: #eaeaea; + border: 1px solid #ccc; + padding: 5px 10px; + word-wrap: break-word; + white-space: pre-wrap; +} + +.get-item-button, .update-item-button { + width: 100%; +} + +.token-view { + margin-top: 10px; +} + +.ms-Spinner { + display: none; +} \ No newline at end of file diff --git a/RestCaller/mobile/RestCaller-ios.html b/RestCaller/mobile/RestCaller-ios.html new file mode 100644 index 0000000..813ae75 --- /dev/null +++ b/RestCaller/mobile/RestCaller-ios.html @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
Get item
+
+

Get Item

+
+
+
+
+
+
+
+
+
+
+
+
+
Change current item
+
+
    +
  • +
    +
    +
    + +
    +
    +
    +
  • +
+
+
+
+
Choose a change...
+
+

Update Item

+
+
+
+
+
+
+
+
+
+
Diagnostic fields
+
+
    +
  • +
    +
    hostName
    +
    +
    +
  • +
  • +
    +
    hostVersion
    +
    +
    +
  • +
  • +
    +
    OWAView
    +
    +
    +
  • +
+
+
Access Token
+
+
Parse token
+
+ +
+
+
loading...
+
+
+
REST URL to item
+
+
+
loading...
+
+
+
+
+
+
+ +
+ + + + \ No newline at end of file diff --git a/RestCaller/mobile/RestCaller-ios.js b/RestCaller/mobile/RestCaller-ios.js new file mode 100644 index 0000000..8085032 --- /dev/null +++ b/RestCaller/mobile/RestCaller-ios.js @@ -0,0 +1,214 @@ +$(document).ready(function() { + +}); + +// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. + +(function () { + 'use strict'; + + var myApp; + + var rawToken = ''; + var parsedToken = ''; + + var getItemSpinnerElement = null; + var getItemSpinner = null; + var updateItemSpinnerElement = null; + var updateItemSpinner = null; + + var markUnreadPayload = { IsRead: false }; + var flagFollowupPayload = { Flag: { FlagStatus: 'Flagged' } }; + var applyCategoryPayload = { Categories: ['Red Category'] }; + + // The Office initialize function must be run each time a new page is loaded + Office.initialize = function (reason) { + $(document).ready(function () { + myApp = new Framework7(); + + var getItemView = myApp.addView('#get-item-view'); + var getItemView = myApp.addView('#update-item-view'); + var getItemView = myApp.addView('#item-details-view'); + + var changePicker = myApp.picker({ + input: '#change-picker', + cols: [ + { + textAlign: 'center', + values: [ + 'Mark unread', + 'Flag for followup', + 'Apply category' + ] + } + ] + }); + + $('#change-picker').change(function() { + var newValue = $('#change-picker').val(); + loadItemChangePayload(newValue); + }); + + $('#parse-token-toggle').change(function() { + loadToken($('#parse-token-toggle').is(':checked')); + }); + + $('.get-item-button').click(function() { + getItemViaRest(); + }); + + $('.update-item-button').click(function() { + updateItemViaRest(); + }); + + loadRestDetails(); + }); + }; + + function loadRestDetails() { + $('.hostname').text(Office.context.mailbox.diagnostics.hostName); + $('.hostversion').text(Office.context.mailbox.diagnostics.hostVersion); + $('.owaview').text(Office.context.mailbox.diagnostics.OWAView); + + myApp.showPreloader(); + + var restId = ''; + if (Office.context.mailbox.diagnostics.hostName !== 'OutlookIOS') { + // Loaded in non-mobile context, so ID needs to be converted + restId = Office.context.mailbox.convertToRestId( + Office.context.mailbox.item.itemId, + Office.MailboxEnums.RestVersion.Beta + ); + } else { + restId = Office.context.mailbox.item.itemId; + } + + // Build the URL to the item + var itemUrl = Office.context.mailbox.restUrl + + '/api/beta/me/messages/' + restId; + + $('.resturl-display code').text(itemUrl); + + Office.context.mailbox.getCallbackTokenAsync({isRest: true}, function(result){ + myApp.hidePreloader(); + if (result.status === "succeeded") { + rawToken = result.value; + loadToken($('#parse-token-toggle').is(':checked')); + enableButtons(); + } else { + rawToken = 'error'; + } + }); + } + + function loadToken(parseToken) { + var code = $('.token-display code'); + if (rawToken === 'error') { + code.text('ERROR RETRIEVING TOKEN'); + return; + } + + if (parseToken) { + if (parsedToken === '') { + parsedToken = jwt_decode(rawToken); + } + + code.text(JSON.stringify(parsedToken, null, 2)); + } else { + code.text(rawToken); + } + } + + function getItemViaRest() { + var itemUrl = $('.resturl-display code').text(); + + myApp.showPreloader(); + + $.ajax({ + url: itemUrl, + dataType: 'json', + headers: { 'Authorization': 'Bearer ' + rawToken } + }).done(function(item){ + myApp.hidePreloader(); + $('.item-display code').text( + JSON.stringify(item, null, 2) + ); + }).fail(function(error){ + myApp.hidePreloader(); + $('.item-display code').text(JSON.stringify(error, null, 2)); + }); + } + + function updateItemViaRest() { + var itemUrl = $('.resturl-display code').text(); + var payload = $('.update-display code').text(); + + myApp.showPreloader(); + + $.ajax({ + type: 'PATCH', + url: itemUrl, + dataType: 'json', + data: payload, + headers: { + 'Authorization': 'Bearer ' + rawToken, + 'Content-Type': 'application/json' + } + }).done(function(item){ + myApp.hidePreloader(); + $('.update-display code').text( + JSON.stringify(item, null, 2) + ); + }).fail(function(error){ + myApp.hidePreloader(); + $('.update-display code').text(JSON.stringify(error, null, 2)); + }); + } + + function loadItemChangePayload(payloadName) { + $('.update-display code').text('loadpayload'); + var payloadText = ''; + + switch(payloadName) { + case "Mark unread": + payloadText = JSON.stringify(markUnreadPayload, null, 2); + break; + case "Flag for followup": + payloadText = JSON.stringify(flagFollowupPayload, null, 2); + break; + case "Apply category": + payloadText = JSON.stringify(applyCategoryPayload, null, 2); + break; + default: + payloadText = "Choose a change..." + } + + $('.update-display code').text(payloadText); + } + + function enableButtons() { + $('.get-item-button').removeClass('disabled'); + $('.update-item-button').removeClass('disabled'); + } +})(); + +// 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. \ No newline at end of file diff --git a/RestCaller/mobile/RestCallerMobile.html b/RestCaller/mobile/RestCallerMobile.html new file mode 100644 index 0000000..1ea1df7 --- /dev/null +++ b/RestCaller/mobile/RestCallerMobile.html @@ -0,0 +1,38 @@ + + + + + + + + + + + + + +

MOBILE DIFFERENTIATION PAGE

+ + + + \ No newline at end of file diff --git a/RestCaller/mobile/RestCallerMobile.js b/RestCaller/mobile/RestCallerMobile.js new file mode 100644 index 0000000..c8e5ac1 --- /dev/null +++ b/RestCaller/mobile/RestCallerMobile.js @@ -0,0 +1,11 @@ +var isAndroid = Framework7.prototype.device.android === true; +var isIos = Framework7.prototype.device.ios === true; + +if (isAndroid) { + alert('ANDROID SUPPORT COMING SOON'); +} + +if (isIos) { + var iosViewUrl = new URI('RestCaller-ios.html').absoluteTo(window.location).toString(); + window.location.href = iosViewUrl; +} \ No newline at end of file diff --git a/command-demo-manifest.xml b/command-demo-manifest.xml index f030f84..9c0664a 100644 --- a/command-demo-manifest.xml +++ b/command-demo-manifest.xml @@ -1035,7 +1035,7 @@ - + @@ -1064,6 +1064,7 @@ + diff --git a/package.json b/package.json index 7c4dfd7..edaef70 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,16 @@ { - "name":"command-demo", + "name": "command-demo", "version": "0.1.0", - "scripts": { - }, + "scripts": {}, "devDependencies": { "chalk": "^1.1.1", "gulp": "^3.9.0", "gulp-webserver": "^0.9.1", "minimist": "^1.2.0", "xmllint": "git+https://github.com/kripken/xml.js.git" + }, + "dependencies": { + "framework7": "^1.5.2", + "urijs": "^1.18.5" } -} \ No newline at end of file +}