sync article selected status via mutation observer

remove all rchk-related hacks
This commit is contained in:
Andrew Dolgov 2018-12-10 21:19:33 +03:00
parent c97c755195
commit ad5a43bf66
3 changed files with 43 additions and 62 deletions

View File

@ -79,12 +79,6 @@ define(["dojo/_base/declare"], function (declare) {
if (row) { if (row) {
row.removeClassName("active"); row.removeClassName("active");
const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]);
if (cb && !row.hasClassName("Selected"))
cb.attr("checked", false);
Article.setActive(0);
if (event) if (event)
event.stopPropagation(); event.stopPropagation();
@ -282,11 +276,6 @@ define(["dojo/_base/declare"], function (declare) {
$$("div[id*=RROW][class*=active]").each((e) => { $$("div[id*=RROW][class*=active]").each((e) => {
e.removeClassName("active"); e.removeClassName("active");
if (!e.hasClassName("Selected")) {
const cb = dijit.getEnclosingWidget(e.select(".rchk")[0]);
if (cb) cb.attr("checked", false);
}
}); });
const row = $("RROW-" + id); const row = $("RROW-" + id);
@ -294,21 +283,11 @@ define(["dojo/_base/declare"], function (declare) {
if (row) { if (row) {
Article.unpack(row); Article.unpack(row);
if (row.hasClassName("Unread")) { row.removeClassName("Unread");
Headlines.toggleUnread(id, 0);
}
row.addClassName("active"); row.addClassName("active");
if (!row.hasClassName("Selected")) {
const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]);
if (cb) cb.attr("checked", true);
}
PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, row.getAttribute("data-article-id")); PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, row.getAttribute("data-article-id"));
} }
//Headlines.updateSelectedPrompt();
}, },
getActive: function () { getActive: function () {
const row = document.querySelector("#headlines-frame > div[id*=RROW][class*=active]"); const row = document.querySelector("#headlines-frame > div[id*=RROW][class*=active]");

View File

@ -29,7 +29,7 @@ define(["dojo/_base/declare"], function (declare) {
hl.selected = row.hasClassName("Selected"); hl.selected = row.hasClassName("Selected");
hl.active = row.hasClassName("active"); hl.active = row.hasClassName("active");
modified.push({id: hl.id, new: hl, old: hl_old}); modified.push({id: hl.id, new: hl, old: hl_old, row: row});
} }
} }
} }
@ -46,6 +46,10 @@ define(["dojo/_base/declare"], function (declare) {
tpub: [], tpub: [],
read: [], read: [],
unread: [], unread: [],
select: [],
deselect: [],
activate: [],
deactivate: [],
}; };
modified.each(function(m) { modified.each(function(m) {
@ -57,6 +61,40 @@ define(["dojo/_base/declare"], function (declare) {
if (m.old.unread != m.new.unread) if (m.old.unread != m.new.unread)
m.new.unread ? ops.unread.push(m.id) : ops.read.push(m.id); m.new.unread ? ops.unread.push(m.id) : ops.read.push(m.id);
if (m.old.selected != m.new.selected)
m.new.selected ? ops.select.push(m.row) : ops.deselect.push(m.row);
if (m.old.active != m.new.active)
m.new.active ? ops.activate.push(m.row) : ops.deactivate.push(m.row);
});
ops.select.each((row) => {
const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]);
if (cb)
cb.attr('checked', true);
});
ops.deselect.each((row) => {
const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]);
if (cb && !row.hasClassName("active"))
cb.attr('checked', false);
});
ops.activate.each((row) => {
const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]);
if (cb)
cb.attr('checked', true);
});
ops.deactivate.each((row) => {
const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]);
if (cb && !row.hasClassName("Selected"))
cb.attr('checked', false);
}); });
if (ops.tmark.length != 0) if (ops.tmark.length != 0)
@ -924,8 +962,6 @@ define(["dojo/_base/declare"], function (declare) {
} else { } else {
row.removeClassName("Selected"); row.removeClassName("Selected");
} }
//this.updateSelectedPrompt();
}, },
select: function (mode, articleId) { select: function (mode, articleId) {
// mode = all,none,unread,invert,marked,published // mode = all,none,unread,invert,marked,published
@ -955,32 +991,17 @@ define(["dojo/_base/declare"], function (declare) {
for (let i = 0; i < rows.length; i++) { for (let i = 0; i < rows.length; i++) {
const row = rows[i]; const row = rows[i];
const cb = dijit.getEnclosingWidget(row.select(".rchk")[0]);
switch (mode) { switch (mode) {
case "none": case "none":
row.removeClassName("Selected"); row.removeClassName("Selected");
if (!row.hasClassName("active"))
cb.attr("checked", false);
break; break;
case "invert": case "invert":
if (row.hasClassName("Selected")) { row.toggleClassName("Selected");
row.removeClassName("Selected");
if (!row.hasClassName("active"))
cb.attr("checked", false);
} else {
row.addClassName("Selected");
cb.attr("checked", true);
}
break; break;
default: default:
row.addClassName("Selected"); row.addClassName("Selected");
cb.attr("checked", true);
} }
//Headlines.updateSelectedPrompt();
} }
}, },
archiveSelection: function () { archiveSelection: function () {
@ -1090,15 +1111,6 @@ define(["dojo/_base/declare"], function (declare) {
var e = $("RROW-" + ids_to_mark[i]); var e = $("RROW-" + ids_to_mark[i]);
e.removeClassName("Unread"); e.removeClassName("Unread");
} }
const query = {
op: "rpc", method: "catchupSelected",
cmode: 0, ids: ids_to_mark.toString()
};
xhrPost("backend.php", query, (transport) => {
App.handleRpcJson(transport);
});
} }
} }
}, },

View File

@ -396,18 +396,8 @@ require(["dojo/_base/kernel",
if (id) { if (id) {
const row = $("RROW-" + id); const row = $("RROW-" + id);
if (row) { if (row)
const cb = dijit.getEnclosingWidget( row.toggleClassName("Selected");
row.select(".rchk")[0]);
if (cb) {
if (!row.hasClassName("active"))
cb.attr("checked", !cb.attr("checked"));
Headlines.onRowChecked(cb);
return false;
}
}
} }
}; };
this.hotkey_actions["create_label"] = function () { this.hotkey_actions["create_label"] = function () {