From 4696bbebe6c775434b13890a46e4d687ae2fe952 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 28 Jun 2021 12:12:17 +0300 Subject: initial --- init.js | 18 ++++++++++++++++++ init.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 init.js create mode 100644 init.php diff --git a/init.js b/init.js new file mode 100644 index 0000000..c2f3d18 --- /dev/null +++ b/init.js @@ -0,0 +1,18 @@ +/* global App, Plugins, xhr */ + +Plugins.Profile_Chooser = { + onChange: function(sender) { + if (confirm("Activate selected profile? Window will reload.")) { + xhr.post("backend.php", {op: "pref-prefs", method: "activateprofile", id: sender.attr('value')}, () => { + window.location.reload(); + }); + } else { + // there has to be a better way to revert select to a previous value in onchange... + + xhr.json("backend.php", App.getPhArgs("profile_chooser", "getprofile"), (reply) => { + if (reply && typeof reply.profile != 'undefined') + sender.attr('value', reply.profile, false); + }); + } + } +}; diff --git a/init.php b/init.php new file mode 100644 index 0000000..0671280 --- /dev/null +++ b/init.php @@ -0,0 +1,46 @@ +host = $host; + + $host->add_hook($host::HOOK_MAIN_TOOLBAR_BUTTON, $this); + } + + function get_js() { + return file_get_contents(__DIR__ . "/init.js"); + } + + function getprofile() { + print json_encode(["profile" => $_SESSION["profile"] ?? 0]); + } + + function hook_main_toolbar_button() { + $profiles = ORM::for_table("ttrss_settings_profiles") + ->where("owner_uid", $_SESSION["uid"]) + ->order_by_expr("title") + ->find_many(); + + $dropdown_items = [ 0 => __("Default profile") ]; + + foreach ($profiles as $profile) { + $dropdown_items[$profile->id] = $profile->title; + } + + echo \Controls\select_hash("profile_chooser", $_SESSION["profile"] ?? "", + $dropdown_items, ["style" => "order: 21", "onchange" => "Plugins.Profile_Chooser.onChange(this)"]); + } + + function api_version() { + return 2; + } + +} -- cgit v1.2.3