]> git.wh0rd.org Git - tt-rss.git/blob - viewfeed.js
fix notify box, add notify prompt in viewfeed
[tt-rss.git] / viewfeed.js
1 var active_post_id = false;
2
3 //var xmlhttp_rpc = Ajax.getTransport();
4
5 function headlines_callback() {
6         if (xmlhttp.readyState == 4) {
7                 debug("headlines_callback");
8                 var f = document.getElementById("headlines-frame");
9                 f.innerHTML = xmlhttp.responseText;
10                 update_all_counters();
11                 notify("");
12         }
13 }
14
15 function article_callback() {
16         if (xmlhttp.readyState == 4) {
17                 debug("article_callback");
18                 var f = document.getElementById("content-frame");
19                 f.innerHTML = xmlhttp.responseText;
20                 update_all_counters();
21         }
22 }
23
24 function view(id, feed_id) {
25         
26         try {
27                 debug("loading article: " + id + "/" + feed_id);
28         
29                 var f_document = getFeedsContext().document;
30                 var m_document = document;
31         
32                 enableHotkeys();
33         
34                 var crow = document.getElementById("RROW-" + id);
35         
36                 crow.className = crow.className.replace("Unread", "");
37         
38                 cleanSelected("headlinesList");
39         
40                 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
41         
42                 if (upd_img_pic) {
43                         upd_img_pic.src = "images/blank_icon.gif";
44                 } 
45         
46                 active_post_id = id; 
47                 setActiveFeedId(feed_id);
48         
49                 var content = m_document.getElementById("content-frame");
50         
51                 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
52                 markHeadline(active_post_id);
53
54                 var query = "backend.php?op=view&id=" + param_escape(id) +
55                         "&feed=" + param_escape(feed_id);
56
57                 if (xmlhttp_ready(xmlhttp)) {
58                         xmlhttp.open("GET", query, true);
59                         xmlhttp.onreadystatechange=article_callback;
60                         xmlhttp.send(null);
61                 } else {
62                         debug("xmlhttp busy (@view)");
63                 }  
64
65         } catch (e) {
66                 exception_error("view", e);
67         }
68 }
69
70 function toggleMark(id) {
71
72         var f_document = document;
73
74         if (!xmlhttp_ready(xmlhttp_rpc)) {
75                 printLockingError();
76                 return;
77         }
78
79         var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
80
81         var mark_img = document.getElementById("FMARKPIC-" + id);
82         var vfeedu = f_document.getElementById("FEEDU--1");
83         var crow = document.getElementById("RROW-" + id);
84
85         if (mark_img.alt != "Reset mark") {
86                 mark_img.src = "images/mark_set.png";
87                 mark_img.alt = "Reset mark";
88                 query = query + "&mark=1";
89
90                 if (vfeedu && crow.className.match("Unread")) {
91                         vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
92                 }
93
94         } else {
95                 mark_img.src = "images/mark_unset.png";
96                 mark_img.alt = "Set mark";
97                 query = query + "&mark=0";
98
99                 if (vfeedu && crow.className.match("Unread")) {
100                         vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
101                 }
102
103         }
104
105         var vfeedctr = f_document.getElementById("FEEDCTR--1");
106         var vfeedr = f_document.getElementById("FEEDR--1");
107
108         if (vfeedu && vfeedctr) {
109                 if ((+vfeedu.innerHTML) > 0) {
110                         if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
111                                 vfeedr.className = vfeedr.className + "Unread";
112                                 vfeedctr.className = "odd";
113                         }
114                 } else {
115                         vfeedctr.className = "invisible";
116                         vfeedr.className = vfeedr.className.replace("Unread", "");
117                 }
118         }
119
120         debug("toggle starred for aid " + id);
121
122         new Ajax.Request(query);
123
124 }
125
126 function moveToPost(mode) {
127
128         // check for combined mode
129         if (!document.getElementById("headlinesList"))
130                 return;
131
132         var rows = getVisibleHeadlineIds();
133
134         var prev_id;
135         var next_id;
136
137         if (active_post_id == false) {
138                 next_id = getFirstVisibleHeadlineId();
139                 prev_id = getLastVisibleHeadlineId();
140         } else {        
141                 for (var i = 0; i < rows.length; i++) {
142                         if (rows[i] == active_post_id) {
143                                 prev_id = rows[i-1];
144                                 next_id = rows[i+1];                    
145                         }
146                 }
147         }
148
149         if (mode == "next") {
150                 if (next_id != undefined) {
151                         view(next_id, getActiveFeedId());
152                 }
153         }
154
155         if (mode == "prev") {
156                 if ( prev_id != undefined) {
157                         view(prev_id, getActiveFeedId());
158                 }
159         } 
160 }
161
162 function toggleUnread(id, cmode) {
163         try {
164                 if (!xmlhttp_ready(xmlhttp_rpc)) {
165                         printLockingError();
166                         return;
167                 }
168         
169                 var row = document.getElementById("RROW-" + id);
170                 if (row) {
171                         var nc = row.className;
172                         nc = nc.replace("Unread", "");
173                         nc = nc.replace("Selected", "");
174
175                         if (row.className.match("Unread")) {
176                                 row.className = nc;
177                         } else {
178                                 row.className = nc + "Unread";
179                         }
180
181                         if (!cmode) cmode = 2;
182
183                         var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
184                                 param_escape(id) + "&cmode=" + param_escape(cmode);
185
186                         xmlhttp_rpc.open("GET", query, true);
187                         xmlhttp_rpc.onreadystatechange=all_counters_callback;
188                         xmlhttp_rpc.send(null);
189
190                 }
191
192
193         } catch (e) {
194                 exception_error("toggleUnread", e);
195         }
196 }
197
198 function selectionToggleUnread(cdm_mode, set_state) {
199         try {
200                 if (!xmlhttp_ready(xmlhttp_rpc)) {
201                         printLockingError();
202                         return;
203                 }
204         
205                 var rows;
206
207                 if (cdm_mode) {
208                         rows = cdmGetSelectedArticles();
209                 } else {        
210                         rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
211                 }
212
213                 for (i = 0; i < rows.length; i++) {
214                         var row = document.getElementById("RROW-" + rows[i]);
215                         if (row) {
216                                 var nc = row.className;
217                                 nc = nc.replace("Unread", "");
218                                 nc = nc.replace("Selected", "");
219
220                                 if (row.className.match("Unread")) {
221                                         row.className = nc + "Selected";
222                                 } else {
223                                         row.className = nc + "UnreadSelected";
224                                 }
225                         }
226                 }
227
228                 if (rows.length > 0) {
229
230                         var cmode = "";
231
232                         if (set_state == undefined) {
233                                 cmode = "2";
234                         } else if (set_state == true) {
235                                 cmode = "1";
236                         } else if (set_state == false) {
237                                 cmode = "0";
238                         }
239
240                         var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
241                                 param_escape(rows.toString()) + "&cmode=" + cmode;
242
243                         xmlhttp_rpc.open("GET", query, true);
244                         xmlhttp_rpc.onreadystatechange=all_counters_callback;
245                         xmlhttp_rpc.send(null);
246
247                 }
248
249         } catch (e) {
250                 exception_error("selectionToggleUnread", e);
251         }
252 }
253
254 function selectionToggleMarked(cdm_mode) {
255         try {
256                 if (!xmlhttp_ready(xmlhttp_rpc)) {
257                         printLockingError();
258                         return;
259                 }
260         
261                 var rows;
262                 
263                 if (cdm_mode) {
264                         rows = cdmGetSelectedArticles();
265                 } else {        
266                         rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
267                 }       
268
269                 for (i = 0; i < rows.length; i++) {
270                         var row = document.getElementById("RROW-" + rows[i]);
271                         var mark_img = document.getElementById("FMARKPIC-" + rows[i]);
272
273                         if (row && mark_img) {
274
275                                 if (mark_img.alt == "Set mark") {
276                                         mark_img.src = "images/mark_set.png";
277                                         mark_img.alt = "Reset mark";
278                                         mark_img.setAttribute('onclick', 
279                                                 'javascript:toggleMark('+rows[i]+', false)');
280
281                                 } else {
282                                         mark_img.src = "images/mark_unset.png";
283                                         mark_img.alt = "Set mark";
284                                         mark_img.setAttribute('onclick', 
285                                                 'javascript:toggleMark('+rows[i]+', true)');
286                                 }
287                         }
288                 }
289
290                 if (rows.length > 0) {
291
292                         var query = "backend.php?op=rpc&subop=markSelected&ids=" +
293                                 param_escape(rows.toString()) + "&cmode=2";
294
295                         xmlhttp_rpc.open("GET", query, true);
296                         xmlhttp_rpc.onreadystatechange=all_counters_callback;
297                         xmlhttp_rpc.send(null);
298
299                 }
300
301         } catch (e) {
302                 exception_error("selectionToggleMarked", e);
303         }
304 }
305
306 function cdmGetSelectedArticles() {
307         var sel_articles = new Array();
308         var container = document.getElementById("headlinesContainer");
309
310         for (i = 0; i < container.childNodes.length; i++) {
311                 var child = container.childNodes[i];
312
313                 if (child.id.match("RROW-") && child.className.match("Selected")) {
314                         var c_id = child.id.replace("RROW-", "");
315                         sel_articles.push(c_id);
316                 }
317         }
318
319         return sel_articles;
320 }
321
322 // mode = all,none,unread
323 function cdmSelectArticles(mode) {
324         var container = document.getElementById("headlinesContainer");
325
326         for (i = 0; i < container.childNodes.length; i++) {
327                 var child = container.childNodes[i];
328
329                 if (child.id.match("RROW-")) {
330                         var aid = child.id.replace("RROW-", "");
331
332                         var cb = document.getElementById("RCHK-" + aid);
333
334                         if (mode == "all") {
335                                 if (!child.className.match("Selected")) {
336                                         child.className = child.className + "Selected";
337                                         cb.checked = true;
338                                 }
339                         } else if (mode == "unread") {
340                                 if (child.className.match("Unread") && !child.className.match("Selected")) {
341                                         child.className = child.className + "Selected";
342                                         cb.checked = true;
343                                 }
344                         } else {
345                                 child.className = child.className.replace("Selected", "");
346                                 cb.checked = false;
347                         }
348                 }               
349         }
350 }
351
352 function catchupPage() {
353
354         if (document.getElementById("headlinesList")) {
355                 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
356                 selectionToggleUnread();
357                 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
358         } else {
359                 cdmSelectArticles('all');
360                 selectionToggleUnread(true, false)
361                 cdmSelectArticles('none');
362         }
363 }
364
365 function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
366
367         if (!xmlhttp_ready(xmlhttp_rpc)) {
368                 printLockingError();
369         }
370
371         var title = prompt("Please enter label title:", "");
372
373         if (title) {
374
375                 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
376                         "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
377                         "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) + 
378                         "&title=" + param_escape(title);
379
380                 debug("LFS: " + query);
381         
382                 xmlhttp_rpc.open("GET", query, true);
383                 xmlhttp_rpc.onreadystatechange=getMainContext().dlg_frefresh_callback;
384                 xmlhttp_rpc.send(null);
385         }
386
387 }
388
389
390
391 function headlines_init() {
392         if (arguments.callee.done) return;
393         arguments.callee.done = true;           
394
395         if (parent.frames["feeds-frame"]) {
396                 document.onkeydown = hotkey_handler;
397         }
398
399         var hl = document.getElementById("headlinesList");
400
401         if (!hl) {
402                 hl = document.getElementById("headlinesContainer");
403         }
404
405         var hw = hl.scrollHeight;
406         var pw = parent.document.getElementById("headlines").scrollHeight;
407
408         if (hw >= pw) {
409                 var bt = document.getElementById("headlineActionsBottom");
410                 bt.className = "headlinesSubToolbar";
411         }
412
413 }