summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-18 11:54:22 +0300
committerAndrew Dolgov <[email protected]>2021-02-18 11:54:22 +0300
commit1adb9bb6b643736706b746629b849df9cdf45e50 (patch)
tree4361f08284d0667a075df004e3c76b2aade51e06
parentb16abc157ee584f4be80a537ee24ec9e5ff25496 (diff)
profiles: use client dialog; move related methods to pref-prefs
-rw-r--r--classes/pref/prefs.php143
-rwxr-xr-xclasses/rpc.php75
-rw-r--r--js/App.js6
-rw-r--r--js/PrefHelpers.js62
4 files changed, 133 insertions, 153 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));
diff --git a/js/App.js b/js/App.js
index 9d8f6c275..ccfeb9024 100644
--- a/js/App.js
+++ b/js/App.js
@@ -42,6 +42,12 @@ const App = {
cancel_dialog_tag: function(value, attributes = {}) {
return this.button_tag(value, "", {...{onclick: "App.dialogOf(this).hide()"}, ...attributes});
},
+ checkbox_tag: function(name, checked = false, value = "", attributes = {}, id = "") {
+ return `<input dojoType="dijit.form.CheckBox" type="checkbox" name="${App.escapeHtml(name)}"
+ ${checked ? "checked" : ""}
+ ${value ? `value="${App.escapeHtml(value)}"` : ""}
+ ${this.attributes_to_string(attributes)} id="${App.escapeHtml(id)}">`
+ },
select_tag: function(name, value, values = [], attributes = {}, id = "") {
return `
<select name="${name}" dojoType="fox.form.Select" id="${App.escapeHtml(id)}" ${this.attributes_to_string(attributes)}>
diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js
index 96d524953..7e0993cb6 100644
--- a/js/PrefHelpers.js
+++ b/js/PrefHelpers.js
@@ -104,7 +104,7 @@ const Helpers = {
Notify.progress("Removing selected profiles...", true);
const query = {
- op: "rpc", method: "remprofiles",
+ op: "pref-prefs", method: "remprofiles",
ids: sel_rows.toString()
};
@@ -122,7 +122,7 @@ const Helpers = {
if (this.validate()) {
Notify.progress("Creating profile...", true);
- const query = {op: "rpc", method: "addprofile", title: dialog.attr('value').newprofile};
+ const query = {op: "pref-prefs", method: "addprofile", title: dialog.attr('value').newprofile};
xhrPost("backend.php", query, () => {
Notify.close();
@@ -132,8 +132,60 @@ const Helpers = {
}
},
refresh: function() {
- xhrPost("backend.php", {op: 'pref-prefs', method: 'editPrefProfiles'}, (transport) => {
- dialog.attr('content', transport.responseText);
+ xhrJson("backend.php", {op: 'pref-prefs', method: 'getprofiles'}, (reply) => {
+ dialog.attr('content', `
+ <div dojoType='fox.Toolbar'>
+ <div dojoType='fox.form.DropDownButton'>
+ <span>${__('Select')}</span>
+ <div dojoType='dijit.Menu' style='display: none'>
+ <div onclick="Tables.select('pref-profiles-list', true)"
+ dojoType='dijit.MenuItem'>${__('All')}</div>
+ <div onclick="Tables.select('pref-profiles-list', false)"
+ dojoType='dijit.MenuItem'>${__('None')}</div>
+ </div>
+ </div>
+
+ <div class="pull-right">
+ <input name='newprofile' dojoType='dijit.form.ValidationTextBox' required='1'>
+ ${App.FormFields.button_tag(__('Create profile'), "", {onclick: 'App.dialogOf(this).addProfile()'})}
+ </div>
+ </div>
+
+ <form onsubmit='return false'>
+
+ <div class='panel panel-scrollable'>
+
+ <table width='100%' id='pref-profiles-list'>
+ ${reply.map((profile) => `
+ <tr data-row-id="${profile.id}">
+ <td width='5%'>
+ ${App.FormFields.checkbox_tag("", false, "", {onclick: 'Tables.onRowChecked(this)'})}
+ </td>
+ <td>
+ ${profile.id > 0 ?
+ `<span dojoType='dijit.InlineEditBox' width='300px' autoSave='false'
+ profile-id='${profile.id}'>${profile.title}
+ <script type='dojo/method' event='onChange' args='value'>
+ xhrPost("backend.php",
+ {op: 'pref-prefs', method: 'saveprofile', value: value, id: this.attr('profile-id')}, (transport) => {
+ //
+ });
+ </script>
+ </span>` : `${profile.title}`}
+ ${profile.active ? __("(active)") : ""}
+ </td>
+ </tr>
+ `).join("")}
+ </table>
+ </div>
+ <footer>
+ ${App.FormFields.button_tag(__('Remove selected profiles'), "",
+ {class: 'pull-left alt-danger', onclick: 'App.dialogOf(this).removeSelected()'})}
+ ${App.FormFields.submit_tag(__('Activate profile'), {onclick: 'App.dialogOf(this).execute()'})}
+ ${App.FormFields.cancel_dialog_tag(__('Cancel'))}
+ </footer>
+ </form>
+ `);
});
},
execute: function () {
@@ -143,7 +195,7 @@ const Helpers = {
if (confirm(__("Activate selected profile?"))) {
Notify.progress("Loading, please wait...");
- xhrPost("backend.php", {op: "rpc", method: "setprofile", id: sel_rows.toString()}, () => {
+ xhrPost("backend.php", {op: "pref-prefs", method: "activateprofile", id: sel_rows.toString()}, () => {
window.location.reload();
});
}