Merge pull request #39 from Bonbadil/master

Add a publish button on article view for TTRSS.
This commit is contained in:
Jeena Paradies 2014-10-15 23:45:54 +02:00
commit 7c63205d36
4 changed files with 70 additions and 2 deletions

View file

@ -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;
}

View file

@ -87,6 +87,7 @@
<section id="full">
<header class="bar">
<a class="button icon list" href="#list">&#57349;</a>
<a id="setpublished" class="button icon" href="#published">&#9729;</a>
<a id="setstarred" class="button icon" href="#starred">&#9734;</a>
<a id="setunread" class="button icon" href="#unread"></a>
<canvas width="40" height="40"></canvas>

View file

@ -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 = "&#9734;";
}
if(article.published) {
$("#setpublished").innerHTML = "&#59153;";
} else {
$("#setpublished").innerHTML = "&#9729;";
}
};
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 = "&#59153;";
}
else {
article.published = false;
this.backend.setArticleUnpublished(article);
$("#setpublished").innerHTML = "&#9729;";
}
};
App.prototype.goToList = function() {
this.changeToPage("#list");
};

View file

@ -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];