plugins/note: allow editing note by clicking on it

This commit is contained in:
Andrew Dolgov 2022-02-01 13:16:23 +03:00
parent 478c9b64a9
commit 6077175c57
3 changed files with 56 additions and 33 deletions

View File

@ -15,6 +15,9 @@ class Note extends Plugin {
return file_get_contents(__DIR__ . "/note.js"); return file_get_contents(__DIR__ . "/note.js");
} }
function get_css() {
return file_get_contents(__DIR__ . "/note.css");
}
function hook_article_button($line) { function hook_article_button($line) {
return "<i class='material-icons' onclick=\"Plugins.Note.edit(".$line["id"].")\" return "<i class='material-icons' onclick=\"Plugins.Note.edit(".$line["id"].")\"

3
plugins/note/note.css Normal file
View File

@ -0,0 +1,3 @@
.article-note[data-note-for] {
cursor : pointer;
}

View File

@ -1,41 +1,58 @@
/* global dojo, Plugins, xhr, App, Notify, fox, __ */ /* global require, Plugins, PluginHost, xhr, App, Notify, fox, __ */
Plugins.Note = { require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
edit: function(id) { ready(function() {
const dialog = new fox.SingleUseDialog({
title: __("Edit article note"),
execute: function () {
if (this.validate()) {
Notify.progress("Saving article note...", true);
xhr.json("backend.php", this.attr('value'), (reply) => { Plugins.Note = {
Notify.close(); set_click_handler: function() {
dialog.hide(); 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) { xhr.json("backend.php", this.attr('value'), (reply) => {
App.findAll(`div[data-note-for="${reply.id}"]`).forEach((elem) => { Notify.close();
elem.querySelector(".body").innerHTML = reply.note; dialog.hide();
if (reply.note) if (reply) {
elem.show(); App.findAll(`div[data-note-for="${reply.id}"]`).forEach((elem) => {
else elem.querySelector(".body").innerHTML = reply.note;
elem.hide();
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();
}
};