Skip to content

Commit

Permalink
add preference for controlling button visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
nneul committed Jun 26, 2022
1 parent 345d3cc commit ee8cee8
Showing 1 changed file with 67 additions and 10 deletions.
77 changes: 67 additions & 10 deletions one_click_mark/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,83 @@ function about() {
"nneul");
}

function init($host) {
function init($host) {
$this->host = $host;

$host->add_hook($host::HOOK_MAIN_TOOLBAR_BUTTON, $this);
$host->add_hook($host::HOOK_TOOLBAR_BUTTON, $this);
$host->add_hook($host::HOOK_TOOLBAR_BUTTON, $this);
$host->add_hook($host::HOOK_PREFS_TAB, $this);
}

function hook_main_toolbar_button() {
?>

<button onclick="Feeds.catchupCurrent('')"><?= __('Mark as read') ?></button>
$disable_button = $this->host->get($this, "disable_left_button");

<?php
if ( ! $disable_button ) {
print "<button onclick=\"Feeds.catchupCurrent('')\">" . __('Mark as read') . "</button>\n";
}
}

function hook_toolbar_button() {
?>
$disable_button = $this->host->get($this, "disable_right_button");

<button onclick="Feeds.catchupCurrent('')"><?= __('Mark as read') ?></button>
if ( ! $disable_button ) {
print "<button onclick=\"Feeds.catchupCurrent('')\">" . __('Mark as read') . "</button>\n";
}
}

<?php
}
function hook_prefs_tab($args) {
if ($args != "prefPrefs") return;
$disable_left_button = $this->host->get($this, "disable_left_button");
$disable_right_button = $this->host->get($this, "disable_right_button");

$disable_left_button_checked = $disable_left_button ? "checked" : "";
$disable_right_button_checked = $disable_right_button ? "checked" : "";

?>
<div dojoType="dijit.layout.AccordionPane"
title="<i class='material-icons'>extension</i> <?= __("One Click Mark Plugin") ?>">
<form dojoType="dijit.form.Form">

<?= \Controls\pluginhandler_tags($this, "save") ?>

<script type="dojo/method" event="onSubmit" args="evt">
evt.preventDefault();
if (this.validate()) {
Notify.progress('Saving data...', true);
xhr.post("backend.php", this.getValues(), (reply) => {
Notify.info(reply);
})
}
</script>

<header><?= __("Enable/disable buttons:") ?></header>
<p>

<?= \Controls\checkbox_tag("disable_left_button", $disable_left_button_checked, "on", [], "disable_left_button"); ?>
<label for="disable_left_button"><?= __("Hide Left Mark as Read button") ?></label>

<p>

<?= \Controls\checkbox_tag("disable_right_button", $disable_right_button_checked, "on", [], "disable_right_button"); ?>
<label for="disable_right_button"><?= __("Hide Right Mark as Read button") ?></label>

<hr/>

<?= \Controls\submit_tag(__("Save")) ?>
</form>
</div>
<?php
}

function save() : void {
$disable_left_button = checkbox_to_sql_bool($_POST["disable_left_button"]) == true;
$this->host->set($this, "disable_left_button", $disable_left_button);

$disable_right_button = checkbox_to_sql_bool($_POST["disable_right_button"]) == true;
$this->host->set($this, "disable_right_button", $disable_right_button);

echo __("Configuration saved.");
}

function api_version() {
return 2;
Expand Down

0 comments on commit ee8cee8

Please sign in to comment.