'use strict' /* global __, ngettext */ define(["dojo/_base/declare"], function (declare) { Article = { _active_article_id: 0, selectionSetScore: function () { 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); row.removeClassName("score-low"); row.removeClassName("score-high"); row.removeClassName("score-half-low"); row.removeClassName("score-half-high"); row.removeClassName("score-neutral"); row.addClassName(reply["score_class"]); if (row) { const pic = row.select(".icon-score")[0]; if (pic) { pic.innerHTML = reply["score_pic"]; pic.setAttribute("data-score", reply["score"]); pic.setAttribute("title", reply["score"]); } } }); } }); } } else { alert(__("No articles selected.")); } }, setScore: function (id, pic) { const row = pic.up("div[id*=RROW]"); const score = pic.getAttribute("data-score"); const new_score = prompt(__("Please enter new score for this article:"), score); if (row && new_score != undefined) { const query = {op: "article", method: "setScore", id: id, score: new_score}; xhrJson("backend.php", query, (reply) => { if (reply) { pic.innerHTML = reply["score_pic"]; pic.setAttribute("data-score", new_score); pic.setAttribute("title", new_score); row.removeClassName("score-low"); row.removeClassName("score-high"); row.removeClassName("score-half-low"); row.removeClassName("score-half-high"); row.removeClassName("score-neutral"); row.addClassName(reply["score_class"]); } }); } }, cdmUnsetActive: function (event) { const row = $("RROW-" + Article.getActive()); if (row) { 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) event.stopPropagation(); return false; } }, close: function () { if (dijit.byId("content-insert")) dijit.byId("headlines-wrap-inner").removeChild( dijit.byId("content-insert")); }, displayUrl: function (id) { const query = {op: "rpc", method: "getlinktitlebyid", id: id}; xhrJson("backend.php", query, (reply) => { if (reply && reply.link) { prompt(__("Article URL:"), reply.link); } }); }, openInNewWindow: function (id) { const w = window.open(""); w.opener = null; w.location = "backend.php?op=article&method=redirect&id=" + id; Headlines.toggleUnread(id, 0); }, render: function (article) { App.cleanupMemory("content-insert"); dijit.byId("headlines-wrap-inner").addChild( dijit.byId("content-insert")); const c = dijit.byId("content-insert"); try { c.domNode.scrollTop = 0; } catch (e) { } c.attr('content', article); PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, c.domNode); Headlines.correctHeadlinesOffset(Article.getActive()); try { c.focus(); } catch (e) { } }, view: function (id, noexpand) { this.setActive(id); if (!noexpand) { console.log("loading article", id); const cids = []; /* only request uncached articles */ this.getRelativeIds(id).each((n) => { if (!ArticleCache.get(n)) cids.push(n); }); const cached_article = ArticleCache.get(id); if (cached_article) { console.log('rendering cached', id); this.render(cached_article); return false; } xhrPost("backend.php", {op: "article", method: "view", id: id, cids: cids.toString()}, (transport) => { try { const reply = App.handleRpcJson(transport); if (reply) { reply.each(function (article) { if (Article.getActive() == article['id']) { Article.render(article['content']); } ArticleCache.set(article['id'], article['content']); }); } else { console.error("Invalid object received: " + transport.responseText); Article.render("