]> git.wh0rd.org - tt-rss.git/blame - prefs.js
OPML export
[tt-rss.git] / prefs.js
CommitLineData
007bda35
AD
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
961513a3
AD
8var active_feed = false;
9
007bda35
AD
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
007bda35
AD
29
30function feedlist_callback() {
31 var container = document.getElementById('feeds');
32 if (xmlhttp.readyState == 4) {
33 container.innerHTML=xmlhttp.responseText;
961513a3
AD
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 }
007bda35
AD
47 }
48}
49
0e091d38
AD
50function notify_callback() {
51 var container = document.getElementById('notify');
52 if (xmlhttp.readyState == 4) {
53 container.innerHTML=xmlhttp.responseText;
54 }
55}
56
175847de 57
0e091d38 58function updateFeedList() {
007bda35 59
c0e5a40e 60 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
61 printLockingError();
62 return
63 }
64
007bda35
AD
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
71ad3959
AD
87function addFeed() {
88
c0e5a40e 89 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
90 printLockingError();
91 return
92 }
93
331900c6
AD
94 var link = document.getElementById("fadd_link");
95
83fe4d6d 96 if (link.value.length == 0) {
c753cd32 97 notify("Missing feed URL.");
331900c6
AD
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
508a81e1
AD
114// notify("Editing feed...");
115
c0e5a40e 116 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
117 printLockingError();
118 return
119 }
331900c6 120
961513a3
AD
121 active_feed = feed;
122
331900c6
AD
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
83fe4d6d 130function getSelectedFeeds() {
331900c6
AD
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
83fe4d6d
AD
143 return sel_rows;
144}
145
146function readSelectedFeeds() {
147
c0e5a40e 148 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
149 printLockingError();
150 return
151 }
152
83fe4d6d
AD
153 var sel_rows = getSelectedFeeds();
154
155 if (sel_rows.length > 0) {
156
157 notify("Marking selected feeds as read...");
158
0e091d38 159 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
83fe4d6d 160 param_escape(sel_rows.toString()), true);
0e091d38 161 xmlhttp.onreadystatechange=notify_callback;
83fe4d6d
AD
162 xmlhttp.send(null);
163
164 } else {
165
c753cd32 166 notify("Please select some feeds first.");
83fe4d6d
AD
167
168 }
169}
170
171function unreadSelectedFeeds() {
172
c0e5a40e 173 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
174 printLockingError();
175 return
176 }
177
83fe4d6d
AD
178 var sel_rows = getSelectedFeeds();
179
180 if (sel_rows.length > 0) {
181
182 notify("Marking selected feeds as unread...");
183
0e091d38 184 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
83fe4d6d 185 param_escape(sel_rows.toString()), true);
0e091d38 186 xmlhttp.onreadystatechange=notify_callback;
83fe4d6d
AD
187 xmlhttp.send(null);
188
189 } else {
190
c753cd32 191 notify("Please select some feeds first.");
83fe4d6d
AD
192
193 }
194}
195
196function removeSelectedFeeds() {
197
c0e5a40e 198 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
199 printLockingError();
200 return
201 }
202
83fe4d6d
AD
203 var sel_rows = getSelectedFeeds();
204
331900c6
AD
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);
71ad3959 213
71ad3959 214 } else {
331900c6 215
c753cd32 216 notify("Please select some feeds first.");
331900c6 217
71ad3959
AD
218 }
219
220}
007bda35 221
508a81e1
AD
222function feedEditCancel() {
223
c0e5a40e 224 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
225 printLockingError();
226 return
227 }
228
961513a3
AD
229 active_feed = false;
230
508a81e1
AD
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
603c27f8
AD
239function feedEditSave() {
240
241 var feed = active_feed;
508a81e1 242
c0e5a40e 243 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
244 printLockingError();
245 return
246 }
247
603c27f8
AD
248 var link = document.getElementById("iedit_link").value;
249 var title = document.getElementById("iedit_title").value;
508a81e1 250
603c27f8 251// notify("Saving feed.");
508a81e1
AD
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
603c27f8
AD
263 active_feed = false;
264
508a81e1
AD
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
13ad9102
AD
289function localPiggieFunction(enable) {
290 if (enable) {
508a81e1
AD
291 piggie.style.display = "block";
292 seq = "";
293 notify("I loveded it!!!");
294 } else {
295 piggie.style.display = "none";
296 notify("");
297 }
508a81e1
AD
298}
299
007bda35 300function init() {
e2ec66a8
AD
301
302 // IE kludge
303
ad095c16 304 if (!xmlhttp) {
e2ec66a8
AD
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
0e091d38 311 updateFeedList();
508a81e1 312 document.onkeydown = hotkey_handler;
857a9270
AD
313 notify("");
314
007bda35 315}