From 0fbf10991237b3f91ee5c77349637d7197a22bdc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 15:38:45 +0300 Subject: * remove users/filters toolbar edit button (just click on it) * fix title of edit filter dialog always showing create filter --- js/PrefUsers.js | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'js/PrefUsers.js') diff --git a/js/PrefUsers.js b/js/PrefUsers.js index 0a7e635fe..e5c281811 100644 --- a/js/PrefUsers.js +++ b/js/PrefUsers.js @@ -93,21 +93,6 @@ const Users = { alert(__("No users selected.")); } }, - editSelected: function() { - const rows = this.getSelection(); - - if (rows.length == 0) { - alert(__("No users selected.")); - return; - } - - if (rows.length > 1) { - alert(__("Please select one user.")); - return; - } - - this.edit(rows[0]); - }, getSelection :function() { return Tables.getSelected("users-list"); } -- cgit v1.2.3-54-g00ecf From 4996d8ccfed98a5052413cdc4f4b9192fac04a89 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 14 Feb 2021 16:44:41 +0300 Subject: pref-users edit: use client dialog --- classes/pref/users.php | 112 +++++++------------------------------------------ js/App.js | 9 ++++ js/PrefUsers.js | 84 +++++++++++++++++++++++++++++++++++-- 3 files changed, 105 insertions(+), 100 deletions(-) (limited to 'js/PrefUsers.js') diff --git a/classes/pref/users.php b/classes/pref/users.php index b34f85d88..bc125d0ce 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -1,7 +1,7 @@ "; + $id = (int)clean($_REQUEST["id"]); - print '
-
'; - - //print "
"; - - $id = (int) clean($_REQUEST["id"]); - - print_hidden("id", "$id"); - print_hidden("op", "pref-users"); - print_hidden("method", "editSave"); - - $sth = $this->pdo->prepare("SELECT * FROM ttrss_users WHERE id = ?"); + $sth = $this->pdo->prepare("SELECT id, login, access_level, email FROM ttrss_users WHERE id = ?"); $sth->execute([$id]); - if ($row = $sth->fetch()) { - - $login = $row["login"]; - $access_level = $row["access_level"]; - $email = $row["email"]; - - $sel_disabled = ($id == $_SESSION["uid"] || $login == "admin") ? "disabled" : ""; - - print "
".__("User")."
"; - print "
"; - - if ($sel_disabled) { - print_hidden("login", "$login"); - } - - print "
"; - print ""; - print ""; - print "
"; - - print "
"; - - print "
".__("Authentication")."
"; - print "
"; - - print "
"; - - print " "; - - if (!$sel_disabled) { - print_select_hash("access_level", $access_level, $access_level_names, - "dojoType=\"fox.form.Select\" $sel_disabled"); - } else { - print_select_hash("", $access_level, $access_level_names, - "dojoType=\"fox.form.Select\" $sel_disabled"); - print_hidden("access_level", "$access_level"); - } - - print "
"; - print "
"; - - print " "; - print ""; - - print "
"; - - print "
"; - - print "
".__("Options")."
"; - print "
"; - - print "
"; - print " "; - print ""; - print "
"; - - print "
"; - - print ""; - + if ($row = $sth->fetch(PDO::FETCH_ASSOC)) { + print json_encode([ + "user" => $row, + "access_level_names" => $access_level_names + ]); + } else { + print json_encode(["error" => "USER_NOT_FOUND"]); } - - print '
'; #tab - print "
"; - - print '
'; - print '
'; - - print "
- - -
"; - - print ""; - - return; } function userdetails() { @@ -186,6 +100,12 @@ class Pref_Users extends Handler_Administrative { $email = clean($_REQUEST["email"]); $password = clean($_REQUEST["password"]); + // no blank usernames + if (!$login) return; + + // forbid renaming admin + if ($uid == 1) $login = "admin"; + if ($password) { $salt = substr(bin2hex(get_random_bytes(125)), 0, 250); $pwd_hash = encrypt_password($password, $salt, true); diff --git a/js/App.js b/js/App.js index 4646145ea..1e6e5fdb1 100644 --- a/js/App.js +++ b/js/App.js @@ -20,6 +20,15 @@ const App = { FormFields: { hidden: function(name, value, id = "") { return `` + }, + select_hash: function(name, value, values, attributes) { + return ` + + ` } }, Scrollable: { diff --git a/js/PrefUsers.js b/js/PrefUsers.js index e5c281811..1fe4db150 100644 --- a/js/PrefUsers.js +++ b/js/PrefUsers.js @@ -1,7 +1,7 @@ 'use strict' /* global __ */ -/* global xhrPost, dojo, dijit, Notify, Tables, fox */ +/* global xhrPost, xhrJson, dojo, dijit, Notify, Tables, App, fox */ const Users = { reload: function(sort) { @@ -27,7 +27,10 @@ const Users = { } }, edit: function(id) { - xhrPost('backend.php', {op: 'pref-users', method: 'edit', id: id}, (transport) => { + xhrJson('backend.php', {op: 'pref-users', method: 'edit', id: id}, (reply) => { + const user = reply.user; + const is_disabled = (user.id == 1) ? "disabled='disabled'" : ''; + const dialog = new fox.SingleUseDialog({ id: "userEditDlg", title: __("User Editor"), @@ -35,13 +38,86 @@ const Users = { if (this.validate()) { Notify.progress("Saving data...", true); - xhrPost("backend.php", dojo.formToObject("user_edit_form"), (/* transport */) => { + xhrPost("backend.php", this.attr('value'), () => { dialog.hide(); Users.reload(); }); } }, - content: transport.responseText + content: ` +
+ + ${App.FormFields.hidden('id', user.id.toString())} + ${App.FormFields.hidden('op', 'pref-users')} + ${App.FormFields.hidden('method', 'editSave')} + +
+
+ +
${__("User")}
+ +
+
+ + + + ${is_disabled ? App.FormFields.hidden("login", user.login) : ''} +
+
+ +
${__("Authentication")}
+ +
+
+ + ${App.FormFields.select_hash("access_level", + user.access_level, reply.access_level_names, is_disabled)} + + ${is_disabled ? App.FormFields.hidden("access_level", + user.access_level.toString()) : ''} +
+
+ + +
+
+ +
${__("Options")}
+ +
+
+ + +
+
+
+
+ + ${__("Loading, please wait...")} +
+
+ +
+ + +
+
+ ` }); dialog.show(); -- cgit v1.2.3-54-g00ecf From b16abc157ee584f4be80a537ee24ec9e5ff25496 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 17 Feb 2021 19:34:54 +0300 Subject: * App: rename hidden to hidden_tag * search: use client dialog * add some form field helpers --- .eslintrc.js | 2 +- classes/feeds.php | 46 ++++++---------------------------------------- js/App.js | 40 +++++++++++++++++++++++++++++++++++----- js/Article.js | 6 +++--- js/CommonDialogs.js | 4 ++-- js/CommonFilters.js | 4 ++-- js/Feeds.js | 42 +++++++++++++++++++++++++++++++++++------- js/PrefFeedTree.js | 4 ++-- js/PrefHelpers.js | 6 +++--- js/PrefLabelTree.js | 10 +++++----- js/PrefUsers.js | 16 ++++++++-------- 11 files changed, 102 insertions(+), 78 deletions(-) (limited to 'js/PrefUsers.js') diff --git a/.eslintrc.js b/.eslintrc.js index 6d76f6082..523ada08e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { "env": { "browser": true, - "es6": true, + "ecmaVersion": 8, "jquery": true, "webextensions": true }, diff --git a/classes/feeds.php b/classes/feeds.php index 68edfbf89..30478ae39 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -588,46 +588,12 @@ class Feeds extends Handler_Protected { } function search() { - $this->params = explode(":", $_REQUEST["param"], 2); - - $active_feed_id = sprintf("%d", $this->params[0]); - $is_cat = $this->params[1] != "false"; - - print "
"; - - print "
"; - - print "
"; - print "_get_title($active_feed_id, $is_cat))."\" - name='query' type='search' value=''>"; - print "
"; - - if (DB_TYPE == "pgsql") { - print "
"; - print ""; - print \Controls\select_tag("search_language", get_pref('DEFAULT_SEARCH_LANGUAGE'), Pref_Feeds::get_ts_languages(), - ["title" => __('Used for word stemming')], "search_language"); - print "
"; - } - - print "
"; - - print "
"; - - if (count(PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH)) == 0) { - print ""; - } - - print " - "; - - print "
"; - - print "
"; + print json_encode([ + "show_language" => DB_TYPE == "pgsql", + "show_syntax_help" => count(PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEARCH)) == 0, + "all_languages" => Pref_Feeds::get_ts_languages(), + "default_language" => get_pref('DEFAULT_SEARCH_LANGUAGE') + ]); } function updatedebugger() { diff --git a/js/App.js b/js/App.js index bb861829d..9d8f6c275 100644 --- a/js/App.js +++ b/js/App.js @@ -18,14 +18,44 @@ const App = { is_prefs: false, LABEL_BASE_INDEX: -1024, FormFields: { - hidden: function(name, value, id = "") { - return `` + attributes_to_string: function(attributes) { + return Object.keys(attributes).map((k) => + `${App.escapeHtml(k)}="${App.escapeHtml(attributes[k])}"`) + .join(" "); }, - select_hash: function(name, value, values, attributes) { + hidden_tag: function(name, value, attributes = {}, id = "") { + return `` + }, + // allow html inside because of icons + button_tag: function(value, type, attributes = {}) { + return `` + + }, + icon: function(icon, attributes = {}) { + return `${icon}`; + }, + submit_tag: function(value, attributes = {}) { + return this.button_tag(value, "submit", {...{class: "alt-primary"}, ...attributes}); + }, + cancel_dialog_tag: function(value, attributes = {}) { + return this.button_tag(value, "", {...{onclick: "App.dialogOf(this).hide()"}, ...attributes}); + }, + select_tag: function(name, value, values = [], attributes = {}, id = "") { + return ` + + ` + }, + select_hash: function(name, value, values = {}, attributes = {}, id = "") { return ` - ${Object.keys(values).map((vk) => - `` + `` ).join("")} ` diff --git a/js/Article.js b/js/Article.js index 4d400e2dc..a42d3af67 100644 --- a/js/Article.js +++ b/js/Article.js @@ -314,9 +314,9 @@ const Article = { const dialog = new fox.SingleUseDialog({ title: __("Edit article Tags"), content: ` - ${App.FormFields.hidden("id", id.toString())} - ${App.FormFields.hidden("op", "article")} - ${App.FormFields.hidden("method", "setArticleTags")} + ${App.FormFields.hidden_tag("id", id.toString())} + ${App.FormFields.hidden_tag("op", "article")} + ${App.FormFields.hidden_tag("method", "setArticleTags")}
${__("Tags for this article (separated by commas):")} diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index c16afed82..dd0d56194 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -86,8 +86,8 @@ const CommonDialogs = { content: `
- ${App.FormFields.hidden("op", "feeds")} - ${App.FormFields.hidden("method", "add")} + ${App.FormFields.hidden_tag("op", "feeds")} + ${App.FormFields.hidden_tag("method", "add")} diff --git a/js/CommonFilters.js b/js/CommonFilters.js index 5afffafdc..e3629157b 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -45,7 +45,7 @@ const Filters = { li.innerHTML = ` ${transport.responseText} - ${App.FormFields.hidden("rule[]", rule)}`; + ${App.FormFields.hidden_tag("rule[]", rule)}`; dojo.parser.parse(li); @@ -76,7 +76,7 @@ const Filters = { li.innerHTML = ` ${transport.responseText} - ${App.FormFields.hidden("action[]", action)}`; + ${App.FormFields.hidden_tag("action[]", action)}`; dojo.parser.parse(li); diff --git a/js/Feeds.js b/js/Feeds.js index 73f1bc338..0567cf8c5 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -1,6 +1,6 @@ 'use strict' -/* global __, App, Headlines, xhrPost, dojo, dijit, Form, fox, PluginHost, Notify, $$, fox */ +/* global __, App, Headlines, xhrPost, xhrJson, dojo, dijit, Form, fox, PluginHost, Notify, $$, fox */ const Feeds = { counters_last_request: 0, @@ -566,14 +566,42 @@ const Feeds = { return tree.model.store.getValue(nuf, 'bare_id'); }, search: function() { - xhrPost("backend.php", - {op: "feeds", method: "search", - param: Feeds.getActive() + ":" + Feeds.activeIsCat()}, - (transport) => { + xhrJson("backend.php", + {op: "feeds", method: "search"}, + (reply) => { try { const dialog = new fox.SingleUseDialog({ - id: "searchDlg", - content: transport.responseText, + content: ` + +
+
+ +
+ + ${reply.show_language ? + ` +
+ + ${App.FormFields.select_tag("search_language", reply.default_language, reply.all_languages, + {title: __('Used for word stemming')}, "search_language")} +
+ ` : ''} +
+ +
+ ${reply.show_syntax_help ? + `${App.FormFields.button_tag(App.FormFields.icon("help") + " " + __("Search syntax"), "", + {class: 'alt-info pull-left', onclick: "window.open('https://tt-rss.org/wiki/SearchSyntax')"})} + ` : ''} + + ${App.FormFields.submit_tag(__('Search'), {onclick: "App.dialogOf(this).execute()"})} + ${App.FormFields.cancel_dialog_tag(__('Cancel'))} +
+
+ `, title: __("Search"), execute: function () { if (this.validate()) { diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index e0a2dd932..e081e2e31 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -405,8 +405,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_b }, content: `
- ${App.FormFields.hidden("op", "pref-feeds")} - ${App.FormFields.hidden("method", "batchaddfeeds")} + ${App.FormFields.hidden_tag("op", "pref-feeds")} + ${App.FormFields.hidden_tag("method", "batchaddfeeds")}
${__("One valid feed per line (no detection is done)")} diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index f7eca59a0..96d524953 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -183,9 +183,9 @@ const Helpers = { ${__("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here.")} - ${App.FormFields.hidden('op', 'rpc')} - ${App.FormFields.hidden('method', 'setpref')} - ${App.FormFields.hidden('key', 'USER_STYLESHEET')} + ${App.FormFields.hidden_tag('op', 'rpc')} + ${App.FormFields.hidden_tag('method', 'setpref')} + ${App.FormFields.hidden_tag('key', 'USER_STYLESHEET')}