]>
git.wh0rd.org - tt-rss.git/blob - functions.js
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>";
37 content
+= "<div><b>Additional information:</b></div>" +
38 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
41 content
+= "<div><b>Stack trace:</b></div>" +
42 "<textarea readonly=\"1\">" + e
.stack
+ "</textarea>";
46 // TODO: add code to automatically report errors to tt-rss.org
48 var dialog
= new dijit
.Dialog({
49 title
: "Unhandled exception",
50 style
: "width: 600px",
61 function format_exception_error(location
, e
) {
65 var base_fname
= e
.fileName
.substring(e
.fileName
.lastIndexOf("/") + 1);
67 msg
= "Exception: " + e
.name
+ ", " + e
.message
+
68 "\nFunction: " + location
+ "()" +
69 "\nLocation: " + base_fname
+ ":" + e
.lineNumber
;
71 } else if (e
.description
) {
72 msg
= "Exception: " + e
.description
+ "\nFunction: " + location
+ "()";
74 msg
= "Exception: " + e
+ "\nFunction: " + location
+ "()";
77 console
.error("EXCEPTION: " + msg
);
82 function param_escape(arg
) {
83 if (typeof encodeURIComponent
!= 'undefined')
84 return encodeURIComponent(arg
);
89 function param_unescape(arg
) {
90 if (typeof decodeURIComponent
!= 'undefined')
91 return decodeURIComponent(arg
);
96 var notify_hide_timerid
= false;
98 function hide_notify() {
101 n
.style
.display
= "none";
105 function notify_silent_next() {
106 notify_silent
= true;
109 function notify_real(msg
, no_hide
, n_type
) {
112 notify_silent
= false;
117 var nb
= $("notify_body");
119 if (!n
|| !nb
) return;
121 if (notify_hide_timerid
) {
122 window
.clearTimeout(notify_hide_timerid
);
126 if (n
.style
.display
== "block") {
127 notify_hide_timerid
= window
.setTimeout("hide_notify()", 0);
131 n
.style
.display
= "block";
143 if (typeof __
!= 'undefined') {
148 n
.className
= "notify";
149 } else if (n_type
== 2) {
150 n
.className
= "notifyProgress";
151 msg
= "<img src='"+getInitParam("sign_progress")+"'> " + msg
;
152 } else if (n_type
== 3) {
153 n
.className
= "notifyError";
154 msg
= "<img src='"+getInitParam("sign_excl")+"'> " + msg
;
155 } else if (n_type
== 4) {
156 n
.className
= "notifyInfo";
157 msg
= "<img src='"+getInitParam("sign_info")+"'> " + msg
;
160 // msg = "<img src='images/live_com_loading.gif'> " + msg;
165 notify_hide_timerid
= window
.setTimeout("hide_notify()", 3000);
169 function notify(msg
, no_hide
) {
170 notify_real(msg
, no_hide
, 1);
173 function notify_progress(msg
, no_hide
) {
174 notify_real(msg
, no_hide
, 2);
177 function notify_error(msg
, no_hide
) {
178 notify_real(msg
, no_hide
, 3);
182 function notify_info(msg
, no_hide
) {
183 notify_real(msg
, no_hide
, 4);
186 function setCookie(name
, value
, lifetime
, path
, domain
, secure
) {
192 d
.setTime(d
.getTime() + (lifetime
* 1000));
195 console
.log("setCookie: " + name
+ " => " + value
+ ": " + d
);
197 int_setCookie(name
, value
, d
, path
, domain
, secure
);
201 function int_setCookie(name
, value
, expires
, path
, domain
, secure
) {
202 document
.cookie
= name
+ "=" + escape(value
) +
203 ((expires
) ? "; expires=" + expires
.toGMTString() : "") +
204 ((path
) ? "; path=" + path
: "") +
205 ((domain
) ? "; domain=" + domain
: "") +
206 ((secure
) ? "; secure" : "");
209 function delCookie(name
, path
, domain
) {
210 if (getCookie(name
)) {
211 document
.cookie
= name
+ "=" +
212 ((path
) ? ";path=" + path
: "") +
213 ((domain
) ? ";domain=" + domain
: "" ) +
214 ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
219 function getCookie(name
) {
221 var dc
= document
.cookie
;
222 var prefix
= name
+ "=";
223 var begin
= dc
.indexOf("; " + prefix
);
225 begin
= dc
.indexOf(prefix
);
226 if (begin
!= 0) return null;
231 var end
= document
.cookie
.indexOf(";", begin
);
235 return unescape(dc
.substring(begin
+ prefix
.length
, end
));
238 function gotoPreferences() {
239 document
.location
.href
= "prefs.php";
242 function gotoMain() {
243 document
.location
.href
= "tt-rss.php";
246 function gotoExportOpml() {
247 document
.location
.href
= "opml.php?op=Export";
251 /** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
252 * * @author Sundar Dorai-Raj
253 * * Email: sdoraira@vt.edu
254 * * This program is free software; you can redistribute it and/or
255 * * modify it under the terms of the GNU General Public License
256 * * as published by the Free Software Foundation; either version 2
257 * * of the License, or (at your option) any later version,
258 * * provided that any use properly credits the author.
259 * * This program is distributed in the hope that it will be useful,
260 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
261 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
262 * * GNU General Public License for more details at http://www.gnu.org * * */
264 var numbers
=".0123456789";
265 function isNumeric(x
) {
266 // is x a String or a character?
268 // remove negative sign
270 for(j
=0;j
<x
.length
;j
++) {
271 // call isNumeric recursively for each character
272 number
=isNumeric(x
.substring(j
,j
+1));
273 if(!number
) return number
;
278 // if x is number return true
279 if(numbers
.indexOf(x
)>=0) return true;
285 function toggleSelectRowById(sender
, id
) {
287 return toggleSelectRow(sender
, row
);
290 function toggleSelectListRow(sender
) {
291 var row
= sender
.parentNode
;
292 return toggleSelectRow(sender
, row
);
295 /* this is for dijit Checkbox */
296 function toggleSelectListRow2(sender
) {
297 var row
= sender
.domNode
.parentNode
;
298 return toggleSelectRow(sender
, row
);
301 function tSR(sender
, row
) {
302 return toggleSelectRow(sender
, row
);
305 /* this is for dijit Checkbox */
306 function toggleSelectRow2(sender
, row
) {
308 if (!row
) row
= sender
.domNode
.parentNode
.parentNode
;
310 if (sender
.checked
&& !row
.hasClassName('Selected'))
311 row
.addClassName('Selected');
313 row
.removeClassName('Selected');
317 function toggleSelectRow(sender
, row
) {
319 if (!row
) row
= sender
.parentNode
.parentNode
;
321 if (sender
.checked
&& !row
.hasClassName('Selected'))
322 row
.addClassName('Selected');
324 row
.removeClassName('Selected');
327 function checkboxToggleElement(elem
, id
) {
329 Effect
.Appear(id
, {duration
: 0.5});
331 Effect
.Fade(id
, {duration
: 0.5});
335 function dropboxSelect(e
, v
) {
336 for (i
= 0; i
< e
.length
; i
++) {
337 if (e
[i
].value
== v
) {
344 // originally stolen from http://www.11tmr.com/11tmr.nsf/d6plinks/MWHE-695L9Z
345 // bugfixed just a little bit :-)
346 function getURLParam(strParamName
){
348 var strHref
= window
.location
.href
;
350 if (strHref
.indexOf("#") == strHref
.length
-1) {
351 strHref
= strHref
.substring(0, strHref
.length
-1);
354 if ( strHref
.indexOf("?") > -1 ){
355 var strQueryString
= strHref
.substr(strHref
.indexOf("?"));
356 var aQueryString
= strQueryString
.split("&");
357 for ( var iParam
= 0; iParam
< aQueryString
.length
; iParam
++ ){
358 if (aQueryString
[iParam
].indexOf(strParamName
+ "=") > -1 ){
359 var aParam
= aQueryString
[iParam
].split("=");
360 strReturn
= aParam
[1];
368 function leading_zero(p
) {
370 if (s
.length
== 1) s
= "0" + s
;
374 function make_timestamp() {
377 return leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
378 ":" + leading_zero(d
.getSeconds());
382 function closeErrorBox() {
384 if (Element
.visible("errorBoxShadow")) {
385 Element
.hide("dialog_overlay");
386 Element
.hide("errorBoxShadow");
392 function closeInfoBox(cleanup
) {
394 dialog
= dijit
.byId("infoBox");
396 if (dialog
) dialog
.hide();
399 //exception_error("closeInfoBox", e);
405 function displayDlg(id
, param
, callback
) {
407 notify_progress("Loading, please wait...", true);
409 var query
= "?op=dlg&id=" +
410 param_escape(id
) + "¶m=" + param_escape(param
);
412 new Ajax
.Request("backend.php", {
414 onComplete: function (transport
) {
415 infobox_callback2(transport
);
416 if (callback
) callback(transport
);
422 function infobox_callback2(transport
) {
426 if (dijit
.byId("infoBox")) {
427 dialog
= dijit
.byId("infoBox");
430 //console.log("infobox_callback2");
434 var dtitle
= "Dialog";
436 var dlg
= transport
.responseXML
.getElementsByTagName("dlg")[0];
438 var title
= transport
.responseXML
.getElementsByTagName("title")[0];
440 title
= title
.firstChild
.nodeValue
;
442 var content
= transport
.responseXML
.getElementsByTagName("content")[0];
444 content
= content
.firstChild
.nodeValue
;
447 dialog
= new dijit
.Dialog({
450 style
: "width: 600px",
451 onCancel: function() {
454 onExecute: function() {
457 onClose: function() {
462 dialog
.attr('title', title
);
463 dialog
.attr('content', content
);
470 exception_error("infobox_callback2", e
);
474 function filterCR(e
, f
)
479 key
= window
.event
.keyCode
; //IE
481 key
= e
.which
; //firefox
484 if (typeof f
!= 'undefined') {
495 function getInitParam(key
) {
496 return init_params
[key
];
499 function setInitParam(key
, value
) {
500 init_params
[key
] = value
;
503 function fatalError(code
, msg
, ext_info
) {
507 window
.location
.href
= "tt-rss.php";
508 } else if (code
== 5) {
509 window
.location
.href
= "db-updater.php";
512 if (msg
== "") msg
= "Unknown error";
515 if (ext_info
.responseText
) {
516 ext_info
= ext_info
.responseText
;
520 if (ERRORS
&& ERRORS
[code
] && !msg
) {
524 var content
= "<div><b>Error code:</b> " + code
+ "</div>" +
525 "<p>" + msg
+ "</p>";
528 content
= content
+ "<div><b>Additional information:</b></div>" +
529 "<textarea style='width: 100%' readonly=\"1\">" +
530 ext_info
+ "</textarea>";
533 var dialog
= new dijit
.Dialog({
534 title
: "Fatal error",
535 style
: "width: 600px",
545 exception_error("fatalError", e
);
549 function filterDlgCheckType(sender
) {
553 var ftype
= sender
.value
;
555 // if selected filter type is 5 (Date) enable the modifier dropbox
557 Element
.show("filterDlg_dateModBox");
558 Element
.show("filterDlg_dateChkBox");
560 Element
.hide("filterDlg_dateModBox");
561 Element
.hide("filterDlg_dateChkBox");
566 exception_error("filterDlgCheckType", e
);
571 function filterDlgCheckAction(sender
) {
575 var action
= sender
.value
;
577 var action_param
= $("filterDlg_paramBox");
580 console
.log("filterDlgCheckAction: can't find action param box!");
584 // if selected action supports parameters, enable params field
585 if (action
== 4 || action
== 6 || action
== 7) {
586 new Effect
.Appear(action_param
, {duration
: 0.5});
588 Element
.show(dijit
.byId("filterDlg_actionParam").domNode
);
589 Element
.hide(dijit
.byId("filterDlg_actionParamLabel").domNode
);
591 Element
.show(dijit
.byId("filterDlg_actionParamLabel").domNode
);
592 Element
.hide(dijit
.byId("filterDlg_actionParam").domNode
);
595 Element
.hide(action_param
);
599 exception_error("filterDlgCheckAction", e
);
604 function filterDlgCheckDate() {
606 var dialog
= dijit
.byId("filterEditDlg");
608 var reg_exp
= dialog
.attr('value').reg_exp
;
610 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
612 new Ajax
.Request("backend.php", {
614 onComplete: function(transport
) {
616 var reply
= JSON
.parse(transport
.responseText
);
618 if (reply
['result'] == true) {
619 alert(__("Date syntax appears to be correct."));
622 alert(__("Date syntax is incorrect."));
629 exception_error("filterDlgCheckDate", e
);
633 function explainError(code
) {
634 return displayDlg("explainError", code
);
637 function displayHelpInfobox(topic_id
) {
639 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
641 var w
= window
.open(url
, "ttrss_help",
642 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
646 function loading_set_progress(p
) {
648 loading_progress
+= p
;
650 if (dijit
.byId("loading_bar"))
651 dijit
.byId("loading_bar").update({progress
: loading_progress
});
653 if (loading_progress
>= 90)
657 exception_error("loading_set_progress", e
);
661 function remove_splash() {
663 if (Element
.visible("overlay")) {
664 console
.log("about to remove splash, OMG!");
665 Element
.hide("overlay");
666 console
.log("removed splash!");
670 function transport_error_check(transport
) {
672 if (transport
.responseXML
) {
673 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
676 var code
= error
.getAttribute("error-code");
677 var msg
= error
.getAttribute("error-msg");
679 fatalError(code
, msg
);
685 exception_error("check_for_error_xml", e
);
690 function strip_tags(s
) {
691 return s
.replace(/<\/?[^>]+(>|$)/g, "");
694 function truncate_string(s
, length
) {
695 if (!length
) length
= 30;
696 var tmp
= s
.substring(0, length
);
697 if (s
.length
> length
) tmp
+= "…";
701 function hotkey_prefix_timeout() {
704 var date
= new Date();
705 var ts
= Math
.round(date
.getTime() / 1000);
707 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
708 console
.log("hotkey_prefix seems to be stuck, aborting");
709 hotkey_prefix_pressed
= false;
710 hotkey_prefix
= false;
711 Element
.hide('cmdline');
714 setTimeout("hotkey_prefix_timeout()", 1000);
717 exception_error("hotkey_prefix_timeout", e
);
721 function hideAuxDlg() {
723 Element
.hide('auxDlg');
725 exception_error("hideAuxDlg", e
);
730 function uploadIconHandler(rc
) {
734 notify_info("Upload complete.");
735 if (inPreferences()) {
738 setTimeout('updateFeedList(false, false)', 50);
742 notify_error("Upload failed: icon is too big.");
745 notify_error("Upload failed.");
750 exception_error("uploadIconHandler", e
);
754 function removeFeedIcon(id
) {
758 if (confirm(__("Remove stored feed icon?"))) {
759 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
763 notify_progress("Removing feed icon...", true);
765 new Ajax
.Request("backend.php", {
767 onComplete: function(transport
) {
768 notify_info("Feed icon removed.");
769 if (inPreferences()) {
772 setTimeout('updateFeedList(false, false)', 50);
779 exception_error("uploadFeedIcon", e
);
783 function uploadFeedIcon() {
787 var file
= $("icon_file");
789 if (file
.value
.length
== 0) {
790 alert(__("Please select an image file to upload."));
792 if (confirm(__("Upload new icon for this feed?"))) {
793 notify_progress("Uploading, please wait...", true);
801 exception_error("uploadFeedIcon", e
);
805 function addLabel(select
, callback
) {
809 var caption
= prompt(__("Please enter label caption:"), "");
811 if (caption
!= undefined) {
814 alert(__("Can't create label: missing caption."));
818 var query
= "?op=pref-labels&subop=add&caption=" +
819 param_escape(caption
);
822 query
+= "&output=select";
824 notify_progress("Loading, please wait...", true);
826 if (inPreferences() && !select
) active_tab
= "labelConfig";
828 new Ajax
.Request("backend.php", {
830 onComplete: function(transport
) {
833 } else if (inPreferences()) {
843 exception_error("addLabel", e
);
847 function quickAddFeed() {
849 var query
= "backend.php?op=dlg&id=quickAddFeed";
851 if (dijit
.byId("feedAddDlg"))
852 dijit
.byId("feedAddDlg").destroyRecursive();
854 var dialog
= new dijit
.Dialog({
856 title
: __("Subscribe to Feed"),
857 style
: "width: 600px",
858 execute: function() {
859 if (this.validate()) {
860 console
.log(dojo
.objectToQuery(this.attr('value')));
862 var feed_url
= this.attr('value').feed
;
864 notify_progress(__("Subscribing to feed..."), true);
866 new Ajax
.Request("backend.php", {
867 parameters
: dojo
.objectToQuery(this.attr('value')),
868 onComplete: function(transport
) {
871 var reply
= JSON
.parse(transport
.responseText
);
873 var rc
= parseInt(reply
['result']);
877 console
.log("GOT RC: " + rc
);
882 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
887 alert(__("Specified URL seems to be invalid."));
890 alert(__("Specified URL doesn't seem to contain any feeds."));
893 notify_progress("Searching for feed urls...", true);
895 new Ajax
.Request("backend.php", {
896 parameters
: 'op=rpc&subop=extractfeedurls&url=' + param_escape(feed_url
),
897 onComplete: function(transport
, dialog
, feed_url
) {
901 var reply
= JSON
.parse(transport
.responseText
);
903 var feeds
= reply
['urls'];
905 console
.log(transport
.responseText
);
907 var select
= dijit
.byId("feedDlg_feedContainerSelect");
909 while (select
.getOptions().length
> 0)
910 select
.removeOption(0);
913 for (var feedUrl
in feeds
) {
914 select
.addOption({value
: feedUrl
, label
: feeds
[feedUrl
]});
918 // if (count > 5) count = 5;
919 // select.size = count;
921 Effect
.Appear('feedDlg_feedsContainer', {duration
: 0.5});
926 alert(__("Couldn't download the specified URL."));
929 alert(__("You are already subscribed to this feed."));
934 exception_error("subscribeToFeed", e
);
945 exception_error("quickAddFeed", e
);
949 function quickAddFilter() {
951 var query
= "backend.php?op=dlg&id=quickAddFilter";
953 if (dijit
.byId("filterEditDlg"))
954 dijit
.byId("filterEditDlg").destroyRecursive();
956 dialog
= new dijit
.Dialog({
958 title
: __("Create Filter"),
959 style
: "width: 600px",
960 execute: function() {
961 if (this.validate()) {
963 var query
= "?op=rpc&subop=verifyRegexp®_exp=" +
964 param_escape(dialog
.attr('value').reg_exp
);
966 notify_progress("Verifying regular expression...");
968 new Ajax
.Request("backend.php", {
970 onComplete: function(transport
) {
971 var reply
= JSON
.parse(transport
.responseText
);
976 if (!reply
['status']) {
977 alert("Match regular expression seems to be invalid.");
980 notify_progress("Saving data...", true);
982 console
.log(dojo
.objectToQuery(dialog
.attr('value')));
984 new Ajax
.Request("backend.php", {
985 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
986 onComplete: function(transport
) {
988 notify_info(transport
.responseText
);
989 if (inPreferences()) {
1002 exception_error("quickAddFilter", e
);
1006 function unsubscribeFeed(feed_id
, title
) {
1008 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1010 if (title
== undefined || confirm(msg
)) {
1011 notify_progress("Removing feed...");
1013 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
1015 new Ajax
.Request("backend.php", {
1017 onComplete: function(transport
) {
1019 if (dijit
.byId("feedEditDlg")) dijit
.byId("feedEditDlg").hide();
1021 if (inPreferences()) {
1024 if (feed_id
== getActiveFeedId())
1025 setTimeout("viewfeed(-5)", 100);
1035 function backend_sanity_check_callback(transport
) {
1039 if (sanity_check_done
) {
1040 fatalError(11, "Sanity check request received twice. This can indicate "+
1041 "presence of Firebug or some other disrupting extension. "+
1042 "Please disable it and try again.");
1046 if (!transport
.responseXML
) {
1048 fatalError(3, "Sanity check: Received reply is not XML",
1049 transport
.responseText
);
1054 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
1057 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1061 var error_code
= reply
.getAttribute("error-code");
1063 if (error_code
&& error_code
!= 0) {
1064 return fatalError(error_code
, reply
.getAttribute("error-msg"));
1067 console
.log("sanity check ok");
1069 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
1072 console
.log('reading init-params...');
1074 params
= JSON
.parse(params
.firstChild
.nodeValue
);
1079 console
.log("IP: " + k
+ " => " + v
);
1083 init_params
= params
;
1086 sanity_check_done
= true;
1088 init_second_stage();
1091 exception_error("backend_sanity_check_callback", e
, transport
);
1095 function has_local_storage() {
1097 return 'sessionStorage' in window
&& window
['sessionStorage'] != null;
1103 function catSelectOnChange(elem
) {
1105 /* var value = elem[elem.selectedIndex].value;
1106 var def = elem.getAttribute('default');
1108 if (value == "ADD_CAT") {
1111 dropboxSelect(elem, def);
1113 elem.selectedIndex = 0;
1119 exception_error("catSelectOnChange", e
);
1123 function quickAddCat(elem
) {
1125 var cat
= prompt(__("Please enter category title:"));
1129 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
1131 notify_progress("Loading, please wait...", true);
1133 new Ajax
.Request("backend.php", {
1135 onComplete: function (transport
) {
1136 var response
= transport
.responseXML
;
1137 var select
= response
.getElementsByTagName("select")[0];
1138 var options
= select
.getElementsByTagName("option");
1140 dropbox_replace_options(elem
, options
);
1149 exception_error("quickAddCat", e
);
1153 function genUrlChangeKey(feed
, is_cat
) {
1156 var ok
= confirm(__("Generate new syndication address for this feed?"));
1160 notify_progress("Trying to change address...", true);
1162 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
1163 "&is_cat=" + param_escape(is_cat
);
1165 new Ajax
.Request("backend.php", {
1167 onComplete: function(transport
) {
1168 var reply
= JSON
.parse(transport
.responseText
);
1169 var new_link
= reply
.link
;
1171 var e
= $('gen_feed_url');
1175 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1176 "&key=" + new_link
);
1178 e
.href
= e
.href
.replace(/\&key=.*$/,
1179 "&key=" + new_link
);
1181 new Effect
.Highlight(e
);
1186 notify_error("Could not change feed URL.");
1191 exception_error("genUrlChangeKey", e
);
1196 function labelSelectOnChange(elem
) {
1198 /* var value = elem[elem.selectedIndex].value;
1199 var def = elem.getAttribute('default');
1201 if (value == "ADD_LABEL") {
1204 dropboxSelect(elem, def);
1206 elem.selectedIndex = 0;
1208 addLabel(elem, function(transport) {
1212 var response = transport.responseXML;
1213 var select = response.getElementsByTagName("select")[0];
1214 var options = select.getElementsByTagName("option");
1216 dropbox_replace_options(elem, options);
1220 exception_error("addLabel", e);
1226 exception_error("labelSelectOnChange", e
);
1230 function dropbox_replace_options(elem
, options
) {
1233 while (elem
.hasChildNodes())
1234 elem
.removeChild(elem
.firstChild
);
1238 for (var i
= 0; i
< options
.length
; i
++) {
1239 var text
= options
[i
].firstChild
.nodeValue
;
1240 var value
= options
[i
].getAttribute("value");
1242 if (value
== undefined) value
= text
;
1244 var issel
= options
[i
].getAttribute("selected") == "1";
1246 var option
= new Option(text
, value
, issel
);
1248 if (options
[i
].getAttribute("disabled"))
1249 option
.setAttribute("disabled", true);
1251 elem
.insert(option
);
1253 if (issel
) sel_idx
= i
;
1256 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1257 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1260 exception_error("dropbox_replace_options", e
);
1264 // mode = all, none, invert
1265 function selectTableRows(id
, mode
) {
1267 var rows
= $(id
).rows
;
1269 for (var i
= 0; i
< rows
.length
; i
++) {
1273 if (row
.id
&& row
.className
) {
1274 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1275 var inputs
= rows
[i
].getElementsByTagName("input");
1277 for (var j
= 0; j
< inputs
.length
; j
++) {
1278 var input
= inputs
[j
];
1280 if (input
.getAttribute("type") == "checkbox" &&
1281 input
.id
.match(bare_id
)) {
1289 var issel
= row
.hasClassName("Selected");
1291 if (mode
== "all" && !issel
) {
1292 row
.addClassName("Selected");
1294 } else if (mode
== "none" && issel
) {
1295 row
.removeClassName("Selected");
1297 } else if (mode
== "invert") {
1300 row
.removeClassName("Selected");
1303 row
.addClassName("Selected");
1312 exception_error("selectTableRows", e
);
1317 function getSelectedTableRowIds(id
) {
1321 var elem_rows
= $(id
).rows
;
1323 for (i
= 0; i
< elem_rows
.length
; i
++) {
1324 if (elem_rows
[i
].hasClassName("Selected")) {
1325 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1331 exception_error("getSelectedTableRowIds", e
);
1337 function editFeed(feed
, event
) {
1340 return alert(__("You can't edit this kind of feed."));
1342 var query
= "backend.php?op=pref-feeds&subop=editfeed&id=" +
1347 if (dijit
.byId("feedEditDlg"))
1348 dijit
.byId("feedEditDlg").destroyRecursive();
1350 dialog
= new dijit
.Dialog({
1352 title
: __("Edit Feed"),
1353 style
: "width: 600px",
1354 execute: function() {
1355 if (this.validate()) {
1356 // console.log(dojo.objectToQuery(this.attr('value')));
1358 notify_progress("Saving data...", true);
1360 new Ajax
.Request("backend.php", {
1361 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
1362 onComplete: function(transport
) {
1374 exception_error("editFeed", e
);
1378 function feedBrowser() {
1380 var query
= "backend.php?op=dlg&id=feedBrowser";
1382 if (dijit
.byId("feedAddDlg"))
1383 dijit
.byId("feedAddDlg").hide();
1385 if (dijit
.byId("feedBrowserDlg"))
1386 dijit
.byId("feedBrowserDlg").destroyRecursive();
1388 var dialog
= new dijit
.Dialog({
1389 id
: "feedBrowserDlg",
1390 title
: __("More Feeds"),
1391 style
: "width: 600px",
1392 getSelectedFeeds: function() {
1393 var list
= $$("#browseFeedList li[id*=FBROW]");
1394 var selected
= new Array();
1396 list
.each(function(child
) {
1397 var id
= child
.id
.replace("FBROW-", "");
1399 if (child
.hasClassName('Selected')) {
1406 subscribe: function() {
1407 var selected
= this.getSelectedFeeds();
1408 var mode
= this.attr('value').mode
;
1410 if (selected
.length
> 0) {
1411 dijit
.byId("feedBrowserDlg").hide();
1413 notify_progress("Loading, please wait...", true);
1415 var query
= "?op=rpc&subop=massSubscribe&ids="+
1416 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1420 new Ajax
.Request("backend.php", {
1422 onComplete: function(transport
) {
1423 if (inPreferences()) {
1429 alert(__("No feeds are selected."));
1433 update: function() {
1434 var query
= dojo
.objectToQuery(dialog
.attr('value'));
1436 Element
.show('feed_browser_spinner');
1438 new Ajax
.Request("backend.php", {
1440 onComplete: function(transport
) {
1443 Element
.hide('feed_browser_spinner');
1445 var c
= $("browseFeedList");
1447 var reply
= JSON
.parse(transport
.responseText
);
1449 var r
= reply
['content'];
1450 var mode
= reply
['mode'];
1456 dojo
.parser
.parse("browseFeedList");
1459 Element
.show(dijit
.byId('feed_archive_remove').domNode
);
1461 Element
.hide(dijit
.byId('feed_archive_remove').domNode
);
1466 removeFromArchive: function() {
1467 var selected
= this.getSelectedFeeds();
1469 if (selected
.length
> 0) {
1471 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1474 Element
.show('feed_browser_spinner');
1476 var query
= "?op=rpc&subop=remarchived&ids=" +
1477 param_escape(selected
.toString());;
1479 new Ajax
.Request("backend.php", {
1481 onComplete: function(transport
) {
1487 execute: function() {
1488 if (this.validate()) {
1497 exception_error("editFeed", e
);