From 3b85da9ae3ade346f0ce124a790f1f8f7c3ff276 Mon Sep 17 00:00:00 2001 From: Harvey Date: Tue, 6 Oct 2020 22:13:44 +0200 Subject: [PATCH] Improved settings depending on render location. --- dist/csp/js/edit.js | 81 ----------------------------------------- dist/csp/js/settings.js | 71 ++++++++++++++++++++++++++++++++++++ dist/csp/js/wrapper.js | 4 ++ dist/csp/settings.html | 6 +-- dist/csp/wrapper.html | 1 + 5 files changed, 79 insertions(+), 84 deletions(-) delete mode 100644 dist/csp/js/edit.js create mode 100644 dist/csp/js/settings.js create mode 100644 dist/csp/js/wrapper.js diff --git a/dist/csp/js/edit.js b/dist/csp/js/edit.js deleted file mode 100644 index 4ff7259..0000000 --- a/dist/csp/js/edit.js +++ /dev/null @@ -1,81 +0,0 @@ -"use strict"; - -// import React, { Component } from "react"; -// import { render } from "react-dom"; -// import Form from "react-jsonschema-form"; -const Form = JSONSchemaForm.default; -const storage = new CustomStartStorage(); - -async function getSchema() { - return await fetch('/manifest/schema.json').then(res => res.json()).then(out => { - return out; - }).catch(err => { - throw err; - }); -} - -const del = () => { - storage.delete(); - window.parent.reloadPreview(); -}; - -const isPreview = () => { - return typeof window.parent.reloadPreview !== 'undefined'; -}; - -async function render() { - const originalFormData = await storage.get(); - const schema = await getSchema(); - let formData = null; - - let formAction = function () { - console.error('No action set.'); - }; - - const previewButton = isPreview() ? React.createElement("button", { - className: "btn btn-success", - onClick: () => { - formAction = saveAndUpdatePreview; - } - }, "Save and update preview") : ''; - - const submit = data => { - formData = data.formData; - storage.set(formData); - console.log(formData); - alert('Saved!'); - formAction(); - }; - - const saveAndUpdatePreview = () => { - window.parent.reloadPreview(); - }; - - const save = () => {}; - - ReactDOM.render(React.createElement(Form, { - schema: schema, - formData: originalFormData // onChange={log("changed")} - , - onSubmit: submit // onError={log("errors")} - - }, React.createElement("footer", { - className: "sticky-footer" - }, React.createElement("div", { - className: "container " - }, previewButton, React.createElement("div", { - class: "pull-right" - }, React.createElement("button", { - className: "btn btn-primary", - onClick: () => { - formAction = save; - } - }, "Save"), "\xA0", React.createElement("a", { - href: "/", - target: "_blank", - class: "btn btn-warning" - }, "View start page"))))), document.getElementById("form")); -} - -render(); -//# sourceMappingURL=edit.min.js.map diff --git a/dist/csp/js/settings.js b/dist/csp/js/settings.js new file mode 100644 index 0000000..643f6e2 --- /dev/null +++ b/dist/csp/js/settings.js @@ -0,0 +1,71 @@ +"use strict"; + +// import React, { Component } from "react"; +// import { render } from "react-dom"; +// import Form from "react-jsonschema-form"; +const Form = JSONSchemaForm.default; +const storage = new CustomStartStorage(); + +async function getSchema() { + return await fetch('/manifest/schema.json').then(res => res.json()).then(out => { + return out; + }).catch(err => { + throw err; + }); +} + +const del = () => { + storage.delete(); + window.parent.reloadPreview(); +}; + +const canReloadStartPage = () => { + return typeof window.parent.reloadStartPage !== 'undefined'; +}; + +async function render() { + const originalFormData = await storage.get(); + const schema = await getSchema(); + let formData = null; + + let formAction = function () { + console.error('No action set.'); + }; + + const submit = data => { + formData = data.formData; + storage.set(formData); + console.log(formData); + + formAction(); + + if (canReloadStartPage()) + window.parent.reloadStartPage(); + }; + + const save = () => { }; + ReactDOM.render( + React.createElement(Form, { schema: schema, formData: originalFormData, onSubmit: submit, }, + React.createElement("footer", { className: "sticky-footer" }, + React.createElement("div", { className: "container " }, + React.createElement("div", { class: "pull-right" }, + React.createElement( + "button", + { + className: "btn btn-primary", + onClick: () => { + formAction = save; + } + }, "Save" + (canReloadStartPage() ? " and update" : "")), + "\xA0", + canReloadStartPage() == false + ? React.createElement( + "a", + { href: "/", target: "_blank", class: "btn btn-warning" }, + "View start page") + : "" + )))), document.getElementById("form")); +} + +render(); +//# sourceMappingURL=edit.min.js.map diff --git a/dist/csp/js/wrapper.js b/dist/csp/js/wrapper.js new file mode 100644 index 0000000..2c5f7b5 --- /dev/null +++ b/dist/csp/js/wrapper.js @@ -0,0 +1,4 @@ +window.reloadStartPage = function() { + document.querySelector('iframe#startpage') + .contentWindow.location.reload(true); +}; diff --git a/dist/csp/settings.html b/dist/csp/settings.html index 751f2b7..1f26ebd 100644 --- a/dist/csp/settings.html +++ b/dist/csp/settings.html @@ -1,7 +1,7 @@ - Edit | Custom Start Page + Settings | Custom Start Page @@ -12,7 +12,7 @@
@@ -22,7 +22,7 @@

Edit

- +