From fda3ad39c8d89b07d4ead691bacdca6865e46517 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 17:00:58 +0300 Subject: split several utility objects into separate dojo modules --- js/PrefUsers.js | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 js/PrefUsers.js (limited to 'js/PrefUsers.js') diff --git a/js/PrefUsers.js b/js/PrefUsers.js new file mode 100644 index 000000000..aa3c2826d --- /dev/null +++ b/js/PrefUsers.js @@ -0,0 +1,119 @@ +define(["dojo/_base/declare"], function (declare) { + + return declare("fox.PrefUsers", null, { + reload: function(sort) { + const user_search = $("user_search"); + const search = user_search ? user_search.value : ""; + + xhrPost("backend.php", { op: "pref-users", sort: sort, search: search }, (transport) => { + dijit.byId('userConfigTab').attr('content', transport.responseText); + notify(""); + }); + }, + add: function() { + const login = prompt(__("Please enter username:"), ""); + + if (login) { + notify_progress("Adding user..."); + + xhrPost("backend.php", {op: "pref-users", method: "add", login: login}, (transport) => { + alert(transport.responseText); + Users.reload(); + }); + + } + }, + edit: function(id) { + const query = "backend.php?op=pref-users&method=edit&id=" + + param_escape(id); + + if (dijit.byId("userEditDlg")) + dijit.byId("userEditDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "userEditDlg", + title: __("User Editor"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + notify_progress("Saving data...", true); + + xhrPost("backend.php", dojo.formToObject("user_edit_form"), (transport) => { + dialog.hide(); + Users.reload(); + }); + } + }, + href: query + }); + + dialog.show(); + }, + resetSelected: function() { + const rows = this.getSelection(); + + if (rows.length == 0) { + alert(__("No users selected.")); + return; + } + + if (rows.length > 1) { + alert(__("Please select one user.")); + return; + } + + if (confirm(__("Reset password of selected user?"))) { + notify_progress("Resetting password for selected user..."); + + const id = rows[0]; + + xhrPost("backend.php", {op: "pref-users", method: "resetPass", id: id}, (transport) => { + notify(''); + alert(transport.responseText); + }); + + } + }, + removeSelected: function() { + const sel_rows = this.getSelection(); + + if (sel_rows.length > 0) { + if (confirm(__("Remove selected users? Neither default admin nor your account will be removed."))) { + notify_progress("Removing selected users..."); + + const query = { + op: "pref-users", method: "remove", + ids: sel_rows.toString() + }; + + xhrPost("backend.php", query, () => { + this.reload(); + }); + } + + } else { + 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("prefUserList"); + } + }); +}); + + -- cgit v1.2.3-54-g00ecf From f89924f7a19871e26d5805a6c1863903c6e474bf Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 18:38:27 +0300 Subject: set use strict on JS modules; remove some mostly useless stuff like get_minified_js() --- include/functions.php | 49 ----- include/login_form.php | 2 +- index.php | 9 +- js/Article.js | 2 + js/ArticleCache.js | 2 + js/CommonDialogs.js | 2 + js/CommonFilters.js | 2 + js/Feeds.js | 2 + js/Headlines.js | 4 +- js/PluginHost.js | 4 +- js/PrefUsers.js | 2 + js/Utils.js | 8 +- js/common.js | 493 +++++++++++++++++++++++++++++++++++++++++++++++++ js/functions.js | 492 ------------------------------------------------ js/prefs.js | 1 + js/tt-rss.js | 1 + prefs.php | 11 +- register.php | 2 +- 18 files changed, 524 insertions(+), 564 deletions(-) create mode 100755 js/common.js delete mode 100755 js/functions.js (limited to 'js/PrefUsers.js') diff --git a/include/functions.php b/include/functions.php index 2ec42c7ee..baed6fb20 100755 --- a/include/functions.php +++ b/include/functions.php @@ -1310,9 +1310,6 @@ $data['last_article_id'] = Article::getLastArticleId(); $data['cdm_expanded'] = get_pref('CDM_EXPANDED'); - $data['dep_ts'] = calculate_dep_timestamp(); - $data['reload_on_ts_change'] = !defined('_NO_RELOAD_ON_TS_CHANGE'); - $data["labels"] = Labels::get_all_labels($_SESSION["uid"]); if (CHECK_FOR_UPDATES && !$disable_update_check && $_SESSION["last_version_check"] + 86400 + rand(-1000, 1000) < time()) { @@ -2379,52 +2376,6 @@ return in_array($interface, class_implements($class)); } - function get_minified_js($files) { - - $rv = ''; - - foreach ($files as $js) { - if (!isset($_GET['debug'])) { - $cached_file = CACHE_DIR . "/js/".basename($js); - - if (file_exists($cached_file) && is_readable($cached_file) && filemtime($cached_file) >= filemtime("js/$js")) { - - list($header, $contents) = explode("\n", file_get_contents($cached_file), 2); - - if ($header && $contents) { - list($htag, $hversion) = explode(":", $header); - - if ($htag == "tt-rss" && $hversion == VERSION) { - $rv .= $contents; - continue; - } - } - } - - $minified = JShrink\Minifier::minify(file_get_contents("js/$js")); - file_put_contents($cached_file, "tt-rss:" . VERSION . "\n" . $minified); - $rv .= $minified; - - } else { - $rv .= file_get_contents("js/$js"); // no cache in debug mode - } - } - - return $rv; - } - - function calculate_dep_timestamp() { - $files = array_merge(glob("js/*.js"), glob("css/*.css")); - - $max_ts = -1; - - foreach ($files as $file) { - if (filemtime($file) > $max_ts) $max_ts = filemtime($file); - } - - return $max_ts; - } - function T_js_decl($s1, $s2) { if ($s1 && $s2) { $s1 = preg_replace("/\n/", "", $s1); diff --git a/include/login_form.php b/include/login_form.php index bb142f6c5..9c3a9b375 100644 --- a/include/login_form.php +++ b/include/login_form.php @@ -10,7 +10,7 @@ foreach (array("lib/prototype.js", "lib/dojo/dojo.js", "lib/dojo/tt-rss-layer.js", - "js/functions.js", + "js/common.js", "errors.php?mode=js") as $jsfile) { echo javascript_tag($jsfile); diff --git a/index.php b/index.php index 00bf42830..4a85ff236 100644 --- a/index.php +++ b/index.php @@ -103,6 +103,9 @@ "lib/scriptaculous/scriptaculous.js?load=effects,controls", "lib/dojo/dojo.js", "lib/dojo/tt-rss-layer.js", + "js/tt-rss.js", + "js/common.js", + "js/PluginHost.js", "errors.php?mode=js") as $jsfile) { echo javascript_tag($jsfile); @@ -110,13 +113,9 @@ } ?> + + +