]> git.wh0rd.org - tt-rss.git/blame_incremental - prefs.js
OPML export
[tt-rss.git] / prefs.js
... / ...
CommitLineData
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
6var xmlhttp = false;
7
8var 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.
14try {
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
25if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
26 xmlhttp = new XMLHttpRequest();
27}
28
29
30function 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
50function notify_callback() {
51 var container = document.getElementById('notify');
52 if (xmlhttp.readyState == 4) {
53 container.innerHTML=xmlhttp.responseText;
54 }
55}
56
57
58function 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
73function 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
87function 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
112function 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
130function 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
146function 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
171function 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
196function 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
222function 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
239function feedEditSave() {
240
241 var feed = active_feed;
242
243 if (!xmlhttp_ready(xmlhttp)) {
244 printLockingError();
245 return
246 }
247
248 var link = document.getElementById("iedit_link").value;
249 var title = document.getElementById("iedit_title").value;
250
251// notify("Saving feed.");
252
253 if (link.length == 0) {
254 notify("Feed link cannot be blank.");
255 return;
256 }
257
258 if (title.length == 0) {
259 notify("Feed title cannot be blank.");
260 return;
261 }
262
263 active_feed = false;
264
265 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
266 feed + "&l=" + param_escape(link) + "&t=" + param_escape(title) ,true);
267 xmlhttp.onreadystatechange=feedlist_callback;
268 xmlhttp.send(null);
269
270}
271
272function editSelectedFeed() {
273 var rows = getSelectedFeeds();
274
275 if (rows.length == 0) {
276 notify("No feeds are selected.");
277 return;
278 }
279
280 if (rows.length > 1) {
281 notify("Please select one feed.");
282 return;
283 }
284
285 editFeed(rows[0]);
286
287}
288
289function localPiggieFunction(enable) {
290 if (enable) {
291 piggie.style.display = "block";
292 seq = "";
293 notify("I loveded it!!!");
294 } else {
295 piggie.style.display = "none";
296 notify("");
297 }
298}
299
300function init() {
301
302 // IE kludge
303
304 if (!xmlhttp) {
305 document.getElementById("prefContent").innerHTML =
306 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
307 "to function properly. Your browser doesn't seem to support it.";
308 return;
309 }
310
311 updateFeedList();
312 document.onkeydown = hotkey_handler;
313 notify("");
314
315}