diff --git a/brain/api/v1/PagesAPI.inc.php b/brain/api/v1/PagesAPI.inc.php index f2c39c1..9e0e5ac 100644 --- a/brain/api/v1/PagesAPI.inc.php +++ b/brain/api/v1/PagesAPI.inc.php @@ -105,6 +105,7 @@ class PagesAPI case "create": case "write": $body = $request->getParsedBody(); + var_dump($body); $passed = true; if (!isset($body["form_token"])) { $result = [ @@ -138,10 +139,7 @@ class PagesAPI } } if ($passed) { - $result = (new Book("../content/pages"))->editPage( - $task, - $request - ); + $result = (new Book())->editPage($task, $request); } else { $result = [ "message" => diff --git a/brain/data/Book.inc.php b/brain/data/Book.inc.php index c4c40ce..e9cec78 100644 --- a/brain/data/Book.inc.php +++ b/brain/data/Book.inc.php @@ -32,8 +32,9 @@ class Book { $content = $this->getContents(); if ($task == "delete") { - $parsed = json_decode(file_get_contents("php://input"), true); - $body = find($content, ["uuid" => $parsed["id"]]); + //$parsed = json_decode(file_get_contents("php://input"), true); + //$body = find($content, ["uuid" => $parsed["id"]]); + $body = $request->getParsedBody(); } else { $body = $request->getParsedBody(); } @@ -93,13 +94,9 @@ class Book if ($task == "delete") { $deleted = "true"; - $body["menu"] ? ($body["menu"] = "true") : ($body["menu"] = "false"); - $body["published"] - ? ($body["published"] = "true") - : ($body["published"] = "false"); - $body["featured"] - ? ($body["featured"] = "true") - : ($body["featured"] = "false"); + $body["menu"] = "false"; + $body["published"] = "false"; + $body["featured"] = "false"; } else { $deleted = isset($page["deleted"]) ? $page["deleted"] : "false"; } @@ -195,7 +192,10 @@ class Book return $item["deleted"] == true; }); - $all = $content; + //$all = $content; + $all = filter($content, function ($item) { + return $item["deleted"] == false; + }); $filter = isset($sort) ? $sort : "all"; switch ($filter) { case "published": @@ -205,7 +205,7 @@ class Book $filtered = $deleted; break; default: - $filtered = $content; + $filtered = $all; break; } $numOfPages = ceil(count($filtered) / ($limit + 1)); diff --git a/public/assets/scripts/Start.js b/public/assets/scripts/Start.js index 593c3fd..69283ad 100644 --- a/public/assets/scripts/Start.js +++ b/public/assets/scripts/Start.js @@ -919,7 +919,7 @@ const API_ACCESS_BAD = "apiUseNotAuthorized"; case TASK_PAGE_DELETE: url = API_DELETE_PAGE; event = TASK_PAGE_DELETE; - content = CONTENT_TYPE_JSON; + content = CONTENT_TYPE_FORM; break; default: break; @@ -1685,7 +1685,7 @@ class PostEditor { // event handlers //-------------------------- handlePostOptions(e) { - let currentOption; + let currentOption = null; switch(e.target.id){ case "option-page-icon": case "option-menu-pin": @@ -1700,8 +1700,10 @@ class PostEditor { currentOption = document.getElementById("option-published"); break; } - let active = currentOption.getAttribute("data-active"); - active == "false" ? currentOption.setAttribute("data-active", "true") : currentOption.setAttribute("data-active", "false"); + if (currentOption != null) { + let active = currentOption.getAttribute("data-active"); + active == "false" ? currentOption.setAttribute("data-active", "true") : currentOption.setAttribute("data-active", "false"); + } } handleEditorOptions(e1) { if (this.processing) return; @@ -1733,19 +1735,17 @@ class PostEditor { notify.alert("Index cannot be deleted", false); return; } - if (confirm("AYE! You know you're deleting this post, right?")) { - let id = { - id: this.postUUID - }; + if (confirm("AYE! You know you're deleting this post, right?")) new _pageActionsDefault.default().collectInfo(document.getElementById("featured-image-upload").files[0]).then((page)=>{ self.processing = true; - this.admin.pageActions(_fipamoAdminAPI.TASK_PAGE_DELETE, id).then(()=>{ + this.admin.pageActions(_fipamoAdminAPI.TASK_PAGE_DELETE, page).then(()=>{ self.processing = false; window.location = "/dashboard/pages"; }).catch((err)=>{ self.processing = false; notify.alert(err, false); }); - } + }).catch(()=>{ + }); break; case _editorEvent.EDITOR_UPLOAD_POST_IMAGE: document.getElementById("post-image-upload").click(); @@ -1995,13 +1995,15 @@ class TextEditor extends _eventEmitterDefault.default { case _dataEvent.PAGE_ADDED: break; case _editorEvent.EDITOR_UPLOAD_POST_IMAGE: - let len = this.textEditor.value.length; - let start = this.textEditor.selectionStart; - let end = this.textEditor.selectionEnd; - let insert = "![image alt text](" + data + ")"; - this.textEditor.value = this.textEditor.value.substring(0, start) + insert + this.textEditor.value.substring(end, len); - document.getElementById("edit").dispatchEvent(new Event("input")); - break; + { + let len = this.textEditor.value.length; + let start = this.textEditor.selectionStart; + let end = this.textEditor.selectionEnd; + let insert = "![image alt text](" + data + ")"; + this.textEditor.value = this.textEditor.value.substring(0, start) + insert + this.textEditor.value.substring(end, len); + document.getElementById("edit").dispatchEvent(new Event("input")); + break; + } } } // event handlers @@ -2039,10 +2041,12 @@ class TextEditor extends _eventEmitterDefault.default { this.textEditor.value = this.textEditor.value.substring(0, start) + insert + this.textEditor.value.substring(end, len); break; case "edit-link": - let url = prompt("Let's get that url, boss"); - let link = url.toLowerCase(); - insert = "[" + selectedText + "](" + link + ")"; - this.textEditor.value = this.textEditor.value.substring(0, start) + insert + this.textEditor.value.substring(end, len); + { + let url = prompt("Let's get that url, boss"); + let link = url.toLowerCase(); + insert = "[" + selectedText + "](" + link + ")"; + this.textEditor.value = this.textEditor.value.substring(0, start) + insert + this.textEditor.value.substring(end, len); + } break; case "edit-image": this.caretPos = _caretPos.position(this.textEditor).pos; diff --git a/src/com/controllers/PageEditor.js b/src/com/controllers/PageEditor.js index fc483b6..d3d8a82 100644 --- a/src/com/controllers/PageEditor.js +++ b/src/com/controllers/PageEditor.js @@ -118,7 +118,7 @@ export default class PostEditor { // event handlers //-------------------------- handlePostOptions(e) { - let currentOption; + let currentOption = null; switch (e.target.id) { case "option-page-icon": case "option-menu-pin": @@ -133,10 +133,12 @@ export default class PostEditor { currentOption = document.getElementById("option-published"); break; } - let active = currentOption.getAttribute("data-active"); - active == "false" - ? currentOption.setAttribute("data-active", "true") - : currentOption.setAttribute("data-active", "false"); + if (currentOption != null) { + let active = currentOption.getAttribute("data-active"); + active == "false" + ? currentOption.setAttribute("data-active", "true") + : currentOption.setAttribute("data-active", "false"); + } } handleEditorOptions(e) { if (this.processing) return; @@ -185,18 +187,24 @@ export default class PostEditor { return; } if (confirm("AYE! You know you're deleting this post, right?")) { - let id = { id: this.postUUID }; - self.processing = true; - this.admin - .pageActions(TASK_PAGE_DELETE, id) - .then(() => { - self.processing = false; - window.location = "/dashboard/pages"; + new PageActions() + .collectInfo( + document.getElementById("featured-image-upload").files[0] + ) + .then((page) => { + self.processing = true; + this.admin + .pageActions(TASK_PAGE_DELETE, page) + .then(() => { + self.processing = false; + window.location = "/dashboard/pages"; + }) + .catch((err) => { + self.processing = false; + notify.alert(err, false); + }); }) - .catch((err) => { - self.processing = false; - notify.alert(err, false); - }); + .catch(() => {}); } else { // Do nothing! } diff --git a/src/com/ui/TextEditor.js b/src/com/ui/TextEditor.js index a2d9679..fc9e0c2 100644 --- a/src/com/ui/TextEditor.js +++ b/src/com/ui/TextEditor.js @@ -89,7 +89,7 @@ class TextEditor extends EventEmitter { case DataEvent.PAGE_ADDED: // do nothing break; - case EditorEvent.EDITOR_UPLOAD_POST_IMAGE: + case EditorEvent.EDITOR_UPLOAD_POST_IMAGE: { let len = this.textEditor.value.length; let start = this.textEditor.selectionStart; let end = this.textEditor.selectionEnd; @@ -101,6 +101,7 @@ class TextEditor extends EventEmitter { this.textEditor.value.substring(end, len); document.getElementById("edit").dispatchEvent(new Event("input")); break; + } } } //-------------------------- @@ -160,13 +161,15 @@ class TextEditor extends EventEmitter { this.textEditor.value.substring(end, len); break; case "edit-link": - let url = prompt("Let's get that url, boss"); - let link = url.toLowerCase(); - insert = "[" + selectedText + "](" + link + ")"; - this.textEditor.value = - this.textEditor.value.substring(0, start) + - insert + - this.textEditor.value.substring(end, len); + { + let url = prompt("Let's get that url, boss"); + let link = url.toLowerCase(); + insert = "[" + selectedText + "](" + link + ")"; + this.textEditor.value = + this.textEditor.value.substring(0, start) + + insert + + this.textEditor.value.substring(end, len); + } break; case "edit-image": this.caretPos = position(this.textEditor).pos; diff --git a/src/libraries/FipamoAdminAPI.js b/src/libraries/FipamoAdminAPI.js index ac57953..36369b5 100644 --- a/src/libraries/FipamoAdminAPI.js +++ b/src/libraries/FipamoAdminAPI.js @@ -248,7 +248,7 @@ class FipamoAdminAPI { case TASK_PAGE_DELETE: url = API_DELETE_PAGE; event = TASK_PAGE_DELETE; - content = CONTENT_TYPE_JSON; + content = CONTENT_TYPE_FORM; break; default: