diff options
author | Andrew Dolgov <[email protected]> | 2021-06-28 12:12:17 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-06-28 12:12:17 +0300 |
commit | 4696bbebe6c775434b13890a46e4d687ae2fe952 (patch) | |
tree | 3d5e6d2fe243804a70ab05a0a64464fe2d461d2f |
initial
-rw-r--r-- | init.js | 18 | ||||
-rw-r--r-- | init.php | 46 |
2 files changed, 64 insertions, 0 deletions
@@ -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 @@ +<?php +class Profile_Chooser extends Plugin { + + private $host; + + function about() { + return array(null, + "Adds a profile chooser to the main toolbar", + "fox"); + } + + function init($host) { + $this->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; + } + +} |