diff options
author | Andrew Dolgov <[email protected]> | 2021-02-18 11:54:22 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-02-18 11:54:22 +0300 |
commit | 1adb9bb6b643736706b746629b849df9cdf45e50 (patch) | |
tree | 4361f08284d0667a075df004e3c76b2aade51e06 /classes | |
parent | b16abc157ee584f4be80a537ee24ec9e5ff25496 (diff) |
profiles: use client dialog; move related methods to pref-prefs
Diffstat (limited to 'classes')
-rw-r--r-- | classes/pref/prefs.php | 143 | ||||
-rwxr-xr-x | classes/rpc.php | 75 |
2 files changed, 70 insertions, 148 deletions
diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 3bc8a9a9c..4a4aa45d6 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -1219,102 +1219,97 @@ class Pref_Prefs extends Handler_Protected { print json_encode(["value" => $value]); } - function editPrefProfiles() { - print "<div dojoType='fox.Toolbar'>"; + function activateprofile() { + $_SESSION["profile"] = (int) clean($_REQUEST["id"]); - print "<div dojoType='fox.form.DropDownButton'>". - "<span>" . __('Select')."</span>"; - print "<div dojoType='dijit.Menu' style='display: none'>"; - print "<div onclick=\"Tables.select('pref-profiles-list', true)\" - dojoType='dijit.MenuItem'>".__('All')."</div>"; - print "<div onclick=\"Tables.select('pref-profiles-list', false)\" - dojoType='dijit.MenuItem'>".__('None')."</div>"; - print "</div></div>"; - - print "<div style='float : right'>"; - - print "<input name='newprofile' dojoType='dijit.form.ValidationTextBox' - required='1'> - <button dojoType='dijit.form.Button' - onclick=\"dijit.byId('profileEditDlg').addProfile()\">". - __('Create profile')."</button></div>"; - - print "</div>"; - - $sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles - WHERE owner_uid = ? ORDER BY title"); - $sth->execute([$_SESSION['uid']]); + // default value + if (!$_SESSION["profile"]) $_SESSION["profile"] = null; + } - print "<form onsubmit='return false'>"; + function remprofiles() { + $ids = explode(",", clean($_REQUEST["ids"])); - print "<div class='panel panel-scrollable'>"; + foreach ($ids as $id) { + if ($_SESSION["profile"] != $id) { + $sth = $this->pdo->prepare("DELETE FROM ttrss_settings_profiles WHERE id = ? AND + owner_uid = ?"); + $sth->execute([$id, $_SESSION['uid']]); + } + } + } - print "<table width='100%' id='pref-profiles-list'>"; + function addprofile() { + $title = clean($_REQUEST["title"]); - print "<tr>"; # data-row-id='0' <-- no point, shouldn't be removed + if ($title) { + $this->pdo->beginTransaction(); - print "<td><input onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' type='checkbox'></td>"; + $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles + WHERE title = ? AND owner_uid = ?"); + $sth->execute([$title, $_SESSION['uid']]); - if (!isset($_SESSION["profile"])) { - $is_active = __("(active)"); - } else { - $is_active = ""; - } + if (!$sth->fetch()) { - print "<td width='100%'><span>" . __("Default profile") . " $is_active</span></td>"; + $sth = $this->pdo->prepare("INSERT INTO ttrss_settings_profiles (title, owner_uid) + VALUES (?, ?)"); - print "</tr>"; + $sth->execute([$title, $_SESSION['uid']]); - while ($line = $sth->fetch()) { + $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles WHERE + title = ? AND owner_uid = ?"); + $sth->execute([$title, $_SESSION['uid']]); - $profile_id = $line["id"]; + if ($row = $sth->fetch()) { + $profile_id = $row['id']; - print "<tr data-row-id='$profile_id'>"; + if ($profile_id) { + Pref_Prefs::_init_user_prefs($_SESSION["uid"], $profile_id); + } + } + } - $edit_title = htmlspecialchars($line["title"]); + $this->pdo->commit(); + } + } - print "<td><input onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' type='checkbox'></td>"; + function saveprofile() { + $id = clean($_REQUEST["id"]); + $title = clean($_REQUEST["title"]); - if (isset($_SESSION["profile"]) && $_SESSION["profile"] == $line["id"]) { - $is_active = __("(active)"); - } else { - $is_active = ""; - } + if ($id == 0) { + print __("Default profile"); + return; + } - print "<td><span dojoType='dijit.InlineEditBox' - width='300px' autoSave='false' - profile-id='$profile_id'>" . $edit_title . - "<script type='dojo/method' event='onChange' args='item'> - var elem = this; - dojo.xhrPost({ - url: 'backend.php', - content: {op: 'rpc', method: 'saveprofile', - value: this.value, - id: this.srcNodeRef.getAttribute('profile-id')}, - load: function(response) { - elem.attr('value', response); - } - }); - </script> - </span> $is_active</td>"; + if ($title) { + $sth = $this->pdo->prepare("UPDATE ttrss_settings_profiles + SET title = ? WHERE id = ? AND + owner_uid = ?"); - print "</tr>"; + $sth->execute([$title, $id, $_SESSION['uid']]); + print $title; } + } + + // TODO: this maybe needs to be unified with Public::getProfiles() + function getProfiles() { + $rv = []; - print "</table>"; - print "</div>"; + $sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles + WHERE owner_uid = ? ORDER BY title"); + $sth->execute([$_SESSION['uid']]); - print "<footer> - <button style='float : left' class='alt-danger' dojoType='dijit.form.Button' onclick='App.dialogOf(this).removeSelected()'>". - __('Remove selected profiles')."</button> - <button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick='App.dialogOf(this).execute()'>". - __('Activate profile')."</button> - <button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>". - __('Cancel')."</button>"; - print "</footer>"; + array_push($rv, ["title" => __("Default profile"), + "id" => 0, + "active" => empty($_SESSION["profile"]) + ]); - print "</form>"; + while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { + $row["active"] = isset($_SESSION["profile"]) && $_SESSION["profile"] == $row["id"]; + array_push($rv, $row); + }; + print json_encode($rv); } private function _get_short_desc($pref_name) { diff --git a/classes/rpc.php b/classes/rpc.php index 6831d5667..0fd06da4d 100755 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -2,84 +2,11 @@ class RPC extends Handler_Protected { function csrf_ignore($method) { - $csrf_ignored = array("completelabels", "saveprofile"); + $csrf_ignored = array("completelabels"); return array_search($method, $csrf_ignored) !== false; } - function setprofile() { - $_SESSION["profile"] = (int) clean($_REQUEST["id"]); - - // default value - if (!$_SESSION["profile"]) $_SESSION["profile"] = null; - } - - function remprofiles() { - $ids = explode(",", clean($_REQUEST["ids"])); - - foreach ($ids as $id) { - if ($_SESSION["profile"] != $id) { - $sth = $this->pdo->prepare("DELETE FROM ttrss_settings_profiles WHERE id = ? AND - owner_uid = ?"); - $sth->execute([$id, $_SESSION['uid']]); - } - } - } - - // Silent - function addprofile() { - $title = clean($_REQUEST["title"]); - - if ($title) { - $this->pdo->beginTransaction(); - - $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles - WHERE title = ? AND owner_uid = ?"); - $sth->execute([$title, $_SESSION['uid']]); - - if (!$sth->fetch()) { - - $sth = $this->pdo->prepare("INSERT INTO ttrss_settings_profiles (title, owner_uid) - VALUES (?, ?)"); - - $sth->execute([$title, $_SESSION['uid']]); - - $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles WHERE - title = ? AND owner_uid = ?"); - $sth->execute([$title, $_SESSION['uid']]); - - if ($row = $sth->fetch()) { - $profile_id = $row['id']; - - if ($profile_id) { - Pref_Prefs::_init_user_prefs($_SESSION["uid"], $profile_id); - } - } - } - - $this->pdo->commit(); - } - } - - function saveprofile() { - $id = clean($_REQUEST["id"]); - $title = clean($_REQUEST["value"]); - - if ($id == 0) { - print __("Default profile"); - return; - } - - if ($title) { - $sth = $this->pdo->prepare("UPDATE ttrss_settings_profiles - SET title = ? WHERE id = ? AND - owner_uid = ?"); - - $sth->execute([$title, $id, $_SESSION['uid']]); - print $title; - } - } - function togglepref() { $key = clean($_REQUEST["key"]); set_pref($key, !get_pref($key)); |