From 6077175c57b4f793880467d4c32d7391f4b0a038 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 1 Feb 2022 13:16:23 +0300 Subject: [PATCH] plugins/note: allow editing note by clicking on it --- plugins/note/init.php | 3 ++ plugins/note/note.css | 3 ++ plugins/note/note.js | 83 ++++++++++++++++++++++++++----------------- 3 files changed, 56 insertions(+), 33 deletions(-) create mode 100644 plugins/note/note.css diff --git a/plugins/note/init.php b/plugins/note/init.php index a22b2894d..65f7e04e9 100644 --- a/plugins/note/init.php +++ b/plugins/note/init.php @@ -15,6 +15,9 @@ class Note extends Plugin { return file_get_contents(__DIR__ . "/note.js"); } + function get_css() { + return file_get_contents(__DIR__ . "/note.css"); + } function hook_article_button($line) { return " { - Notify.close(); - dialog.hide(); + Plugins.Note = { + set_click_handler: function() { + document.querySelectorAll(".article-note[data-note-for]").forEach((note) => { + note.onclick = function() { + Plugins.Note.edit(this.getAttribute('data-note-for')); + } + }); + }, + edit: function(id) { + const dialog = new fox.SingleUseDialog({ + title: __("Edit article note"), + execute: function () { + if (this.validate()) { + Notify.progress("Saving article note...", true); - if (reply) { - App.findAll(`div[data-note-for="${reply.id}"]`).forEach((elem) => { - elem.querySelector(".body").innerHTML = reply.note; + xhr.json("backend.php", this.attr('value'), (reply) => { + Notify.close(); + dialog.hide(); - if (reply.note) - elem.show(); - else - elem.hide(); + if (reply) { + App.findAll(`div[data-note-for="${reply.id}"]`).forEach((elem) => { + elem.querySelector(".body").innerHTML = reply.note; + + if (reply.note) + elem.show(); + else + elem.hide(); + }); + } }); } + }, + content: __("Loading, please wait...") + }); + + const tmph = dojo.connect(dialog, 'onShow', function () { + dojo.disconnect(tmph); + + xhr.post("backend.php", App.getPhArgs("note", "edit", {id: id}), (reply) => { + dialog.attr('content', reply); }); - } - }, - content: __("Loading, please wait...") + }); + + dialog.show(); + } + }; + + PluginHost.register(PluginHost.HOOK_HEADLINE_RENDERED, function() { + Plugins.Note.set_click_handler(); + return true; }); - - const tmph = dojo.connect(dialog, 'onShow', function () { - dojo.disconnect(tmph); - - xhr.post("backend.php", App.getPhArgs("note", "edit", {id: id}), (reply) => { - dialog.attr('content', reply); - }); - }); - - dialog.show(); - } -}; + }); +});