summaryrefslogtreecommitdiff
path: root/js/Article.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-12-11 10:30:32 +0300
committerAndrew Dolgov <[email protected]>2018-12-11 10:30:32 +0300
commitf3c04fc5d85d1e411e731af95074e604e60abafb (patch)
tree5290f99e07312caba8fc4f3aacaed07168ab453d /js/Article.js
parent25ca144bb775f29dfc152a87c975f1fcdb367174 (diff)
sync modified scores via mutation observer
Diffstat (limited to 'js/Article.js')
-rw-r--r--js/Article.js65
1 files changed, 28 insertions, 37 deletions
diff --git a/js/Article.js b/js/Article.js
index cfba3804b..e281ea5ae 100644
--- a/js/Article.js
+++ b/js/Article.js
@@ -30,37 +30,27 @@ define(["dojo/_base/declare"], function (declare) {
const ids = Headlines.getSelected();
if (ids.length > 0) {
- console.log(ids);
-
const score = prompt(__("Please enter new score for selected articles:"));
- if (score != undefined) {
- const query = {
- op: "article", method: "setScore", id: ids.toString(),
- score: score
- };
-
- xhrJson("backend.php", query, (reply) => {
- if (reply) {
- reply.id.each((id) => {
- const row = $("RROW-" + id);
+ if (parseInt(score) != undefined) {
+ ids.each((id) => {
+ const row = $("RROW-" + id);
- ["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
- .each(function(scl) {
- row.removeClassName(scl);
- });
+ if (row) {
+ row.setAttribute("data-score", score);
- row.addClassName(Article.getScoreClass(reply['score']));
+ const pic = row.select(".icon-score")[0];
- if (row) {
- row.setAttribute("data-score", reply["score"]);
+ pic.innerHTML = Article.getScorePic(score);
+ pic.setAttribute("title", score);
- const pic = row.select(".icon-score")[0];
+ ["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
+ .each(function(scl) {
+ if (row.hasClassName(scl))
+ row.removeClassName(scl);
+ });
- pic.innerHTML = reply["score_pic"];
- pic.setAttribute("title", reply["score"]);
- }
- });
+ row.addClassName(Article.getScoreClass(score));
}
});
}
@@ -71,26 +61,27 @@ define(["dojo/_base/declare"], function (declare) {
},
setScore: function (id, pic) {
const row = pic.up("div[id*=RROW]");
- const score = row.getAttribute("data-score");
- const new_score = prompt(__("Please enter new score for this article:"), score);
+ if (row) {
+ const score_old = row.getAttribute("data-score");
+ const score = prompt(__("Please enter new score for this article:"), score_old);
+
+ if (parseInt(score) != undefined) {
+ row.setAttribute("data-score", score);
- if (row && new_score != undefined) {
- const query = {op: "article", method: "setScore", id: id, score: new_score};
+ const pic = row.select(".icon-score")[0];
- xhrJson("backend.php", query, (reply) => {
- if (reply) {
- pic.innerHTML = reply["score_pic"];
- row.setAttribute("title", new_score);
+ pic.innerHTML = Article.getScorePic(score);
+ pic.setAttribute("title", score);
- ["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
- .each(function(scl) {
+ ["score-low", "score-high", "score-half-low", "score-half-high", "score-neutral"]
+ .each(function(scl) {
+ if (row.hasClassName(scl))
row.removeClassName(scl);
});
- row.addClassName(Article.getScoreClass(reply['score']));
- }
- });
+ row.addClassName(Article.getScoreClass(score));
+ }
}
},
cdmUnsetActive: function (event) {