prefs.js 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  1. var xmlhttp = false;
  2. var active_feed_cat = false;
  3. var active_label = false;
  4. var active_tab = false;
  5. var feed_to_expand = false;
  6. var piggie_top = -400;
  7. var piggie_fwd = true;
  8. var xmlhttp = Ajax.getTransport();
  9. var init_params = new Array();
  10. var caller_subop = false;
  11. var sanity_check_done = false;
  12. function expand_feed_callback() {
  13. if (xmlhttp.readyState == 4) {
  14. try {
  15. var container = document.getElementById("BRDET-" + feed_to_expand);
  16. container.innerHTML=xmlhttp.responseText;
  17. container.style.display = "block";
  18. // p_notify("");
  19. } catch (e) {
  20. exception_error("expand_feed_callback", e);
  21. }
  22. }
  23. }
  24. function feedlist_callback() {
  25. if (xmlhttp.readyState == 4) {
  26. try {
  27. var container = document.getElementById('prefContent');
  28. container.innerHTML=xmlhttp.responseText;
  29. selectTab("feedConfig", true);
  30. if (caller_subop) {
  31. var tuple = caller_subop.split(":");
  32. if (tuple[0] == 'editFeed') {
  33. window.setTimeout('editFeed('+tuple[1]+')', 100);
  34. }
  35. caller_subop = false;
  36. }
  37. if (typeof correctPNG != 'undefined') {
  38. correctPNG();
  39. }
  40. notify("");
  41. } catch (e) {
  42. exception_error("feedlist_callback", e);
  43. }
  44. }
  45. }
  46. function filterlist_callback() {
  47. var container = document.getElementById('prefContent');
  48. if (xmlhttp.readyState == 4) {
  49. container.innerHTML=xmlhttp.responseText;
  50. if (typeof correctPNG != 'undefined') {
  51. correctPNG();
  52. }
  53. notify("");
  54. }
  55. }
  56. function labellist_callback() {
  57. var container = document.getElementById('prefContent');
  58. if (xmlhttp.readyState == 4) {
  59. closeInfoBox();
  60. container.innerHTML=xmlhttp.responseText;
  61. if (active_label) {
  62. var row = document.getElementById("LILRR-" + active_label);
  63. if (row) {
  64. if (!row.className.match("Selected")) {
  65. row.className = row.className + "Selected";
  66. }
  67. }
  68. var checkbox = document.getElementById("LICHK-" + active_label);
  69. if (checkbox) {
  70. checkbox.checked = true;
  71. }
  72. }
  73. if (typeof correctPNG != 'undefined') {
  74. correctPNG();
  75. }
  76. notify("");
  77. }
  78. }
  79. function labeltest_callback() {
  80. var container = document.getElementById('label_test_result');
  81. if (xmlhttp.readyState == 4) {
  82. container.innerHTML=xmlhttp.responseText;
  83. notify("");
  84. }
  85. }
  86. function feed_browser_callback() {
  87. var container = document.getElementById('prefContent');
  88. if (xmlhttp.readyState == 4) {
  89. container.innerHTML=xmlhttp.responseText;
  90. notify("");
  91. }
  92. }
  93. function userlist_callback() {
  94. var container = document.getElementById('prefContent');
  95. if (xmlhttp.readyState == 4) {
  96. container.innerHTML=xmlhttp.responseText;
  97. notify("");
  98. }
  99. }
  100. function prefslist_callback() {
  101. var container = document.getElementById('prefContent');
  102. if (xmlhttp.readyState == 4) {
  103. container.innerHTML=xmlhttp.responseText;
  104. notify("");
  105. }
  106. }
  107. function gethelp_callback() {
  108. var container = document.getElementById('prefHelpBox');
  109. if (xmlhttp.readyState == 4) {
  110. container.innerHTML = xmlhttp.responseText;
  111. container.style.display = "block";
  112. }
  113. }
  114. function notify_callback() {
  115. if (xmlhttp.readyState == 4) {
  116. notify_info(xmlhttp.responseText);
  117. }
  118. }
  119. function changepass_callback() {
  120. try {
  121. if (xmlhttp.readyState == 4) {
  122. if (xmlhttp.responseText.indexOf("ERROR: ") == 0) {
  123. notify_error(xmlhttp.responseText.replace("ERROR: ", ""));
  124. } else {
  125. notify_info(xmlhttp.responseText);
  126. var warn = document.getElementById("default_pass_warning");
  127. if (warn) warn.style.display = "none";
  128. }
  129. document.forms['change_pass_form'].reset();
  130. }
  131. } catch (e) {
  132. exception_error("changepass_callback", e);
  133. }
  134. }
  135. function updateFeedList(sort_key) {
  136. if (!xmlhttp_ready(xmlhttp)) {
  137. printLockingError();
  138. return
  139. }
  140. // document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
  141. // p_notify("Loading, please wait...");
  142. var feed_search = document.getElementById("feed_search");
  143. var search = "";
  144. if (feed_search) { search = feed_search.value; }
  145. xmlhttp.open("GET", "backend.php?op=pref-feeds" +
  146. "&sort=" + param_escape(sort_key) +
  147. "&search=" + param_escape(search), true);
  148. xmlhttp.onreadystatechange=feedlist_callback;
  149. xmlhttp.send(null);
  150. }
  151. function updateUsersList(sort_key) {
  152. if (!xmlhttp_ready(xmlhttp)) {
  153. printLockingError();
  154. return
  155. }
  156. // document.getElementById("prefContent").innerHTML = "Loading feeds, please wait...";
  157. // p_notify("Loading, please wait...");
  158. xmlhttp.open("GET", "backend.php?op=pref-users&sort="
  159. + param_escape(sort_key), true);
  160. xmlhttp.onreadystatechange=userlist_callback;
  161. xmlhttp.send(null);
  162. }
  163. function addLabel() {
  164. if (!xmlhttp_ready(xmlhttp)) {
  165. printLockingError();
  166. return
  167. }
  168. var form = document.forms['label_edit_form'];
  169. var sql_exp = form.sql_exp.value;
  170. var description = form.description.value;
  171. if (sql_exp == "") {
  172. alert("Can't create label: missing SQL expression.");
  173. return false;
  174. }
  175. if (description == "") {
  176. alert("Can't create label: missing caption.");
  177. return false;
  178. }
  179. var query = Form.serialize("label_edit_form");
  180. xmlhttp.open("GET", "backend.php?op=pref-labels&subop=add&" + query, true);
  181. xmlhttp.onreadystatechange=infobox_submit_callback;
  182. xmlhttp.send(null);
  183. }
  184. function addFeed() {
  185. if (!xmlhttp_ready(xmlhttp)) {
  186. printLockingError();
  187. return
  188. }
  189. var link = document.getElementById("fadd_link");
  190. if (link.value.length == 0) {
  191. alert(__("Error: No feed URL given."));
  192. } else if (!isValidURL(link.value)) {
  193. alert(__("Error: Invalid feed URL."));
  194. } else {
  195. notify_progress("Adding feed...");
  196. xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&from=tt-rss&feed_url=" +
  197. param_escape(link.value), true);
  198. xmlhttp.onreadystatechange=feedlist_callback;
  199. xmlhttp.send(null);
  200. link.value = "";
  201. }
  202. }
  203. function addFeedCat() {
  204. if (!xmlhttp_ready(xmlhttp)) {
  205. printLockingError();
  206. return
  207. }
  208. var cat = document.getElementById("fadd_cat");
  209. if (cat.value.length == 0) {
  210. alert(__("Can't add category: no name specified."));
  211. } else {
  212. notify_progress("Adding feed category...");
  213. xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=add&cat=" +
  214. param_escape(cat.value), true);
  215. xmlhttp.onreadystatechange=infobox_callback;
  216. xmlhttp.send(null);
  217. link.value = "";
  218. }
  219. }
  220. function addUser() {
  221. if (!xmlhttp_ready(xmlhttp)) {
  222. printLockingError();
  223. return
  224. }
  225. var sqlexp = document.getElementById("uadd_box");
  226. if (sqlexp.value.length == 0) {
  227. alert("Can't add user: no login specified.");
  228. } else {
  229. notify_progress("Adding user...");
  230. xmlhttp.open("GET", "backend.php?op=pref-users&subop=add&login=" +
  231. param_escape(sqlexp.value), true);
  232. xmlhttp.onreadystatechange=userlist_callback;
  233. xmlhttp.send(null);
  234. sqlexp.value = "";
  235. }
  236. }
  237. function editLabel(id) {
  238. if (!xmlhttp_ready(xmlhttp)) {
  239. printLockingError();
  240. return
  241. }
  242. notify_progress("Loading, please wait...");
  243. document.getElementById("label_create_btn").disabled = true;
  244. active_label = id;
  245. selectTableRowsByIdPrefix('prefLabelList', 'LILRR-', 'LICHK-', false);
  246. selectTableRowById('LILRR-'+id, 'LICHK-'+id, true);
  247. xmlhttp.open("GET", "backend.php?op=pref-labels&subop=edit&id=" +
  248. param_escape(id), true);
  249. xmlhttp.onreadystatechange=infobox_callback;
  250. xmlhttp.send(null);
  251. }
  252. function editUser(id) {
  253. if (!xmlhttp_ready(xmlhttp)) {
  254. printLockingError();
  255. return
  256. }
  257. notify_progress("Loading, please wait...");
  258. selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
  259. selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
  260. xmlhttp.open("GET", "backend.php?op=pref-users&subop=edit&id=" +
  261. param_escape(id), true);
  262. xmlhttp.onreadystatechange=infobox_callback;
  263. xmlhttp.send(null);
  264. }
  265. function editFilter(id) {
  266. if (!xmlhttp_ready(xmlhttp)) {
  267. printLockingError();
  268. return
  269. }
  270. notify_progress("Loading, please wait...");
  271. document.getElementById("create_filter_btn").disabled = true;
  272. selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
  273. selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
  274. xmlhttp.open("GET", "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id), true);
  275. xmlhttp.onreadystatechange=infobox_callback;
  276. xmlhttp.send(null);
  277. }
  278. function editFeed(feed) {
  279. // notify("Editing feed...");
  280. if (!xmlhttp_ready(xmlhttp)) {
  281. printLockingError();
  282. return
  283. }
  284. notify_progress("Loading, please wait...");
  285. // clean selection from all rows & select row being edited
  286. selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
  287. selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
  288. xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
  289. param_escape(feed), true);
  290. xmlhttp.onreadystatechange=infobox_callback;
  291. xmlhttp.send(null);
  292. }
  293. function editFeedCat(cat) {
  294. if (!xmlhttp_ready(xmlhttp)) {
  295. printLockingError();
  296. return
  297. }
  298. notify_progress("Loading, please wait...");
  299. active_feed_cat = cat;
  300. xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=edit&id=" +
  301. param_escape(cat), true);
  302. xmlhttp.onreadystatechange=infobox_callback;
  303. xmlhttp.send(null);
  304. }
  305. function getSelectedLabels() {
  306. return getSelectedTableRowIds("prefLabelList", "LILRR");
  307. }
  308. function getSelectedUsers() {
  309. return getSelectedTableRowIds("prefUserList", "UMRR");
  310. }
  311. function getSelectedFeeds() {
  312. return getSelectedTableRowIds("prefFeedList", "FEEDR");
  313. }
  314. function getSelectedFilters() {
  315. return getSelectedTableRowIds("prefFilterList", "FILRR");
  316. }
  317. function getSelectedFeedCats() {
  318. return getSelectedTableRowIds("prefFeedCatList", "FCATR");
  319. }
  320. function getSelectedFeedsFromBrowser() {
  321. var list = document.getElementById("browseFeedList");
  322. if (!list) list = document.getElementById("browseBigFeedList");
  323. var selected = new Array();
  324. for (i = 0; i < list.childNodes.length; i++) {
  325. var child = list.childNodes[i];
  326. if (child.id && child.id.match("FBROW-")) {
  327. var id = child.id.replace("FBROW-", "");
  328. var cb = document.getElementById("FBCHK-" + id);
  329. if (cb.checked) {
  330. selected.push(id);
  331. }
  332. }
  333. }
  334. return selected;
  335. }
  336. function removeSelectedLabels() {
  337. if (!xmlhttp_ready(xmlhttp)) {
  338. printLockingError();
  339. return
  340. }
  341. var sel_rows = getSelectedLabels();
  342. if (sel_rows.length > 0) {
  343. var ok = confirm("Remove selected labels?");
  344. if (ok) {
  345. notify_progress("Removing selected labels...");
  346. xmlhttp.open("GET", "backend.php?op=pref-labels&subop=remove&ids="+
  347. param_escape(sel_rows.toString()), true);
  348. xmlhttp.onreadystatechange=labellist_callback;
  349. xmlhttp.send(null);
  350. }
  351. } else {
  352. alert("No labels are selected.");
  353. }
  354. return false;
  355. }
  356. function removeSelectedUsers() {
  357. if (!xmlhttp_ready(xmlhttp)) {
  358. printLockingError();
  359. return
  360. }
  361. var sel_rows = getSelectedUsers();
  362. if (sel_rows.length > 0) {
  363. var ok = confirm("Remove selected users?");
  364. if (ok) {
  365. notify_progress("Removing selected users...");
  366. xmlhttp.open("GET", "backend.php?op=pref-users&subop=remove&ids="+
  367. param_escape(sel_rows.toString()), true);
  368. xmlhttp.onreadystatechange=userlist_callback;
  369. xmlhttp.send(null);
  370. }
  371. } else {
  372. alert("No users are selected.");
  373. }
  374. return false;
  375. }
  376. function removeSelectedFilters() {
  377. if (!xmlhttp_ready(xmlhttp)) {
  378. printLockingError();
  379. return
  380. }
  381. var sel_rows = getSelectedFilters();
  382. if (sel_rows.length > 0) {
  383. var ok = confirm("Remove selected filters?");
  384. if (ok) {
  385. notify_progress("Removing selected filters...");
  386. xmlhttp.open("GET", "backend.php?op=pref-filters&subop=remove&ids="+
  387. param_escape(sel_rows.toString()), true);
  388. xmlhttp.onreadystatechange=filterlist_callback;
  389. xmlhttp.send(null);
  390. }
  391. } else {
  392. alert("No filters are selected.");
  393. }
  394. return false;
  395. }
  396. function removeSelectedFeeds() {
  397. if (!xmlhttp_ready(xmlhttp)) {
  398. printLockingError();
  399. return
  400. }
  401. var sel_rows = getSelectedFeeds();
  402. if (sel_rows.length > 0) {
  403. var ok = confirm("Unsubscribe from selected feeds?");
  404. if (ok) {
  405. notify_progress("Unsubscribing from selected feeds...");
  406. xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
  407. param_escape(sel_rows.toString()), true);
  408. xmlhttp.onreadystatechange=feedlist_callback;
  409. xmlhttp.send(null);
  410. }
  411. } else {
  412. alert("No feeds are selected.");
  413. }
  414. return false;
  415. }
  416. function removeSelectedFeedCats() {
  417. if (!xmlhttp_ready(xmlhttp)) {
  418. printLockingError();
  419. return
  420. }
  421. var sel_rows = getSelectedFeedCats();
  422. if (sel_rows.length > 0) {
  423. var ok = confirm("Remove selected categories?");
  424. if (ok) {
  425. notify_progress("Removing selected categories...");
  426. xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats&action=remove&ids="+
  427. param_escape(sel_rows.toString()), true);
  428. xmlhttp.onreadystatechange=infobox_callback;
  429. xmlhttp.send(null);
  430. }
  431. } else {
  432. alert("No categories are selected.");
  433. }
  434. return false;
  435. }
  436. function feedEditCancel() {
  437. if (!xmlhttp_ready(xmlhttp)) {
  438. printLockingError();
  439. return
  440. }
  441. closeInfoBox();
  442. selectPrefRows('feed', false); // cleanup feed selection
  443. return false;
  444. }
  445. function feedCatEditCancel() {
  446. if (!xmlhttp_ready(xmlhttp)) {
  447. printLockingError();
  448. return
  449. }
  450. active_feed_cat = false;
  451. // notify("Operation cancelled.");
  452. xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
  453. xmlhttp.onreadystatechange=infobox_callback;
  454. xmlhttp.send(null);
  455. return false;
  456. }
  457. function feedEditSave() {
  458. try {
  459. if (!xmlhttp_ready(xmlhttp)) {
  460. printLockingError();
  461. return
  462. }
  463. // FIXME: add parameter validation
  464. var query = Form.serialize("edit_feed_form");
  465. notify_progress("Saving feed...");
  466. xmlhttp.open("POST", "backend.php", true);
  467. xmlhttp.onreadystatechange=feedlist_callback;
  468. xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  469. xmlhttp.send(query);
  470. closeInfoBox();
  471. return false;
  472. } catch (e) {
  473. exception_error("feedEditSave", e);
  474. }
  475. }
  476. function feedCatEditSave() {
  477. if (!xmlhttp_ready(xmlhttp)) {
  478. printLockingError();
  479. return
  480. }
  481. notify_progress("Saving category...");
  482. var query = Form.serialize("feed_cat_edit_form");
  483. xmlhttp.open("GET", "backend.php?" + query, true);
  484. xmlhttp.onreadystatechange=infobox_callback;
  485. xmlhttp.send(null);
  486. active_feed_cat = false;
  487. return false;
  488. }
  489. function labelTest() {
  490. var container = document.getElementById('label_test_result');
  491. container.style.display = "block";
  492. container.innerHTML = "<p>Loading, please wait...</p>";
  493. var form = document.forms['label_edit_form'];
  494. var sql_exp = form.sql_exp.value;
  495. var description = form.description.value;
  496. xmlhttp.open("GET", "backend.php?op=pref-labels&subop=test&expr=" +
  497. param_escape(sql_exp) + "&descr=" + param_escape(description), true);
  498. xmlhttp.onreadystatechange=labeltest_callback;
  499. xmlhttp.send(null);
  500. return false;
  501. }
  502. function displayHelpInfobox(topic_id) {
  503. if (!xmlhttp_ready(xmlhttp)) {
  504. printLockingError();
  505. return
  506. }
  507. notify_progress("Loading help...");
  508. xmlhttp.open("GET", "backend.php?op=help&tid=" +
  509. param_escape(topic_id) + "&noheaders=1", true);
  510. xmlhttp.onreadystatechange=infobox_callback;
  511. xmlhttp.send(null);
  512. }
  513. function labelEditCancel() {
  514. if (!xmlhttp_ready(xmlhttp)) {
  515. printLockingError();
  516. return
  517. }
  518. document.getElementById("label_create_btn").disabled = false;
  519. active_label = false;
  520. selectPrefRows('label', false); // cleanup feed selection
  521. closeInfoBox();
  522. return false;
  523. }
  524. function userEditCancel() {
  525. if (!xmlhttp_ready(xmlhttp)) {
  526. printLockingError();
  527. return
  528. }
  529. selectPrefRows('user', false); // cleanup feed selection
  530. closeInfoBox();
  531. return false;
  532. }
  533. function filterEditCancel() {
  534. if (!xmlhttp_ready(xmlhttp)) {
  535. printLockingError();
  536. return
  537. }
  538. document.getElementById("create_filter_btn").disabled = false;
  539. selectPrefRows('filter', false); // cleanup feed selection
  540. closeInfoBox();
  541. return false;
  542. }
  543. function labelEditSave() {
  544. var label = active_label;
  545. if (!xmlhttp_ready(xmlhttp)) {
  546. printLockingError();
  547. return
  548. }
  549. /* if (!is_opera()) {
  550. var sql_exp = document.forms["label_edit_form"].sql_exp.value;
  551. var description = document.forms["label_edit_form"].description.value;
  552. if (sql_exp.length == 0) {
  553. alert("SQL Expression cannot be blank.");
  554. return false;
  555. }
  556. if (description.length == 0) {
  557. alert("Caption field cannot be blank.");
  558. return false;
  559. }
  560. } */
  561. closeInfoBox();
  562. notify_progress("Saving label...");
  563. active_label = false;
  564. query = Form.serialize("label_edit_form");
  565. xmlhttp.open("GET", "backend.php?" + query, true);
  566. xmlhttp.onreadystatechange=labellist_callback;
  567. xmlhttp.send(null);
  568. return false;
  569. }
  570. function userEditSave() {
  571. if (!xmlhttp_ready(xmlhttp)) {
  572. printLockingError();
  573. return
  574. }
  575. var login = document.forms["user_edit_form"].login.value;
  576. if (login.length == 0) {
  577. alert("Login field cannot be blank.");
  578. return;
  579. }
  580. notify_progress("Saving user...");
  581. closeInfoBox();
  582. var query = Form.serialize("user_edit_form");
  583. xmlhttp.open("GET", "backend.php?" + query, true);
  584. xmlhttp.onreadystatechange=userlist_callback;
  585. xmlhttp.send(null);
  586. return false;
  587. }
  588. function filterEditSave() {
  589. if (!xmlhttp_ready(xmlhttp)) {
  590. printLockingError();
  591. return
  592. }
  593. /* if (!is_opera()) {
  594. var reg_exp = document.forms["filter_edit_form"].reg_exp.value;
  595. if (reg_exp.length == 0) {
  596. alert("Filter expression field cannot be blank.");
  597. return;
  598. }
  599. } */
  600. notify_progress("Saving filter...");
  601. var query = Form.serialize("filter_edit_form");
  602. closeInfoBox();
  603. document.getElementById("create_filter_btn").disabled = false;
  604. xmlhttp.open("GET", "backend.php?" + query, true);
  605. xmlhttp.onreadystatechange=filterlist_callback;
  606. xmlhttp.send(null);
  607. return false;
  608. }
  609. function editSelectedLabel() {
  610. var rows = getSelectedLabels();
  611. if (rows.length == 0) {
  612. alert(__("No labels are selected."));
  613. return;
  614. }
  615. if (rows.length > 1) {
  616. alert(__("Please select only one label."));
  617. return;
  618. }
  619. notify("");
  620. editLabel(rows[0]);
  621. }
  622. function editSelectedUser() {
  623. var rows = getSelectedUsers();
  624. if (rows.length == 0) {
  625. alert(__("No users are selected."));
  626. return;
  627. }
  628. if (rows.length > 1) {
  629. alert(__("Please select only one user."));
  630. return;
  631. }
  632. notify("");
  633. editUser(rows[0]);
  634. }
  635. function resetSelectedUserPass() {
  636. var rows = getSelectedUsers();
  637. if (rows.length == 0) {
  638. alert(__("No users are selected."));
  639. return;
  640. }
  641. if (rows.length > 1) {
  642. alert(__("Please select only one user."));
  643. return;
  644. }
  645. var ok = confirm(__("Reset password of selected user?"));
  646. if (ok) {
  647. notify_progress("Resetting password for selected user...");
  648. var id = rows[0];
  649. xmlhttp.open("GET", "backend.php?op=pref-users&subop=resetPass&id=" +
  650. param_escape(id), true);
  651. xmlhttp.onreadystatechange=userlist_callback;
  652. xmlhttp.send(null);
  653. }
  654. }
  655. function selectedUserDetails() {
  656. if (!xmlhttp_ready(xmlhttp)) {
  657. printLockingError();
  658. return
  659. }
  660. var rows = getSelectedUsers();
  661. if (rows.length == 0) {
  662. alert(__("No users are selected."));
  663. return;
  664. }
  665. if (rows.length > 1) {
  666. alert(__("Please select only one user."));
  667. return;
  668. }
  669. notify_progress("Loading, please wait...");
  670. var id = rows[0];
  671. xmlhttp.open("GET", "backend.php?op=user-details&id=" + id, true);
  672. xmlhttp.onreadystatechange=infobox_callback;
  673. xmlhttp.send(null);
  674. }
  675. function selectedFeedDetails() {
  676. if (!xmlhttp_ready(xmlhttp)) {
  677. printLockingError();
  678. return
  679. }
  680. var rows = getSelectedFeeds();
  681. if (rows.length == 0) {
  682. alert(__("No feeds are selected."));
  683. return;
  684. }
  685. if (rows.length > 1) {
  686. alert(__("Please select only one feed."));
  687. return;
  688. }
  689. // var id = rows[0];
  690. notify("");
  691. xmlhttp.open("GET", "backend.php?op=feed-details&id=" +
  692. param_escape(rows.toString()), true);
  693. xmlhttp.onreadystatechange=infobox_callback;
  694. xmlhttp.send(null);
  695. }
  696. function editSelectedFilter() {
  697. var rows = getSelectedFilters();
  698. if (rows.length == 0) {
  699. alert(__("No filters are selected."));
  700. return;
  701. }
  702. if (rows.length > 1) {
  703. alert(__("Please select only one filter."));
  704. return;
  705. }
  706. notify("");
  707. editFilter(rows[0]);
  708. }
  709. function editSelectedFeed() {
  710. var rows = getSelectedFeeds();
  711. if (rows.length == 0) {
  712. alert(__("No feeds are selected."));
  713. return;
  714. }
  715. if (rows.length > 1) {
  716. alert(__("Please select one feed."));
  717. return;
  718. }
  719. notify("");
  720. editFeed(rows[0]);
  721. }
  722. function editSelectedFeedCat() {
  723. var rows = getSelectedFeedCats();
  724. if (rows.length == 0) {
  725. alert(__("No categories are selected."));
  726. return;
  727. }
  728. if (rows.length > 1) {
  729. alert(__("Please select only one category."));
  730. return;
  731. }
  732. notify("");
  733. editFeedCat(rows[0]);
  734. }
  735. function piggie_callback() {
  736. var piggie = document.getElementById("piggie");
  737. piggie.style.top = piggie_top;
  738. piggie.style.backgroundColor = "white";
  739. piggie.style.borderWidth = "1px";
  740. if (piggie_fwd && piggie_top < 0) {
  741. setTimeout("piggie_callback()", 50);
  742. piggie_top = piggie_top + 10;
  743. } else if (piggie_fwd && piggie_top >= 0) {
  744. piggie_fwd = false;
  745. setTimeout("piggie_callback()", 50);
  746. } else if (!piggie_fwd && piggie_top > -400) {
  747. setTimeout("piggie_callback()", 50);
  748. piggie_top = piggie_top - 10;
  749. } else if (!piggie_fwd && piggie_top <= -400) {
  750. piggie.style.display = "none";
  751. piggie_fwd = true;
  752. }
  753. }
  754. var piggie_opacity = 0;
  755. function piggie2_callback() {
  756. var piggie = document.getElementById("piggie");
  757. piggie.style.top = 0;
  758. piggie.style.opacity = piggie_opacity;
  759. piggie.style.backgroundColor = "transparent";
  760. piggie.style.borderWidth = "0px";
  761. if (piggie_fwd && piggie_opacity < 1) {
  762. setTimeout("piggie2_callback()", 50);
  763. piggie_opacity = piggie_opacity + 0.03;
  764. } else if (piggie_fwd && piggie_opacity >= 1) {
  765. piggie_fwd = false;
  766. setTimeout("piggie2_callback()", 50);
  767. } else if (!piggie_fwd && piggie_opacity > 0) {
  768. setTimeout("piggie2_callback()", 50);
  769. piggie_opacity = piggie_opacity - 0.03;
  770. } else if (!piggie_fwd && piggie_opacity <= 0) {
  771. piggie.style.display = "none";
  772. piggie_fwd = true;
  773. }
  774. }
  775. function localPiggieFunction(enable) {
  776. if (enable) {
  777. debug("I LOVEDED IT!");
  778. var piggie = document.getElementById("piggie");
  779. piggie.style.display = "block";
  780. if (navigator.userAgent.match("Gecko") && Math.random(1) > 0.5) {
  781. piggie2_callback();
  782. } else {
  783. piggie_callback();
  784. }
  785. }
  786. }
  787. function validateOpmlImport() {
  788. var opml_file = document.getElementById("opml_file");
  789. if (opml_file.value.length == 0) {
  790. alert(__("No OPML file to upload."));
  791. return false;
  792. } else {
  793. return true;
  794. }
  795. }
  796. function updateFilterList(sort_key) {
  797. if (!xmlhttp_ready(xmlhttp)) {
  798. printLockingError();
  799. return
  800. }
  801. // document.getElementById("prefContent").innerHTML = "Loading filters, please wait...";
  802. // p_notify("Loading, please wait...");
  803. xmlhttp.open("GET", "backend.php?op=pref-filters&sort=" +
  804. param_escape(sort_key), true);
  805. xmlhttp.onreadystatechange=filterlist_callback;
  806. xmlhttp.send(null);
  807. }
  808. function updateLabelList(sort_key) {
  809. if (!xmlhttp_ready(xmlhttp)) {
  810. printLockingError();
  811. return
  812. }
  813. // p_notify("Loading, please wait...");
  814. // document.getElementById("prefContent").innerHTML = "Loading labels, please wait...";
  815. xmlhttp.open("GET", "backend.php?op=pref-labels&sort=" +
  816. param_escape(sort_key), true);
  817. xmlhttp.onreadystatechange=labellist_callback;
  818. xmlhttp.send(null);
  819. }
  820. function updatePrefsList() {
  821. if (!xmlhttp_ready(xmlhttp)) {
  822. printLockingError();
  823. return
  824. }
  825. // p_notify("Loading, please wait...");
  826. xmlhttp.open("GET", "backend.php?op=pref-prefs", true);
  827. xmlhttp.onreadystatechange=prefslist_callback;
  828. xmlhttp.send(null);
  829. }
  830. function selectTab(id, noupdate, subop) {
  831. // alert(id);
  832. if (!id) id = active_tab;
  833. try {
  834. if (!xmlhttp_ready(xmlhttp)) {
  835. printLockingError();
  836. return
  837. }
  838. try {
  839. var c = document.getElementById('prefContent');
  840. c.scrollTop = 0;
  841. } catch (e) { };
  842. if (!noupdate) {
  843. debug("selectTab: " + id + "(NU: " + noupdate + ")");
  844. notify_progress("Loading, please wait...");
  845. // close active infobox if needed
  846. closeInfoBox();
  847. // clean up all current selections, just in case
  848. active_feed_cat = false;
  849. active_label = false;
  850. if (id == "feedConfig") {
  851. updateFeedList();
  852. } else if (id == "filterConfig") {
  853. updateFilterList();
  854. } else if (id == "labelConfig") {
  855. updateLabelList();
  856. } else if (id == "genConfig") {
  857. updatePrefsList();
  858. } else if (id == "userConfig") {
  859. updateUsersList();
  860. } else if (id == "feedBrowser") {
  861. updateBigFeedBrowser();
  862. }
  863. }
  864. var tab = document.getElementById(active_tab + "Tab");
  865. if (tab) {
  866. if (tab.className.match("Selected")) {
  867. tab.className = "prefsTab";
  868. }
  869. }
  870. tab = document.getElementById(id + "Tab");
  871. if (tab) {
  872. if (!tab.className.match("Selected")) {
  873. tab.className = tab.className + "Selected";
  874. }
  875. }
  876. active_tab = id;
  877. } catch (e) {
  878. exception_error("selectTab", e);
  879. }
  880. }
  881. function backend_sanity_check_callback() {
  882. if (xmlhttp.readyState == 4) {
  883. try {
  884. if (sanity_check_done) {
  885. fatalError(11, "Sanity check request received twice. This can indicate "+
  886. "presence of Firebug or some other disrupting extension. "+
  887. "Please disable it and try again.");
  888. return;
  889. }
  890. if (!xmlhttp.responseXML) {
  891. fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
  892. return;
  893. }
  894. var reply = xmlhttp.responseXML.firstChild.firstChild;
  895. if (!reply) {
  896. fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
  897. return;
  898. }
  899. var error_code = reply.getAttribute("error-code");
  900. if (error_code && error_code != 0) {
  901. return fatalError(error_code, reply.getAttribute("error-msg"));
  902. }
  903. debug("sanity check ok");
  904. var params = reply.nextSibling;
  905. if (params) {
  906. debug('reading init-params...');
  907. var param = params.firstChild;
  908. while (param) {
  909. var k = param.getAttribute("key");
  910. var v = param.getAttribute("value");
  911. debug(k + " => " + v);
  912. init_params[k] = v;
  913. param = param.nextSibling;
  914. }
  915. }
  916. sanity_check_done = true;
  917. init_second_stage();
  918. } catch (e) {
  919. exception_error("backend_sanity_check_callback", e);
  920. }
  921. }
  922. }
  923. function init_second_stage() {
  924. try {
  925. active_tab = getInitParam("prefs_active_tab");
  926. if (!active_tab) active_tab = "genConfig";
  927. document.onkeydown = pref_hotkey_handler;
  928. var tab = getURLParam('tab');
  929. caller_subop = getURLParam('subop');
  930. if (tab) {
  931. active_tab = tab;
  932. }
  933. if (navigator.userAgent.match("Opera")) {
  934. setTimeout("selectTab()", 500);
  935. } else {
  936. selectTab(active_tab);
  937. }
  938. notify("");
  939. } catch (e) {
  940. exception_error("init_second_stage", e);
  941. }
  942. }
  943. function init() {
  944. try {
  945. if (arguments.callee.done) return;
  946. arguments.callee.done = true;
  947. if (getURLParam('debug')) {
  948. document.getElementById('debug_output').style.display = 'block';
  949. debug('debug mode activated');
  950. }
  951. // IE kludge
  952. if (!xmlhttp) {
  953. document.getElementById("prefContent").innerHTML =
  954. "<b>Fatal error:</b> This program needs XmlHttpRequest " +
  955. "to function properly. Your browser doesn't seem to support it.";
  956. return;
  957. }
  958. xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
  959. xmlhttp.onreadystatechange=backend_sanity_check_callback;
  960. xmlhttp.send(null);
  961. } catch (e) {
  962. exception_error("init", e);
  963. }
  964. }
  965. function categorizeSelectedFeeds() {
  966. if (!xmlhttp_ready(xmlhttp)) {
  967. printLockingError();
  968. return
  969. }
  970. var sel_rows = getSelectedFeeds();
  971. var cat_sel = document.getElementById("sfeed_set_fcat");
  972. var cat_id = cat_sel[cat_sel.selectedIndex].value;
  973. if (sel_rows.length > 0) {
  974. notify_progress("Changing category of selected feeds...");
  975. xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=categorize&ids="+
  976. param_escape(sel_rows.toString()) + "&cat_id=" + param_escape(cat_id), true);
  977. xmlhttp.onreadystatechange=feedlist_callback;
  978. xmlhttp.send(null);
  979. } else {
  980. alert(__("No feeds are selected."));
  981. }
  982. }
  983. function validatePrefsReset() {
  984. return confirm(__("Reset to defaults?"));
  985. }
  986. function browseFeeds(limit) {
  987. xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=browse", true);
  988. xmlhttp.onreadystatechange=infobox_callback;
  989. xmlhttp.send(null);
  990. }
  991. function feedBrowserSubscribe() {
  992. try {
  993. var selected = getSelectedFeedsFromBrowser();
  994. if (selected.length > 0) {
  995. closeInfoBox();
  996. xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=massSubscribe&ids="+
  997. param_escape(selected.toString()), true);
  998. xmlhttp.onreadystatechange=feedlist_callback;
  999. xmlhttp.send(null);
  1000. } else {
  1001. alert("No feeds are selected.");
  1002. }
  1003. } catch (e) {
  1004. exception_error("feedBrowserSubscribe", e);
  1005. }
  1006. }
  1007. function updateBigFeedBrowser(limit) {
  1008. if (!xmlhttp_ready(xmlhttp)) {
  1009. printLockingError();
  1010. return
  1011. }
  1012. // p_notify("Loading, please wait...");
  1013. var query = "backend.php?op=pref-feed-browser";
  1014. var limit_sel = document.getElementById("feedBrowserLimit");
  1015. if (limit_sel) {
  1016. var limit = limit_sel[limit_sel.selectedIndex].value;
  1017. query = query + "&limit=" + param_escape(limit);
  1018. }
  1019. xmlhttp.open("GET", query, true);
  1020. xmlhttp.onreadystatechange=feed_browser_callback;
  1021. xmlhttp.send(null);
  1022. }
  1023. function browserToggleExpand(id) {
  1024. try {
  1025. /* if (feed_to_expand && feed_to_expand != id) {
  1026. var d = document.getElementById("BRDET-" + feed_to_expand);
  1027. d.style.display = "none";
  1028. } */
  1029. if (!xmlhttp_ready(xmlhttp)) {
  1030. printLockingError();
  1031. return
  1032. }
  1033. var d = document.getElementById("BRDET-" + id);
  1034. if (d.style.display == "block") {
  1035. d.style.display = "none";
  1036. } else {
  1037. feed_to_expand = id;
  1038. d.style.display = "block";
  1039. d.innerHTML = "Loading, please wait...";
  1040. xmlhttp.open("GET", "backend.php?op=pref-feed-browser&subop=details&id="
  1041. + param_escape(id), true);
  1042. xmlhttp.onreadystatechange=expand_feed_callback;
  1043. xmlhttp.send(null);
  1044. }
  1045. } catch (e) {
  1046. exception_error("browserExpand", e);
  1047. }
  1048. }
  1049. function selectPrefRows(kind, select) {
  1050. if (kind) {
  1051. var opbarid = false;
  1052. var nchk = false;
  1053. var nrow = false;
  1054. var lname = false;
  1055. if (kind == "feed") {
  1056. opbarid = "feedOpToolbar";
  1057. nrow = "FEEDR-";
  1058. nchk = "FRCHK-";
  1059. lname = "prefFeedList";
  1060. } else if (kind == "fcat") {
  1061. opbarid = "catOpToolbar";
  1062. nrow = "FCATR-";
  1063. nchk = "FCCHK-";
  1064. lname = "prefFeedCatList";
  1065. } else if (kind == "filter") {
  1066. opbarid = "filterOpToolbar";
  1067. nrow = "FILRR-";
  1068. nchk = "FICHK-";
  1069. lname = "prefFilterList";
  1070. } else if (kind == "label") {
  1071. opbarid = "labelOpToolbar";
  1072. nrow = "LILRR-";
  1073. nchk = "LICHK-";
  1074. lname = "prefLabelList";
  1075. } else if (kind == "user") {
  1076. opbarid = "userOpToolbar";
  1077. nrow = "UMRR-";
  1078. nchk = "UMCHK-";
  1079. lname = "prefUserList";
  1080. }
  1081. if (opbarid) {
  1082. selectTableRowsByIdPrefix(lname, nrow, nchk, select);
  1083. disableContainerChildren(opbarid, !select);
  1084. }
  1085. }
  1086. }
  1087. function toggleSelectPrefRow(sender, kind) {
  1088. toggleSelectRow(sender);
  1089. if (kind) {
  1090. var opbarid = false;
  1091. var nsel = -1;
  1092. if (kind == "feed") {
  1093. opbarid = "feedOpToolbar";
  1094. nsel = getSelectedFeeds();
  1095. } else if (kind == "fcat") {
  1096. opbarid = "catOpToolbar";
  1097. nsel = getSelectedFeedCats();
  1098. } else if (kind == "filter") {
  1099. opbarid = "filterOpToolbar";
  1100. nsel = getSelectedFilters();
  1101. } else if (kind == "label") {
  1102. opbarid = "labelOpToolbar";
  1103. nsel = getSelectedLabels();
  1104. } else if (kind == "user") {
  1105. opbarid = "userOpToolbar";
  1106. nsel = getSelectedUsers();
  1107. }
  1108. if (opbarid && nsel != -1) {
  1109. disableContainerChildren(opbarid, nsel == false);
  1110. }
  1111. }
  1112. }
  1113. function toggleSelectFBListRow(sender) {
  1114. toggleSelectListRow(sender);
  1115. disableContainerChildren("fbrOpToolbar", getSelectedFeedsFromBrowser() == 0);
  1116. }
  1117. var seq = "";
  1118. function pref_hotkey_handler(e) {
  1119. try {
  1120. var keycode;
  1121. if (!hotkeys_enabled) return;
  1122. if (window.event) {
  1123. keycode = window.event.keyCode;
  1124. } else if (e) {
  1125. keycode = e.which;
  1126. }
  1127. if (keycode == 13 || keycode == 27) {
  1128. seq = "";
  1129. } else {
  1130. seq = seq + "" + keycode;
  1131. }
  1132. if (document.getElementById("piggie")) {
  1133. if (seq.match("807371717369")) {
  1134. seq = "";
  1135. localPiggieFunction(true);
  1136. } else {
  1137. localPiggieFunction(false);
  1138. }
  1139. }
  1140. } catch (e) {
  1141. exception_error("pref_hotkey_handler", e);
  1142. }
  1143. }
  1144. function userSwitch() {
  1145. var chooser = document.getElementById("userSwitch");
  1146. var user = chooser[chooser.selectedIndex].value;
  1147. window.location = "prefs.php?swu=" + user;
  1148. }
  1149. function editFeedCats() {
  1150. if (!xmlhttp_ready(xmlhttp)) {
  1151. printLockingError();
  1152. return
  1153. }
  1154. xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editCats", true);
  1155. xmlhttp.onreadystatechange=infobox_callback;
  1156. xmlhttp.send(null);
  1157. }
  1158. function showFeedsWithErrors() {
  1159. displayDlg('feedUpdateErrors');
  1160. }
  1161. function changeUserPassword() {
  1162. try {
  1163. if (!xmlhttp_ready(xmlhttp)) {
  1164. printLockingError();
  1165. return false;
  1166. }
  1167. var query = Form.serialize("change_pass_form");
  1168. notify_progress("Trying to change password...");
  1169. xmlhttp.open("POST", "backend.php", true);
  1170. xmlhttp.onreadystatechange=changepass_callback;
  1171. xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  1172. xmlhttp.send(query);
  1173. } catch (e) {
  1174. exception_error("changeUserPassword", e);
  1175. }
  1176. return false;
  1177. }
  1178. function changeUserEmail() {
  1179. try {
  1180. if (!xmlhttp_ready(xmlhttp)) {
  1181. printLockingError();
  1182. return false;
  1183. }
  1184. var query = Form.serialize("change_email_form");
  1185. notify_progress("Trying to change e-mail...");
  1186. xmlhttp.open("POST", "backend.php", true);
  1187. xmlhttp.onreadystatechange=notify_callback;
  1188. xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  1189. xmlhttp.send(query);
  1190. } catch (e) {
  1191. exception_error("changeUserPassword", e);
  1192. }
  1193. return false;
  1194. }