]> git.wh0rd.org - tt-rss.git/blob - prefs.js
highlight selected feed in preferences
[tt-rss.git] / prefs.js
1 /*
2 This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>
3 Licensed under GPL v.2 or (at your preference) any later version.
4 */
5
6 var xmlhttp = false;
7
8 var active_feed = false;
9
10 /*@cc_on @*/
11 /*@if (@_jscript_version >= 5)
12 // JScript gives us Conditional compilation, we can cope with old IE versions.
13 // and security blocked creation of the objects.
14 try {
15 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
16 } catch (e) {
17 try {
18 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
19 } catch (E) {
20 xmlhttp = false;
21 }
22 }
23 @end @*/
24
25 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
26 xmlhttp = new XMLHttpRequest();
27 }
28
29
30 function feedlist_callback() {
31 var container = document.getElementById('feeds');
32 if (xmlhttp.readyState == 4) {
33 container.innerHTML=xmlhttp.responseText;
34
35 if (active_feed) {
36 var row = document.getElementById("FEEDR-" + active_feed);
37 if (row) {
38 if (!row.className.match("Selected")) {
39 row.className = row.className + "Selected";
40 }
41 }
42 var checkbox = document.getElementById("FRCHK-" + active_feed);
43 if (checkbox) {
44 checkbox.checked = true;
45 }
46 }
47 }
48 }
49
50 function notify_callback() {
51 var container = document.getElementById('notify');
52 if (xmlhttp.readyState == 4) {
53 container.innerHTML=xmlhttp.responseText;
54 }
55 }
56
57
58 function updateFeedList() {
59
60 if (!xmlhttp_ready(xmlhttp)) {
61 printLockingError();
62 return
63 }
64
65 document.getElementById("feeds").innerHTML = "Loading feeds, please wait...";
66
67 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
68 xmlhttp.onreadystatechange=feedlist_callback;
69 xmlhttp.send(null);
70
71 }
72
73 function toggleSelectRow(sender) {
74 var parent_row = sender.parentNode.parentNode;
75
76 if (sender.checked) {
77 if (!parent_row.className.match("Selected")) {
78 parent_row.className = parent_row.className + "Selected";
79 }
80 } else {
81 if (parent_row.className.match("Selected")) {
82 parent_row.className = parent_row.className.replace("Selected", "");
83 }
84 }
85 }
86
87 function addFeed() {
88
89 if (!xmlhttp_ready(xmlhttp)) {
90 printLockingError();
91 return
92 }
93
94 var link = document.getElementById("fadd_link");
95
96 if (link.value.length == 0) {
97 notify("Missing feed URL.");
98 } else {
99 notify("Adding feed...");
100
101 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
102 param_escape(link.value), true);
103 xmlhttp.onreadystatechange=feedlist_callback;
104 xmlhttp.send(null);
105
106 link.value = "";
107
108 }
109
110 }
111
112 function editFeed(feed) {
113
114 // notify("Editing feed...");
115
116 if (!xmlhttp_ready(xmlhttp)) {
117 printLockingError();
118 return
119 }
120
121 active_feed = feed;
122
123 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" +
124 param_escape(feed), true);
125 xmlhttp.onreadystatechange=feedlist_callback;
126 xmlhttp.send(null);
127
128 }
129
130 function getSelectedFeeds() {
131
132 var content = document.getElementById("prefFeedList");
133
134 var sel_rows = new Array();
135
136 for (i = 0; i < content.rows.length; i++) {
137 if (content.rows[i].className.match("Selected")) {
138 var row_id = content.rows[i].id.replace("FEEDR-", "");
139 sel_rows.push(row_id);
140 }
141 }
142
143 return sel_rows;
144 }
145
146 function readSelectedFeeds() {
147
148 if (!xmlhttp_ready(xmlhttp)) {
149 printLockingError();
150 return
151 }
152
153 var sel_rows = getSelectedFeeds();
154
155 if (sel_rows.length > 0) {
156
157 notify("Marking selected feeds as read...");
158
159 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
160 param_escape(sel_rows.toString()), true);
161 xmlhttp.onreadystatechange=notify_callback;
162 xmlhttp.send(null);
163
164 } else {
165
166 notify("Please select some feeds first.");
167
168 }
169 }
170
171 function unreadSelectedFeeds() {
172
173 if (!xmlhttp_ready(xmlhttp)) {
174 printLockingError();
175 return
176 }
177
178 var sel_rows = getSelectedFeeds();
179
180 if (sel_rows.length > 0) {
181
182 notify("Marking selected feeds as unread...");
183
184 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
185 param_escape(sel_rows.toString()), true);
186 xmlhttp.onreadystatechange=notify_callback;
187 xmlhttp.send(null);
188
189 } else {
190
191 notify("Please select some feeds first.");
192
193 }
194 }
195
196 function removeSelectedFeeds() {
197
198 if (!xmlhttp_ready(xmlhttp)) {
199 printLockingError();
200 return
201 }
202
203 var sel_rows = getSelectedFeeds();
204
205 if (sel_rows.length > 0) {
206
207 notify("Removing selected feeds...");
208
209 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
210 param_escape(sel_rows.toString()), true);
211 xmlhttp.onreadystatechange=feedlist_callback;
212 xmlhttp.send(null);
213
214 } else {
215
216 notify("Please select some feeds first.");
217
218 }
219
220 }
221
222 function feedEditCancel() {
223
224 if (!xmlhttp_ready(xmlhttp)) {
225 printLockingError();
226 return
227 }
228
229 active_feed = false;
230
231 notify("Operation cancelled.");
232
233 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
234 xmlhttp.onreadystatechange=feedlist_callback;
235 xmlhttp.send(null);
236
237 }
238
239 function feedEditSave(feed) {
240
241 if (!xmlhttp_ready(xmlhttp)) {
242 printLockingError();
243 return
244 }
245
246 notify("Saving feed.");
247
248 var link = document.getElementById("fedit_link").value;
249 var title = document.getElementById("fedit_title").value;
250
251 if (link.length == 0) {
252 notify("Feed link cannot be blank.");
253 return;
254 }
255
256 if (title.length == 0) {
257 notify("Feed title cannot be blank.");
258 return;
259 }
260
261 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
262 feed + "&l=" + param_escape(link) + "&t=" + param_escape(title) ,true);
263 xmlhttp.onreadystatechange=feedlist_callback;
264 xmlhttp.send(null);
265
266 }
267
268 function editSelectedFeed() {
269 var rows = getSelectedFeeds();
270
271 if (rows.length == 0) {
272 notify("No feeds are selected.");
273 return;
274 }
275
276 if (rows.length > 1) {
277 notify("Please select one feed.");
278 return;
279 }
280
281 editFeed(rows[0]);
282
283 }
284
285 function localPiggieFunction(enable) {
286 if (enable) {
287 piggie.style.display = "block";
288 seq = "";
289 notify("I loveded it!!!");
290 } else {
291 piggie.style.display = "none";
292 notify("");
293 }
294 }
295
296 function init() {
297
298 // IE kludge
299
300 if (!xmlhttp) {
301 document.getElementById("prefContent").innerHTML =
302 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
303 "to function properly. Your browser doesn't seem to support it.";
304 return;
305 }
306
307 updateFeedList();
308 document.onkeydown = hotkey_handler;
309 notify("");
310
311 }