forked from timendum/ttportal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrss.js
153 lines (152 loc) · 4.68 KB
/
rss.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* jshint curly: true, eqeqeq: true, forin: true, freeze: true, immed: true, indent: 4, latedef: true, undef: true, unused: true, sub: true, trailing: true */
/* jshint browser: true, jquery: true */
var ttRss = {
base: null,
session: null,
categoryId: null,
errorHandler: function() {alert('Error during request');},
sessionErrorHandler: function() {alert('Error for session');},
_errorHandler: function(c, e, s) {
var t = this,
errorHandler = e || t.errorHandler,
sessionErrorHandler = s || t.sessionErrorHandler;
if (c.noWrap) {
return c;
} else {
return function(d, r) {
if (r === "success") {
if (d.content) {
if (!d.content.error) {
c(d.content);
return;
}
if (d.content.error && d.content.error === "NOT_LOGGED_IN") {
t.session = null;
sessionErrorHandler(d);
return;
}
}
}
errorHandler(d);
return;
};
}
},
_is_cat: function(id) {
return parseInt(id) < 100;
},
_request: function(op, c, data, e, s) {
var base = this.base;
data = data || {};
data['op'] = op;
if (this.session) {
data['sid'] = this.session;
}
jQuery.post(
base,
JSON.stringify(data),
'json'
).always(this._errorHandler(c, e, s));
},
isLoggedIn: function(c) {
if (this.base === null) {
c({content: {status: false}}, "success");
return;
}
c.noWrap = true;
this._request('isLoggedIn', c);
},
_loginHandler: function(c, t) {
return function(data) {
if (data && data.session_id) {
t.session = data.session_id;
c(true);
} else {
t.session = false;
c(false);
}
};
},
login: function(user, pass, c) {
var lh = this._loginHandler;
var t = this;
var loginError = function () {
if (t.session) {
t.session = null;
alert('Error for session, retry');
} else {
t.sessionErrorHandler();
}
};
this._request('login', lh(c, this), {user: user, password: pass}, loginError);
},
logout: function(c) {
this._request('logout', c);
},
getCategories: function(c) {
var t = this,
w = function(data) {
for (var i = 0; i < data.length; i++) {
if (data[i].title.toUpperCase() === "PORTAL") {
t.categoryId = data[i].id;
c(data[i].id);
return;
}
}
c(0);
return;
};
t._request('getCategories', w);
},
getFeeds: function(c) {
var t = this,
w = {
cat_id: t.categoryId,
include_nested: true
};
t._request('getFeeds', c, w);
},
getUpdatedContent: function(id, limit, skip, c) {
var t = this;
this._request(
'updateFeed',
function() {
t.getContent(id, limit, skip, c);
},
{feed_id: id}
);
},
getContent: function(id, limit, skip, c, onlyUnread) {
var is_cat = this._is_cat(id);
onlyUnread = onlyUnread || false;
this._request('getHeadlines', c,
{
feed_id: id,
is_cat: is_cat,
limit: limit,
skip: skip,
show_excerpt: true,
excerpt_length: 100,
//show_content: true,
view_mode: (onlyUnread ? 'unread' :'all_articles'), //all_articles, unread, adaptive, marked, updated)
order_by: 'feed_dates'// date_reverse, feed_dates, (nothing)
}
);
},
markReadItem: function(id, c) {
this._request('updateArticle', c, {
article_ids: id,
mode: 0, //0 - set to false, 1 - set to true, 2 - toggle
field: 2 // 0 - starred, 1 - published, 2 - unread, 3 - article note since api level 1)
});
},
markReadFeed: function(id, c) {
var is_cat = this._is_cat(id);
this._request('catchupFeed', c,
{
feed_id: id,
is_cat: is_cat
}
);
}
};