diff --git a/css/screen.css b/css/screen.css index b0f4b1b..88bd159 100644 --- a/css/screen.css +++ b/css/screen.css @@ -120,11 +120,14 @@ section > header h1 { overflow: auto; } -.reload, .all-read, #setstarred, #setunread { +.reload, .all-read, #setstarred, #setunread, #setpublished { float: right; margin-left: 10px; } +#setpublished { display: none;} +#setpublished.active { display: inline;} + .settings, .list { float: left; } diff --git a/index.html b/index.html index 8c4e733..bbd0e05 100644 --- a/index.html +++ b/index.html @@ -87,6 +87,7 @@
+ P diff --git a/js/App.js b/js/App.js index 520f9ab..3d1d674 100644 --- a/js/App.js +++ b/js/App.js @@ -54,6 +54,8 @@ App.prototype.after_login = function(backend) { _this.toggleCurrentUnread(); } else if(url == "#starred") { _this.toggleStarred(); + } else if(url == "#published") { + _this.togglePublished(); } else if(url == "#logout") { _this.logout(); } else if(url == "#reset-info") { @@ -109,6 +111,7 @@ App.prototype.after_login = function(backend) { this.backend = new Pond(this, localStorage.server_url, localStorage.session_id) } else { this.backend = new TinyTinyRSS(this, localStorage.server_url, localStorage.session_id); + $("#setpublished").addClass("active"); } var numArticles = localStorage.numArticles; @@ -346,6 +349,12 @@ App.prototype.showFull = function(article, slide_back) { $("#setstarred").innerHTML = "☆"; } + if(article.published) { + $("#setpublished").innerHTML = "U"; + } else { + $("#setpublished").innerHTML = "P"; + } + }; App.prototype.showNext = function() { @@ -455,6 +464,23 @@ App.prototype.toggleStarred = function() { }; +App.prototype.togglePublished = function() { + var article = this.unread_articles[this.currentIndex]; + if(!article) return; // happens if we're not on a full article site + + if(!article.published) { + article.published = true; + this.backend.setArticlePublished(article); + $("#setpublished").innerHTML = "U"; + } + else { + article.published = false; + this.backend.setArticleUnpublished(article); + $("#setpublished").innerHTML = "P"; + } + +}; + App.prototype.goToList = function() { this.changeToPage("#list"); }; diff --git a/js/TinyTinyRSS.js b/js/TinyTinyRSS.js index 64edd78..2644d02 100644 --- a/js/TinyTinyRSS.js +++ b/js/TinyTinyRSS.js @@ -13,7 +13,7 @@ TinyTinyRSS.prototype.onoffline = function() { TinyTinyRSS.prototype.ononline = function() { - ["read", "unread", "starred", "unstarred"].forEach(function(type) { + ["read", "unread", "starred", "unstarred", "published", "unpublished"].forEach(function(type) { var articles = localStorage[type + "_articles"]; if(articles) { var callback = function(ok) { if(ok) localStorage[type + "_articles"] = null } @@ -149,6 +149,44 @@ TinyTinyRSS.prototype.setArticleUnstarred = function(article, callback) { this.setArticlesUnstarred([article], callback); }; +TinyTinyRSS.prototype.setArticlesPublished = function(articles, callback) { + + var options = { + article_ids: articles.map(function(o) { return o.id }).join(","), + mode: 1, + field: 1 + }; + + if (navigator.onLine) { + this.doOperation("updateArticle", options); + } else { + this.append("published_articles", articles); + } +}; + +TinyTinyRSS.prototype.setArticlePublished = function(article, callback) { + this.setArticlesPublished([article], callback); +}; + +TinyTinyRSS.prototype.setArticlesUnpublished = function(articles, callback) { + + var options = { + article_ids: articles.map(function(o) { return o.id}).join(","), + mode: 0, + field: 1 + }; + + if (navigator.onLine) { + this.doOperation("updateArticle", options, callback); + } else { + this.append("unpublished_articles", articles); + } +}; + +TinyTinyRSS.prototype.setArticleUnpublished = function(article, callback) { + this.setArticlesUnpublished([article], callback); +}; + TinyTinyRSS.prototype.append = function(key, array) { var tmp = localStorage[key];