prefs: store active tab for reload, remove most old table row functions

This commit is contained in:
Andrew Dolgov 2018-12-02 11:25:32 +03:00
parent aa2f119eb6
commit e23b6e397d
5 changed files with 70 additions and 94 deletions

View File

@ -1412,9 +1412,9 @@ class Pref_Feeds extends Handler_Protected {
print "<div dojoType=\"dijit.form.DropDownButton\">". print "<div dojoType=\"dijit.form.DropDownButton\">".
"<span>" . __('Select')."</span>"; "<span>" . __('Select')."</span>";
print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'all')\" print "<div onclick=\"Tables.select('prefInactiveFeedList', true)\"
dojoType=\"dijit.MenuItem\">".__('All')."</div>"; dojoType=\"dijit.MenuItem\">".__('All')."</div>";
print "<div onclick=\"selectTableRows('prefInactiveFeedList', 'none')\" print "<div onclick=\"Tables.select('prefInactiveFeedList', false)\"
dojoType=\"dijit.MenuItem\">".__('None')."</div>"; dojoType=\"dijit.MenuItem\">".__('None')."</div>";
print "</div></div>"; print "</div></div>";
print "</div>"; #toolbar print "</div>"; #toolbar
@ -1428,15 +1428,12 @@ class Pref_Feeds extends Handler_Protected {
while ($line = $sth->fetch()) { while ($line = $sth->fetch()) {
$feed_id = $line["id"]; $feed_id = $line["id"];
$this_row_id = "id=\"FUPDD-$feed_id\"";
# class needed for selectTableRows() print "<tr class=\"placeholder\" data-row-id='$feed_id'>";
print "<tr class=\"placeholder\" $this_row_id>";
# id needed for selectTableRows()
print "<td width='5%' align='center'><input print "<td width='5%' align='center'><input
onclick='Tables.onRowChecked(this);' dojoType=\"dijit.form.CheckBox\" onclick='Tables.onRowChecked(this);' dojoType=\"dijit.form.CheckBox\"
type=\"checkbox\" id=\"FUPDC-$feed_id\"></td>"; type=\"checkbox\"></td>";
print "<td>"; print "<td>";
print "<a class=\"visibleLink\" href=\"#\" ". print "<a class=\"visibleLink\" href=\"#\" ".
@ -1477,9 +1474,9 @@ class Pref_Feeds extends Handler_Protected {
print "<div dojoType=\"dijit.form.DropDownButton\">". print "<div dojoType=\"dijit.form.DropDownButton\">".
"<span>" . __('Select')."</span>"; "<span>" . __('Select')."</span>";
print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
print "<div onclick=\"selectTableRows('prefErrorFeedList', 'all')\" print "<div onclick=\"Tables.select('prefErrorFeedList', true)\"
dojoType=\"dijit.MenuItem\">".__('All')."</div>"; dojoType=\"dijit.MenuItem\">".__('All')."</div>";
print "<div onclick=\"selectTableRows('prefErrorFeedList', 'none')\" print "<div onclick=\"Tables.select('prefErrorFeedList', false)\"
dojoType=\"dijit.MenuItem\">".__('None')."</div>"; dojoType=\"dijit.MenuItem\">".__('None')."</div>";
print "</div></div>"; print "</div></div>";
print "</div>"; #toolbar print "</div>"; #toolbar
@ -1493,15 +1490,12 @@ class Pref_Feeds extends Handler_Protected {
while ($line = $sth->fetch()) { while ($line = $sth->fetch()) {
$feed_id = $line["id"]; $feed_id = $line["id"];
$this_row_id = "id=\"FERDD-$feed_id\"";
# class needed for selectTableRows() print "<tr class=\"placeholder\" data-row-id='$feed_id'>";
print "<tr class=\"placeholder\" $this_row_id>";
# id needed for selectTableRows()
print "<td width='5%' align='center'><input print "<td width='5%' align='center'><input
onclick='Tables.onRowChecked(this);' dojoType=\"dijit.form.CheckBox\" onclick='Tables.onRowChecked(this);' dojoType=\"dijit.form.CheckBox\"
type=\"checkbox\" id=\"FERDC-$feed_id\"></td>"; type=\"checkbox\"></td>";
print "<td>"; print "<td>";
print "<a class=\"visibleLink\" href=\"#\" ". print "<a class=\"visibleLink\" href=\"#\" ".

View File

@ -992,9 +992,9 @@ class Pref_Prefs extends Handler_Protected {
print "<div dojoType=\"dijit.form.DropDownButton\">". print "<div dojoType=\"dijit.form.DropDownButton\">".
"<span>" . __('Select')."</span>"; "<span>" . __('Select')."</span>";
print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
print "<div onclick=\"selectTableRows('prefFeedProfileList', 'all')\" print "<div onclick=\"Tables.select('prefFeedProfileList', true)\"
dojoType=\"dijit.MenuItem\">".__('All')."</div>"; dojoType=\"dijit.MenuItem\">".__('All')."</div>";
print "<div onclick=\"selectTableRows('prefFeedProfileList', 'none')\" print "<div onclick=\"Tables.select('prefFeedProfileList', false)\"
dojoType=\"dijit.MenuItem\">".__('None')."</div>"; dojoType=\"dijit.MenuItem\">".__('None')."</div>";
print "</div></div>"; print "</div></div>";
@ -1019,10 +1019,9 @@ class Pref_Prefs extends Handler_Protected {
print "<table width=\"100%\" class=\"prefFeedProfileList\" print "<table width=\"100%\" class=\"prefFeedProfileList\"
cellspacing=\"0\" id=\"prefFeedProfileList\">"; cellspacing=\"0\" id=\"prefFeedProfileList\">";
print "<tr class=\"placeholder\" id=\"FCATR-0\">"; #odd print "<tr class=\"placeholder\">"; # data-row-id='0' <-- no point, shouldn't be removed
print "<td width='5%' align='center'><input print "<td width='5%' align='center'><input
id='FCATC-0'
onclick='Tables.onRowChecked(this);' onclick='Tables.onRowChecked(this);'
dojoType=\"dijit.form.CheckBox\" dojoType=\"dijit.form.CheckBox\"
type=\"checkbox\"></td>"; type=\"checkbox\"></td>";
@ -1043,15 +1042,13 @@ class Pref_Prefs extends Handler_Protected {
while ($line = $sth->fetch()) { while ($line = $sth->fetch()) {
$profile_id = $line["id"]; $profile_id = $line["id"];
$this_row_id = "id=\"FCATR-$profile_id\"";
print "<tr class=\"placeholder\" $this_row_id>"; print "<tr class=\"placeholder\" data-row-id='$profile_id'>";
$edit_title = htmlspecialchars($line["title"]); $edit_title = htmlspecialchars($line["title"]);
print "<td width='5%' align='center'><input print "<td width='5%' align='center'><input
onclick='Tables.onRowChecked(this);' onclick='Tables.onRowChecked(this);'
id='FCATC-$profile_id'
dojoType=\"dijit.form.CheckBox\" dojoType=\"dijit.form.CheckBox\"
type=\"checkbox\"></td>"; type=\"checkbox\"></td>";

View File

@ -354,9 +354,9 @@ class Pref_Users extends Handler_Protected {
print "<div dojoType=\"dijit.form.DropDownButton\">". print "<div dojoType=\"dijit.form.DropDownButton\">".
"<span>" . __('Select')."</span>"; "<span>" . __('Select')."</span>";
print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
print "<div onclick=\"selectTableRows('prefUserList', 'all')\" print "<div onclick=\"Tables.select('prefUserList', true)\"
dojoType=\"dijit.MenuItem\">".__('All')."</div>"; dojoType=\"dijit.MenuItem\">".__('All')."</div>";
print "<div onclick=\"selectTableRows('prefUserList', 'none')\" print "<div onclick=\"Tables.select('prefUserList', false)\"
dojoType=\"dijit.MenuItem\">".__('None')."</div>"; dojoType=\"dijit.MenuItem\">".__('None')."</div>";
print "</div></div>"; print "</div></div>";
@ -412,7 +412,7 @@ class Pref_Users extends Handler_Protected {
$uid = $line["id"]; $uid = $line["id"];
print "<tr id=\"UMRR-$uid\">"; print "<tr data-row-id=\"$uid\">";
$line["login"] = htmlspecialchars($line["login"]); $line["login"] = htmlspecialchars($line["login"]);
@ -420,8 +420,7 @@ class Pref_Users extends Handler_Protected {
$line["last_login"] = make_local_datetime($line["last_login"], false); $line["last_login"] = make_local_datetime($line["last_login"], false);
print "<td align='center'><input onclick='Tables.onRowChecked(this);' print "<td align='center'><input onclick='Tables.onRowChecked(this);'
dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" dojoType=\"dijit.form.CheckBox\" type=\"checkbox\"></td>";
id=\"UMCHK-$uid\"></td>";
$onclick = "onclick='editUser($uid, event)' title='".__('Click to edit')."'"; $onclick = "onclick='editUser($uid, event)' title='".__('Click to edit')."'";

View File

@ -55,10 +55,14 @@ Array.prototype.remove = function(s) {
const Lists = { const Lists = {
onRowChecked: function(elem) { onRowChecked: function(elem) {
const checked = elem.domNode ? elem.attr("checked") : elem.checked;
// account for dojo checkboxes // account for dojo checkboxes
elem = elem.domNode || elem; elem = elem.domNode || elem;
elem.up("li").toggleClassName("Selected"); const row = elem.up("li");
if (row)
checked ? row.addClassName("Selected") : row.removeClassName("Selected");
} }
}; };
@ -66,9 +70,30 @@ const Lists = {
const Tables = { const Tables = {
onRowChecked: function(elem) { onRowChecked: function(elem) {
// account for dojo checkboxes // account for dojo checkboxes
const checked = elem.domNode ? elem.attr("checked") : elem.checked;
elem = elem.domNode || elem; elem = elem.domNode || elem;
elem.up("tr").toggleClassName("Selected"); const row = elem.up("tr");
if (row)
checked ? row.addClassName("Selected") : row.removeClassName("Selected");
},
select: function(elemId, selected) {
$(elemId).select("tr").each((row) => {
const checkNode = row.select(".dijitCheckBox,input[type=checkbox]")[0];
if (checkNode) {
const widget = dijit.getEnclosingWidget(checkNode);
if (widget) {
widget.attr("checked", selected);
} else {
checkNode.checked = selected;
}
this.onRowChecked(widget);
}
});
}, },
getSelected: function(elemId) { getSelected: function(elemId) {
const rv = []; const rv = [];
@ -1532,60 +1557,6 @@ function uploadFeedIcon() {
return false; return false;
} }
// mode = all, none, invert
function selectTableRows(id, mode) {
const rows = $(id).rows;
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
let cb = false;
let dcb = false;
if (row.id && row.className) {
const bare_id = row.id.replace(/^[A-Z]*?-/, "");
const inputs = rows[i].getElementsByTagName("input");
for (let j = 0; j < inputs.length; j++) {
const input = inputs[j];
if (input.getAttribute("type") == "checkbox" &&
input.id.match(bare_id)) {
cb = input;
dcb = dijit.getEnclosingWidget(cb);
break;
}
}
if (cb || dcb) {
const issel = row.hasClassName("Selected");
if (mode == "all" && !issel) {
row.addClassName("Selected");
cb.checked = true;
if (dcb) dcb.set("checked", true);
} else if (mode == "none" && issel) {
row.removeClassName("Selected");
cb.checked = false;
if (dcb) dcb.set("checked", false);
} else if (mode == "invert") {
if (issel) {
row.removeClassName("Selected");
cb.checked = false;
if (dcb) dcb.set("checked", false);
} else {
row.addClassName("Selected");
cb.checked = true;
if (dcb) dcb.set("checked", true);
}
}
}
}
}
}
// noinspection JSUnusedGlobalSymbols // noinspection JSUnusedGlobalSymbols
function label_to_feed_id(label) { function label_to_feed_id(label) {
return _label_base_index - 1 - Math.abs(label); return _label_base_index - 1 - Math.abs(label);

View File

@ -73,18 +73,34 @@ const App = {
if (tab) { if (tab) {
tab = dijit.byId(tab + "Tab"); tab = dijit.byId(tab + "Tab");
if (tab) dijit.byId("pref-tabs").selectChild(tab); if (tab) {
dijit.byId("pref-tabs").selectChild(tab);
switch (Utils.urlParam('method')) {
case "editfeed":
window.setTimeout(function () {
CommonDialogs.editFeed(Utils.urlParam('methodparam'))
}, 100);
break;
default:
console.warn("initSecondStage, unknown method:", Utils.urlParam("method"));
}
}
} else {
let tab = localStorage.getItem("ttrss:prefs-tab");
if (tab) {
tab = dijit.byId(tab);
if (tab) {
dijit.byId("pref-tabs").selectChild(tab);
}
}
} }
const method = Utils.urlParam('method'); dojo.connect(dijit.byId("pref-tabs"), "selectChild", function (elem) {
localStorage.setItem("ttrss:prefs-tab", elem.id);
});
if (method == 'editFeed') {
const param = Utils.urlParam('methodparam');
window.setTimeout(function () {
CommonDialogs.editFeed(param)
}, 100);
}
}, },
hotkeyHandler: function (event) { hotkeyHandler: function (event) {
if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return;
@ -725,8 +741,8 @@ function updateSystemList() {
}); });
} }
function selectTab(id, noupdate) { function selectTab(id, selectOnly) {
if (!noupdate) { if (!selectOnly) {
notify_progress("Loading, please wait..."); notify_progress("Loading, please wait...");
switch (id) { switch (id) {
@ -754,7 +770,6 @@ function selectTab(id, noupdate) {
const tab = dijit.byId(id + "Tab"); const tab = dijit.byId(id + "Tab");
dijit.byId("pref-tabs").selectChild(tab); dijit.byId("pref-tabs").selectChild(tab);
} }
} }