1 var notify_silent = false;
2 var loading_progress = 0;
3 var sanity_check_done = false;
5 /* add method to remove element from array */
7 Array.prototype.remove = function(s) {
8 for (var i=0; i < this.length; i++) {
9 if (s == this[i]) this.splice(i, 1);
13 /* create console.log if it doesn't exist */
15 if (!window.console) console = {};
16 console.log = console.log || function(msg) { };
17 console.warn = console.warn || function(msg) { };
18 console.error = console.error || function(msg) { };
20 function exception_error(location, e, ext_info) {
21 var msg = format_exception_error(location, e);
23 if (!ext_info) ext_info = false;
28 if (ext_info.responseText) {
29 ext_info = ext_info.responseText;
33 var content = "<div class=\"fatalError\">" +
34 "<pre>" + msg + "</pre>";
36 content += "<form name=\"exceptionForm\" id=\"exceptionForm\" target=\"_blank\" "+
37 "action=\"http://tt-rss.org/report.php\" method=\"POST\">";
39 content += "<textarea style=\"display : none\" name=\"message\">" + msg + "</textarea>";
40 content += "<textarea style=\"display : none\" name=\"params\">N/A</textarea>";
43 content += "<div><b>Additional information:</b></div>" +
44 "<textarea name=\"xinfo\" readonly=\"1\">" + ext_info + "</textarea>";
47 content += "<div><b>Stack trace:</b></div>" +
48 "<textarea name=\"stack\" readonly=\"1\">" + e.stack + "</textarea>";
54 content += "<div class='dlgButtons'>";
56 content += "<button dojoType=\"dijit.form.Button\""+
57 "onclick=\"dijit.byId('exceptionDlg').report()\">" +
58 __('Report to tt-rss.org') + "</button> ";
59 content += "<button dojoType=\"dijit.form.Button\" "+
60 "onclick=\"dijit.byId('exceptionDlg').hide()\">" +
61 __('Close') + "</button>";
64 if (dijit.byId("exceptionDlg"))
65 dijit.byId("exceptionDlg").destroyRecursive();
67 var dialog = new dijit.Dialog({
69 title: "Unhandled exception",
70 style: "width: 600px",
72 if (confirm(__("Are you sure to report this exception to tt-rss.org? The report will include your browser information. Your IP would be saved in the database."))) {
74 document.forms['exceptionForm'].params.value = $H({
75 browserName: navigator.appName,
76 browserVersion: navigator.appVersion,
77 browserPlatform: navigator.platform,
78 browserCookies: navigator.cookieEnabled,
81 document.forms['exceptionForm'].submit();
95 function format_exception_error(location, e) {
99 var base_fname = e.fileName.substring(e.fileName.lastIndexOf("/") + 1);
101 msg = "Exception: " + e.name + ", " + e.message +
102 "\nFunction: " + location + "()" +
103 "\nLocation: " + base_fname + ":" + e.lineNumber;
105 } else if (e.description) {
106 msg = "Exception: " + e.description + "\nFunction: " + location + "()";
108 msg = "Exception: " + e + "\nFunction: " + location + "()";
111 console.error("EXCEPTION: " + msg);
116 function param_escape(arg) {
117 if (typeof encodeURIComponent != 'undefined')
118 return encodeURIComponent(arg);
123 function param_unescape(arg) {
124 if (typeof decodeURIComponent != 'undefined')
125 return decodeURIComponent(arg);
127 return unescape(arg);
130 var notify_hide_timerid = false;
132 function hide_notify() {
135 n.style.display = "none";
139 function notify_silent_next() {
140 notify_silent = true;
143 function notify_real(msg, no_hide, n_type) {
146 notify_silent = false;
151 var nb = $("notify_body");
153 if (!n || !nb) return;
155 if (notify_hide_timerid) {
156 window.clearTimeout(notify_hide_timerid);
160 if (n.style.display == "block") {
161 notify_hide_timerid = window.setTimeout("hide_notify()", 0);
165 n.style.display = "block";
177 if (typeof __ != 'undefined') {
182 n.className = "notify";
183 } else if (n_type == 2) {
184 n.className = "notifyProgress";
185 msg = "<img src='"+getInitParam("sign_progress")+"'> " + msg;
186 } else if (n_type == 3) {
187 n.className = "notifyError";
188 msg = "<img src='"+getInitParam("sign_excl")+"'> " + msg;
189 } else if (n_type == 4) {
190 n.className = "notifyInfo";
191 msg = "<img src='"+getInitParam("sign_info")+"'> " + msg;
194 // msg = "<img src='images/live_com_loading.gif'> " + msg;
199 notify_hide_timerid = window.setTimeout("hide_notify()", 3000);
203 function notify(msg, no_hide) {
204 notify_real(msg, no_hide, 1);
207 function notify_progress(msg, no_hide) {
208 notify_real(msg, no_hide, 2);
211 function notify_error(msg, no_hide) {
212 notify_real(msg, no_hide, 3);
216 function notify_info(msg, no_hide) {
217 notify_real(msg, no_hide, 4);
220 function setCookie(name, value, lifetime, path, domain, secure) {
226 d.setTime(d.getTime() + (lifetime * 1000));
229 console.log("setCookie: " + name + " => " + value + ": " + d);
231 int_setCookie(name, value, d, path, domain, secure);
235 function int_setCookie(name, value, expires, path, domain, secure) {
236 document.cookie= name + "=" + escape(value) +
237 ((expires) ? "; expires=" + expires.toGMTString() : "") +
238 ((path) ? "; path=" + path : "") +
239 ((domain) ? "; domain=" + domain : "") +
240 ((secure) ? "; secure" : "");
243 function delCookie(name, path, domain) {
244 if (getCookie(name)) {
245 document.cookie = name + "=" +
246 ((path) ? ";path=" + path : "") +
247 ((domain) ? ";domain=" + domain : "" ) +
248 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
253 function getCookie(name) {
255 var dc = document.cookie;
256 var prefix = name + "=";
257 var begin = dc.indexOf("; " + prefix);
259 begin = dc.indexOf(prefix);
260 if (begin != 0) return null;
265 var end = document.cookie.indexOf(";", begin);
269 return unescape(dc.substring(begin + prefix.length, end));
272 function gotoPreferences() {
273 document.location.href = "prefs.php";
276 function gotoMain() {
277 document.location.href = "tt-rss.php";
280 function gotoExportOpml() {
281 document.location.href = "opml.php?op=Export";
285 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
286 * * @author Sundar Dorai-Raj
287 * * Email: sdoraira@vt.edu
288 * * This program is free software; you can redistribute it and/or
289 * * modify it under the terms of the GNU General Public License
290 * * as published by the Free Software Foundation; either version 2
291 * * of the License, or (at your option) any later version,
292 * * provided that any use properly credits the author.
293 * * This program is distributed in the hope that it will be useful,
294 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
295 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
296 * * GNU General Public License for more details at http://www.gnu.org * * */
298 var numbers=".0123456789";
299 function isNumeric(x) {
300 // is x a String or a character?
302 // remove negative sign
304 for(j=0;j<x.length;j++) {
305 // call isNumeric recursively for each character
306 number=isNumeric(x.substring(j,j+1));
307 if(!number) return number;
312 // if x is number return true
313 if(numbers.indexOf(x)>=0) return true;
319 function toggleSelectRowById(sender, id) {
321 return toggleSelectRow(sender, row);
324 function toggleSelectListRow(sender) {
325 var row = sender.parentNode;
326 return toggleSelectRow(sender, row);
329 /* this is for dijit Checkbox */
330 function toggleSelectListRow2(sender) {
331 var row = sender.domNode.parentNode;
332 return toggleSelectRow(sender, row);
335 function tSR(sender, row) {
336 return toggleSelectRow(sender, row);
339 /* this is for dijit Checkbox */
340 function toggleSelectRow2(sender, row) {
342 if (!row) row = sender.domNode.parentNode.parentNode;
344 if (sender.checked && !row.hasClassName('Selected'))
345 row.addClassName('Selected');
347 row.removeClassName('Selected');
351 function toggleSelectRow(sender, row) {
353 if (!row) row = sender.parentNode.parentNode;
355 if (sender.checked && !row.hasClassName('Selected'))
356 row.addClassName('Selected');
358 row.removeClassName('Selected');
361 function checkboxToggleElement(elem, id) {
363 Effect.Appear(id, {duration : 0.5});
365 Effect.Fade(id, {duration : 0.5});
369 function dropboxSelect(e, v) {
370 for (i = 0; i < e.length; i++) {
371 if (e[i].value == v) {
378 function getURLParam(param){
379 return String(window.location.href).parseQuery()[param];
382 function leading_zero(p) {
384 if (s.length == 1) s = "0" + s;
388 function make_timestamp() {
391 return leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
392 ":" + leading_zero(d.getSeconds());
396 function closeErrorBox() {
398 if (Element.visible("errorBoxShadow")) {
399 Element.hide("dialog_overlay");
400 Element.hide("errorBoxShadow");
406 function closeInfoBox(cleanup) {
408 dialog = dijit.byId("infoBox");
410 if (dialog) dialog.hide();
413 //exception_error("closeInfoBox", e);
419 function displayDlg(id, param, callback) {
421 notify_progress("Loading, please wait...", true);
423 var query = "?op=dlg&id=" +
424 param_escape(id) + "¶m=" + param_escape(param);
426 new Ajax.Request("backend.php", {
428 onComplete: function (transport) {
429 infobox_callback2(transport);
430 if (callback) callback(transport);
436 function infobox_callback2(transport) {
440 if (dijit.byId("infoBox")) {
441 dialog = dijit.byId("infoBox");
444 //console.log("infobox_callback2");
448 var dtitle = "Dialog";
450 var dlg = transport.responseXML.getElementsByTagName("dlg")[0];
452 var title = transport.responseXML.getElementsByTagName("title")[0];
454 title = title.firstChild.nodeValue;
456 var content = transport.responseXML.getElementsByTagName("content")[0];
458 content = content.firstChild.nodeValue;
461 dialog = new dijit.Dialog({
464 style: "width: 600px",
465 onCancel: function() {
468 onExecute: function() {
471 onClose: function() {
476 dialog.attr('title', title);
477 dialog.attr('content', content);
484 exception_error("infobox_callback2", e);
488 function filterCR(e, f)
493 key = window.event.keyCode; //IE
495 key = e.which; //firefox
498 if (typeof f != 'undefined') {
509 function getInitParam(key) {
510 return init_params[key];
513 function setInitParam(key, value) {
514 init_params[key] = value;
517 function fatalError(code, msg, ext_info) {
521 window.location.href = "tt-rss.php";
522 } else if (code == 5) {
523 window.location.href = "db-updater.php";
526 if (msg == "") msg = "Unknown error";
529 if (ext_info.responseText) {
530 ext_info = ext_info.responseText;
534 if (ERRORS && ERRORS[code] && !msg) {
538 var content = "<div><b>Error code:</b> " + code + "</div>" +
539 "<p>" + msg + "</p>";
542 content = content + "<div><b>Additional information:</b></div>" +
543 "<textarea style='width: 100%' readonly=\"1\">" +
544 ext_info + "</textarea>";
547 var dialog = new dijit.Dialog({
548 title: "Fatal error",
549 style: "width: 600px",
559 exception_error("fatalError", e);
563 function filterDlgCheckType(sender) {
567 var ftype = sender.value;
569 // if selected filter type is 5 (Date) enable the modifier dropbox
571 Element.show("filterDlg_dateModBox");
572 Element.show("filterDlg_dateChkBox");
574 Element.hide("filterDlg_dateModBox");
575 Element.hide("filterDlg_dateChkBox");
580 exception_error("filterDlgCheckType", e);
585 function filterDlgCheckAction(sender) {
589 var action = sender.value;
591 var action_param = $("filterDlg_paramBox");
594 console.log("filterDlgCheckAction: can't find action param box!");
598 // if selected action supports parameters, enable params field
599 if (action == 4 || action == 6 || action == 7) {
600 new Effect.Appear(action_param, {duration : 0.5});
602 Element.show(dijit.byId("filterDlg_actionParam").domNode);
603 Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode);
605 Element.show(dijit.byId("filterDlg_actionParamLabel").domNode);
606 Element.hide(dijit.byId("filterDlg_actionParam").domNode);
609 Element.hide(action_param);
613 exception_error("filterDlgCheckAction", e);
618 function filterDlgCheckDate() {
620 var dialog = dijit.byId("filterEditDlg");
622 var reg_exp = dialog.attr('value').reg_exp;
624 var query = "?op=rpc&subop=checkDate&date=" + reg_exp;
626 new Ajax.Request("backend.php", {
628 onComplete: function(transport) {
630 var reply = JSON.parse(transport.responseText);
632 if (reply['result'] == true) {
633 alert(__("Date syntax appears to be correct:") + " " + reply['date']);
636 alert(__("Date syntax is incorrect."));
643 exception_error("filterDlgCheckDate", e);
647 function explainError(code) {
648 return displayDlg("explainError", code);
651 function displayHelpInfobox(topic_id) {
653 var url = "backend.php?op=help&tid=" + param_escape(topic_id);
655 var w = window.open(url, "ttrss_help",
656 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
660 function loading_set_progress(p) {
662 loading_progress += p;
664 if (dijit.byId("loading_bar"))
665 dijit.byId("loading_bar").update({progress: loading_progress});
667 if (loading_progress >= 90)
671 exception_error("loading_set_progress", e);
675 function remove_splash() {
677 if (Element.visible("overlay")) {
678 console.log("about to remove splash, OMG!");
679 Element.hide("overlay");
680 console.log("removed splash!");
684 function transport_error_check(transport) {
686 if (transport.responseXML) {
687 var error = transport.responseXML.getElementsByTagName("error")[0];
690 var code = error.getAttribute("error-code");
691 var msg = error.getAttribute("error-msg");
693 fatalError(code, msg);
699 exception_error("check_for_error_xml", e);
704 function strip_tags(s) {
705 return s.replace(/<\/?[^>]+(>|$)/g, "");
708 function truncate_string(s, length) {
709 if (!length) length = 30;
710 var tmp = s.substring(0, length);
711 if (s.length > length) tmp += "…";
715 function hotkey_prefix_timeout() {
718 var date = new Date();
719 var ts = Math.round(date.getTime() / 1000);
721 if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) {
722 console.log("hotkey_prefix seems to be stuck, aborting");
723 hotkey_prefix_pressed = false;
724 hotkey_prefix = false;
725 Element.hide('cmdline');
728 setTimeout("hotkey_prefix_timeout()", 1000);
731 exception_error("hotkey_prefix_timeout", e);
735 function hideAuxDlg() {
737 Element.hide('auxDlg');
739 exception_error("hideAuxDlg", e);
744 function uploadIconHandler(rc) {
748 notify_info("Upload complete.");
749 if (inPreferences()) {
752 setTimeout('updateFeedList(false, false)', 50);
756 notify_error("Upload failed: icon is too big.");
759 notify_error("Upload failed.");
764 exception_error("uploadIconHandler", e);
768 function removeFeedIcon(id) {
772 if (confirm(__("Remove stored feed icon?"))) {
773 var query = "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id);
777 notify_progress("Removing feed icon...", true);
779 new Ajax.Request("backend.php", {
781 onComplete: function(transport) {
782 notify_info("Feed icon removed.");
783 if (inPreferences()) {
786 setTimeout('updateFeedList(false, false)', 50);
793 exception_error("uploadFeedIcon", e);
797 function uploadFeedIcon() {
801 var file = $("icon_file");
803 if (file.value.length == 0) {
804 alert(__("Please select an image file to upload."));
806 if (confirm(__("Upload new icon for this feed?"))) {
807 notify_progress("Uploading, please wait...", true);
815 exception_error("uploadFeedIcon", e);
819 function addLabel(select, callback) {
823 var caption = prompt(__("Please enter label caption:"), "");
825 if (caption != undefined) {
828 alert(__("Can't create label: missing caption."));
832 var query = "?op=pref-labels&subop=add&caption=" +
833 param_escape(caption);
836 query += "&output=select";
838 notify_progress("Loading, please wait...", true);
840 if (inPreferences() && !select) active_tab = "labelConfig";
842 new Ajax.Request("backend.php", {
844 onComplete: function(transport) {
847 } else if (inPreferences()) {
857 exception_error("addLabel", e);
861 function quickAddFeed() {
863 var query = "backend.php?op=dlg&id=quickAddFeed";
865 if (dijit.byId("feedAddDlg"))
866 dijit.byId("feedAddDlg").destroyRecursive();
868 var dialog = new dijit.Dialog({
870 title: __("Subscribe to Feed"),
871 style: "width: 600px",
872 execute: function() {
873 if (this.validate()) {
874 console.log(dojo.objectToQuery(this.attr('value')));
876 var feed_url = this.attr('value').feed;
878 notify_progress(__("Subscribing to feed..."), true);
880 new Ajax.Request("backend.php", {
881 parameters: dojo.objectToQuery(this.attr('value')),
882 onComplete: function(transport) {
885 var reply = JSON.parse(transport.responseText);
887 var rc = parseInt(reply['result']);
891 console.log("GOT RC: " + rc);
896 notify_info(__("Subscribed to %s").replace("%s", feed_url));
901 alert(__("Specified URL seems to be invalid."));
904 alert(__("Specified URL doesn't seem to contain any feeds."));
907 notify_progress("Searching for feed urls...", true);
909 new Ajax.Request("backend.php", {
910 parameters: 'op=rpc&subop=extractfeedurls&url=' + param_escape(feed_url),
911 onComplete: function(transport, dialog, feed_url) {
915 var reply = JSON.parse(transport.responseText);
917 var feeds = reply['urls'];
919 console.log(transport.responseText);
921 var select = dijit.byId("feedDlg_feedContainerSelect");
923 while (select.getOptions().length > 0)
924 select.removeOption(0);
927 for (var feedUrl in feeds) {
928 select.addOption({value: feedUrl, label: feeds[feedUrl]});
932 // if (count > 5) count = 5;
933 // select.size = count;
935 Effect.Appear('feedDlg_feedsContainer', {duration : 0.5});
940 alert(__("Couldn't download the specified URL."));
943 alert(__("You are already subscribed to this feed."));
948 exception_error("subscribeToFeed", e, transport);
959 exception_error("quickAddFeed", e);
963 function quickAddFilter() {
965 var query = "backend.php?op=dlg&id=quickAddFilter";
967 if (dijit.byId("filterEditDlg"))
968 dijit.byId("filterEditDlg").destroyRecursive();
970 dialog = new dijit.Dialog({
972 title: __("Create Filter"),
973 style: "width: 600px",
975 if (this.validate()) {
977 if (dijit.byId("filterTestDlg"))
978 dijit.byId("filterTestDlg").destroyRecursive();
980 tdialog = new dijit.Dialog({
982 title: __("Filter Test Results"),
983 style: "width: 600px",
984 href: "backend.php?savemode=test&" +
985 dojo.objectToQuery(dialog.attr('value')),
992 execute: function() {
993 if (this.validate()) {
995 var query = "?op=rpc&subop=verifyRegexp®_exp=" +
996 param_escape(dialog.attr('value').reg_exp);
998 notify_progress("Verifying regular expression...");
1000 new Ajax.Request("backend.php", {
1002 onComplete: function(transport) {
1003 var reply = JSON.parse(transport.responseText);
1008 if (!reply['status']) {
1009 alert("Match regular expression seems to be invalid.");
1012 notify_progress("Saving data...", true);
1014 console.log(dojo.objectToQuery(dialog.attr('value')));
1016 new Ajax.Request("backend.php", {
1017 parameters: dojo.objectToQuery(dialog.attr('value')),
1018 onComplete: function(transport) {
1020 notify_info(transport.responseText);
1021 if (inPreferences()) {
1034 exception_error("quickAddFilter", e);
1038 function resetPubSub(feed_id, title) {
1040 var msg = __("Reset subscription? Tiny Tiny RSS will try to subscribe to the notification hub again on next feed update.").replace("%s", title);
1042 if (title == undefined || confirm(msg)) {
1043 notify_progress("Loading, please wait...");
1045 var query = "?op=pref-feeds&quiet=1&subop=resetPubSub&ids=" + feed_id;
1047 new Ajax.Request("backend.php", {
1049 onComplete: function(transport) {
1050 dijit.byId("pubsubReset_Btn").attr('disabled', true);
1051 notify_info("Subscription reset.");
1059 function unsubscribeFeed(feed_id, title) {
1061 var msg = __("Unsubscribe from %s?").replace("%s", title);
1063 if (title == undefined || confirm(msg)) {
1064 notify_progress("Removing feed...");
1066 var query = "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id;
1068 new Ajax.Request("backend.php", {
1070 onComplete: function(transport) {
1072 if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").hide();
1074 if (inPreferences()) {
1077 if (feed_id == getActiveFeedId())
1078 setTimeout("viewfeed(-5)", 100);
1088 function backend_sanity_check_callback(transport) {
1092 if (sanity_check_done) {
1093 fatalError(11, "Sanity check request received twice. This can indicate "+
1094 "presence of Firebug or some other disrupting extension. "+
1095 "Please disable it and try again.");
1099 var reply = JSON.parse(transport.responseText);
1102 fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
1106 var error_code = reply['error']['code'];
1108 if (error_code && error_code != 0) {
1109 return fatalError(error_code, reply['error']['message']);
1112 console.log("sanity check ok");
1114 var params = reply['init-params'];
1117 console.log('reading init-params...');
1122 console.log("IP: " + k + " => " + v);
1126 init_params = params;
1129 sanity_check_done = true;
1131 init_second_stage();
1134 exception_error("backend_sanity_check_callback", e, transport);
1138 function has_local_storage() {
1140 return 'sessionStorage' in window && window['sessionStorage'] != null;
1146 function catSelectOnChange(elem) {
1148 /* var value = elem[elem.selectedIndex].value;
1149 var def = elem.getAttribute('default');
1151 if (value == "ADD_CAT") {
1154 dropboxSelect(elem, def);
1156 elem.selectedIndex = 0;
1162 exception_error("catSelectOnChange", e);
1166 function quickAddCat(elem) {
1168 var cat = prompt(__("Please enter category title:"));
1172 var query = "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat);
1174 notify_progress("Loading, please wait...", true);
1176 new Ajax.Request("backend.php", {
1178 onComplete: function (transport) {
1179 var response = transport.responseXML;
1180 var select = response.getElementsByTagName("select")[0];
1181 var options = select.getElementsByTagName("option");
1183 dropbox_replace_options(elem, options);
1192 exception_error("quickAddCat", e);
1196 function genUrlChangeKey(feed, is_cat) {
1199 var ok = confirm(__("Generate new syndication address for this feed?"));
1203 notify_progress("Trying to change address...", true);
1205 var query = "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed) +
1206 "&is_cat=" + param_escape(is_cat);
1208 new Ajax.Request("backend.php", {
1210 onComplete: function(transport) {
1211 var reply = JSON.parse(transport.responseText);
1212 var new_link = reply.link;
1214 var e = $('gen_feed_url');
1218 e.innerHTML = e.innerHTML.replace(/\&key=.*$/,
1219 "&key=" + new_link);
1221 e.href = e.href.replace(/\&key=.*$/,
1222 "&key=" + new_link);
1224 new Effect.Highlight(e);
1229 notify_error("Could not change feed URL.");
1234 exception_error("genUrlChangeKey", e);
1239 function labelSelectOnChange(elem) {
1241 /* var value = elem[elem.selectedIndex].value;
1242 var def = elem.getAttribute('default');
1244 if (value == "ADD_LABEL") {
1247 dropboxSelect(elem, def);
1249 elem.selectedIndex = 0;
1251 addLabel(elem, function(transport) {
1255 var response = transport.responseXML;
1256 var select = response.getElementsByTagName("select")[0];
1257 var options = select.getElementsByTagName("option");
1259 dropbox_replace_options(elem, options);
1263 exception_error("addLabel", e);
1269 exception_error("labelSelectOnChange", e);
1273 function dropbox_replace_options(elem, options) {
1276 while (elem.hasChildNodes())
1277 elem.removeChild(elem.firstChild);
1281 for (var i = 0; i < options.length; i++) {
1282 var text = options[i].firstChild.nodeValue;
1283 var value = options[i].getAttribute("value");
1285 if (value == undefined) value = text;
1287 var issel = options[i].getAttribute("selected") == "1";
1289 var option = new Option(text, value, issel);
1291 if (options[i].getAttribute("disabled"))
1292 option.setAttribute("disabled", true);
1294 elem.insert(option);
1296 if (issel) sel_idx = i;
1299 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1300 if (sel_idx >= 0) elem.selectedIndex = sel_idx;
1303 exception_error("dropbox_replace_options", e);
1307 // mode = all, none, invert
1308 function selectTableRows(id, mode) {
1310 var rows = $(id).rows;
1312 for (var i = 0; i < rows.length; i++) {
1316 if (row.id && row.className) {
1317 var bare_id = row.id.replace(/^[A-Z]*?-/, "");
1318 var inputs = rows[i].getElementsByTagName("input");
1320 for (var j = 0; j < inputs.length; j++) {
1321 var input = inputs[j];
1323 if (input.getAttribute("type") == "checkbox" &&
1324 input.id.match(bare_id)) {
1332 var issel = row.hasClassName("Selected");
1334 if (mode == "all" && !issel) {
1335 row.addClassName("Selected");
1337 } else if (mode == "none" && issel) {
1338 row.removeClassName("Selected");
1340 } else if (mode == "invert") {
1343 row.removeClassName("Selected");
1346 row.addClassName("Selected");
1355 exception_error("selectTableRows", e);
1360 function getSelectedTableRowIds(id) {
1364 var elem_rows = $(id).rows;
1366 for (i = 0; i < elem_rows.length; i++) {
1367 if (elem_rows[i].hasClassName("Selected")) {
1368 var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, "");
1374 exception_error("getSelectedTableRowIds", e);
1380 function editFeed(feed, event) {
1383 return alert(__("You can't edit this kind of feed."));
1385 var query = "backend.php?op=pref-feeds&subop=editfeed&id=" +
1390 if (dijit.byId("feedEditDlg"))
1391 dijit.byId("feedEditDlg").destroyRecursive();
1393 dialog = new dijit.Dialog({
1395 title: __("Edit Feed"),
1396 style: "width: 600px",
1397 execute: function() {
1398 if (this.validate()) {
1399 // console.log(dojo.objectToQuery(this.attr('value')));
1401 notify_progress("Saving data...", true);
1403 new Ajax.Request("backend.php", {
1404 parameters: dojo.objectToQuery(dialog.attr('value')),
1405 onComplete: function(transport) {
1417 exception_error("editFeed", e);
1421 function feedBrowser() {
1423 var query = "backend.php?op=dlg&id=feedBrowser";
1425 if (dijit.byId("feedAddDlg"))
1426 dijit.byId("feedAddDlg").hide();
1428 if (dijit.byId("feedBrowserDlg"))
1429 dijit.byId("feedBrowserDlg").destroyRecursive();
1431 var dialog = new dijit.Dialog({
1432 id: "feedBrowserDlg",
1433 title: __("More Feeds"),
1434 style: "width: 600px",
1435 getSelectedFeedIds: function() {
1436 var list = $$("#browseFeedList li[id*=FBROW]");
1437 var selected = new Array();
1439 list.each(function(child) {
1440 var id = child.id.replace("FBROW-", "");
1442 if (child.hasClassName('Selected')) {
1449 getSelectedFeeds: function() {
1450 var list = $$("#browseFeedList li.Selected");
1451 var selected = new Array();
1453 list.each(function(child) {
1454 var title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML;
1455 var url = child.getElementsBySelector("a.fb_feedUrl")[0].href;
1457 selected.push([title,url]);
1464 subscribe: function() {
1465 var mode = this.attr('value').mode;
1469 selected = this.getSelectedFeeds();
1471 selected = this.getSelectedFeedIds();
1473 if (selected.length > 0) {
1474 dijit.byId("feedBrowserDlg").hide();
1476 notify_progress("Loading, please wait...", true);
1478 // we use dojo.toJson instead of JSON.stringify because
1479 // it somehow escapes everything TWICE, at least in Chrome 9
1481 var query = "?op=rpc&subop=massSubscribe&payload="+
1482 param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode);
1486 new Ajax.Request("backend.php", {
1488 onComplete: function(transport) {
1494 alert(__("No feeds are selected."));
1498 update: function() {
1499 var query = dojo.objectToQuery(dialog.attr('value'));
1501 Element.show('feed_browser_spinner');
1503 new Ajax.Request("backend.php", {
1505 onComplete: function(transport) {
1508 Element.hide('feed_browser_spinner');
1510 var c = $("browseFeedList");
1512 var reply = JSON.parse(transport.responseText);
1514 var r = reply['content'];
1515 var mode = reply['mode'];
1521 dojo.parser.parse("browseFeedList");
1524 Element.show(dijit.byId('feed_archive_remove').domNode);
1526 Element.hide(dijit.byId('feed_archive_remove').domNode);
1531 removeFromArchive: function() {
1532 var selected = this.getSelectedFeeds();
1534 if (selected.length > 0) {
1536 var pr = __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1539 Element.show('feed_browser_spinner');
1541 var query = "?op=rpc&subop=remarchived&ids=" +
1542 param_escape(selected.toString());;
1544 new Ajax.Request("backend.php", {
1546 onComplete: function(transport) {
1552 execute: function() {
1553 if (this.validate()) {
1562 exception_error("editFeed", e);
1566 function showFeedsWithErrors() {
1568 var query = "backend.php?op=dlg&id=feedsWithErrors";
1570 if (dijit.byId("errorFeedsDlg"))
1571 dijit.byId("errorFeedsDlg").destroyRecursive();
1573 dialog = new dijit.Dialog({
1574 id: "errorFeedsDlg",
1575 title: __("Feeds with update errors"),
1576 style: "width: 600px",
1577 getSelectedFeeds: function() {
1578 return getSelectedTableRowIds("prefErrorFeedList");
1580 removeSelected: function() {
1581 var sel_rows = this.getSelectedFeeds();
1583 console.log(sel_rows);
1585 if (sel_rows.length > 0) {
1586 var ok = confirm(__("Remove selected feeds?"));
1589 notify_progress("Removing selected feeds...", true);
1591 var query = "?op=pref-feeds&subop=remove&ids="+
1592 param_escape(sel_rows.toString());
1594 new Ajax.Request("backend.php", {
1596 onComplete: function(transport) {
1604 alert(__("No feeds are selected."));
1607 execute: function() {
1608 if (this.validate()) {
1616 exception_error("showFeedsWithErrors", e);