From e423683c4da2e29fc4e6158431408a23d57b0315 Mon Sep 17 00:00:00 2001 From: Tom Needham Date: Wed, 15 Aug 2018 13:22:39 +0100 Subject: [PATCH 1/4] WIP public preview --- appinfo/app.php | 1 + js/editor.js | 9 +++++++++ js/public.js | 36 ++++++++++++++++++++++++++++++++++++ lib/Application.php | 18 ++++++++++++++++-- 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 js/public.js diff --git a/appinfo/app.php b/appinfo/app.php index 5e0857f..87919ee 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -24,3 +24,4 @@ \OC::$server->getEventDispatcher(), \OC::$server->getUserSession() ); + diff --git a/js/editor.js b/js/editor.js index bfdab9e..e4980cb 100644 --- a/js/editor.js +++ b/js/editor.js @@ -29,6 +29,15 @@ }; } + OCA.Drawio.LoadPublicFileHandler = function(eventHandler, downloadPath, editWindow) { + $.get( downloadPath, function( data ) { + editWindow.postMessage(JSON.stringify({ + action: "load", + xml: data + }), "*"); + }); + }; + OCA.Drawio.LoadEditorHandler = function(eventHandler, path, editWindow) { // Handle the load event at the start of the page load var loadMsg = OC.Notification.show(t(OCA.Drawio.AppName, "Loading diagram...")); diff --git a/js/public.js b/js/public.js new file mode 100644 index 0000000..db359d7 --- /dev/null +++ b/js/public.js @@ -0,0 +1,36 @@ +var eventHandler = function (evt) { + if (evt.data.length > 0) { + var payload = JSON.parse(evt.data); + if (payload.event === "init") { + OCA.Drawio.LoadPublicFileHandler( + eventHandler, + $('#downloadURL').val(), + $('#drawioEditor')[0].contentWindow); + } + } +}; +window.addEventListener("message", eventHandler); + +$(document).ready(function(){ + if ($('#isPublic').val()) { + // TODO this needs to be imported + var src = 'https://www.draw.io?embed=1&chrome=0&spin=1&stealth=1&proto=json'; + var html ='