]>
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
) {
506 if (!ext_info
) ext_info
= "N/A";
509 window
.location
.href
= "tt-rss.php";
510 } else if (code
== 5) {
511 window
.location
.href
= "db-updater.php";
514 if (msg
== "") msg
= "Unknown error";
516 var ebc
= $("xebContent");
520 Element
.show("dialog_overlay");
521 Element
.show("errorBoxShadow");
522 Element
.hide("xebBtn");
525 if (ext_info
.responseText
) {
526 ext_info
= ext_info
.responseText
;
531 "<div><b>Error message:</b></div>" +
532 "<pre>" + msg
+ "</pre>" +
533 "<div><b>Additional information:</b></div>" +
534 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
539 exception_error("fatalError", e
);
543 function filterDlgCheckType(sender
) {
547 var ftype
= sender
.value
;
549 // if selected filter type is 5 (Date) enable the modifier dropbox
551 Element
.show("filterDlg_dateModBox");
552 Element
.show("filterDlg_dateChkBox");
554 Element
.hide("filterDlg_dateModBox");
555 Element
.hide("filterDlg_dateChkBox");
560 exception_error("filterDlgCheckType", e
);
565 function filterDlgCheckAction(sender
) {
569 var action
= sender
.value
;
571 var action_param
= $("filterDlg_paramBox");
574 console
.log("filterDlgCheckAction: can't find action param box!");
578 // if selected action supports parameters, enable params field
579 if (action
== 4 || action
== 6 || action
== 7) {
580 new Effect
.Appear(action_param
, {duration
: 0.5});
582 Element
.show(dijit
.byId("filterDlg_actionParam").domNode
);
583 Element
.hide(dijit
.byId("filterDlg_actionParamLabel").domNode
);
585 Element
.show(dijit
.byId("filterDlg_actionParamLabel").domNode
);
586 Element
.hide(dijit
.byId("filterDlg_actionParam").domNode
);
589 Element
.hide(action_param
);
593 exception_error("filterDlgCheckAction", e
);
598 function filterDlgCheckDate() {
600 var dialog
= dijit
.byId("filterEditDlg");
602 var reg_exp
= dialog
.attr('value').reg_exp
;
604 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
606 new Ajax
.Request("backend.php", {
608 onComplete: function(transport
) {
610 var reply
= JSON
.parse(transport
.responseText
);
612 if (reply
['result'] == true) {
613 alert(__("Date syntax appears to be correct."));
616 alert(__("Date syntax is incorrect."));
623 exception_error("filterDlgCheckDate", e
);
627 function explainError(code
) {
628 return displayDlg("explainError", code
);
631 function displayHelpInfobox(topic_id
) {
633 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
635 var w
= window
.open(url
, "ttrss_help",
636 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
640 function loading_set_progress(p
) {
642 loading_progress
+= p
;
644 if (dijit
.byId("loading_bar"))
645 dijit
.byId("loading_bar").update({progress
: loading_progress
});
647 if (loading_progress
>= 90)
651 exception_error("loading_set_progress", e
);
655 function remove_splash() {
657 if (Element
.visible("overlay")) {
658 console
.log("about to remove splash, OMG!");
659 Element
.hide("overlay");
660 console
.log("removed splash!");
664 function transport_error_check(transport
) {
666 if (transport
.responseXML
) {
667 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
670 var code
= error
.getAttribute("error-code");
671 var msg
= error
.getAttribute("error-msg");
673 fatalError(code
, msg
);
679 exception_error("check_for_error_xml", e
);
684 function strip_tags(s
) {
685 return s
.replace(/<\/?[^>]+(>|$)/g, "");
688 function truncate_string(s
, length
) {
689 if (!length
) length
= 30;
690 var tmp
= s
.substring(0, length
);
691 if (s
.length
> length
) tmp
+= "…";
695 function hotkey_prefix_timeout() {
698 var date
= new Date();
699 var ts
= Math
.round(date
.getTime() / 1000);
701 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
702 console
.log("hotkey_prefix seems to be stuck, aborting");
703 hotkey_prefix_pressed
= false;
704 hotkey_prefix
= false;
705 Element
.hide('cmdline');
708 setTimeout("hotkey_prefix_timeout()", 1000);
711 exception_error("hotkey_prefix_timeout", e
);
715 function hideAuxDlg() {
717 Element
.hide('auxDlg');
719 exception_error("hideAuxDlg", e
);
724 function uploadIconHandler(rc
) {
728 notify_info("Upload complete.");
729 if (inPreferences()) {
732 setTimeout('updateFeedList(false, false)', 50);
736 notify_error("Upload failed: icon is too big.");
739 notify_error("Upload failed.");
744 exception_error("uploadIconHandler", e
);
748 function removeFeedIcon(id
) {
752 if (confirm(__("Remove stored feed icon?"))) {
753 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
757 notify_progress("Removing feed icon...", true);
759 new Ajax
.Request("backend.php", {
761 onComplete: function(transport
) {
762 notify_info("Feed icon removed.");
763 if (inPreferences()) {
766 setTimeout('updateFeedList(false, false)', 50);
773 exception_error("uploadFeedIcon", e
);
777 function uploadFeedIcon() {
781 var file
= $("icon_file");
783 if (file
.value
.length
== 0) {
784 alert(__("Please select an image file to upload."));
786 if (confirm(__("Upload new icon for this feed?"))) {
787 notify_progress("Uploading, please wait...", true);
795 exception_error("uploadFeedIcon", e
);
799 function addLabel(select
, callback
) {
803 var caption
= prompt(__("Please enter label caption:"), "");
805 if (caption
!= undefined) {
808 alert(__("Can't create label: missing caption."));
812 var query
= "?op=pref-labels&subop=add&caption=" +
813 param_escape(caption
);
816 query
+= "&output=select";
818 notify_progress("Loading, please wait...", true);
820 if (inPreferences() && !select
) active_tab
= "labelConfig";
822 new Ajax
.Request("backend.php", {
824 onComplete: function(transport
) {
827 } else if (inPreferences()) {
837 exception_error("addLabel", e
);
841 function quickAddFeed() {
843 var query
= "backend.php?op=dlg&id=quickAddFeed";
845 if (dijit
.byId("feedAddDlg"))
846 dijit
.byId("feedAddDlg").destroyRecursive();
848 var dialog
= new dijit
.Dialog({
850 title
: __("Subscribe to Feed"),
851 style
: "width: 600px",
852 execute: function() {
853 if (this.validate()) {
854 console
.log(dojo
.objectToQuery(this.attr('value')));
856 var feed_url
= this.attr('value').feed
;
858 notify_progress(__("Subscribing to feed..."), true);
860 new Ajax
.Request("backend.php", {
861 parameters
: dojo
.objectToQuery(this.attr('value')),
862 onComplete: function(transport
) {
865 var reply
= JSON
.parse(transport
.responseText
);
867 var rc
= parseInt(reply
['result']);
871 console
.log("GOT RC: " + rc
);
876 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
881 alert(__("Specified URL seems to be invalid."));
884 alert(__("Specified URL doesn't seem to contain any feeds."));
887 notify_progress("Searching for feed urls...", true);
889 new Ajax
.Request("backend.php", {
890 parameters
: 'op=rpc&subop=extractfeedurls&url=' + param_escape(feed_url
),
891 onComplete: function(transport
, dialog
, feed_url
) {
895 var reply
= JSON
.parse(transport
.responseText
);
897 var feeds
= reply
['urls'];
899 console
.log(transport
.responseText
);
901 var select
= dijit
.byId("feedDlg_feedContainerSelect");
903 while (select
.getOptions().length
> 0)
904 select
.removeOption(0);
907 for (var feedUrl
in feeds
) {
908 select
.addOption({value
: feedUrl
, label
: feeds
[feedUrl
]});
912 // if (count > 5) count = 5;
913 // select.size = count;
915 Effect
.Appear('feedDlg_feedsContainer', {duration
: 0.5});
920 alert(__("Couldn't download the specified URL."));
923 alert(__("You are already subscribed to this feed."));
928 exception_error("subscribeToFeed", e
);
939 exception_error("quickAddFeed", e
);
943 function quickAddFilter() {
945 var query
= "backend.php?op=dlg&id=quickAddFilter";
947 if (dijit
.byId("filterEditDlg"))
948 dijit
.byId("filterEditDlg").destroyRecursive();
950 dialog
= new dijit
.Dialog({
952 title
: __("Create Filter"),
953 style
: "width: 600px",
954 execute: function() {
955 if (this.validate()) {
957 var query
= "?op=rpc&subop=verifyRegexp®_exp=" +
958 param_escape(dialog
.attr('value').reg_exp
);
960 notify_progress("Verifying regular expression...");
962 new Ajax
.Request("backend.php", {
964 onComplete: function(transport
) {
965 var reply
= JSON
.parse(transport
.responseText
);
970 if (!reply
['status']) {
971 alert("Match regular expression seems to be invalid.");
974 notify_progress("Saving data...", true);
976 console
.log(dojo
.objectToQuery(dialog
.attr('value')));
978 new Ajax
.Request("backend.php", {
979 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
980 onComplete: function(transport
) {
982 notify_info(transport
.responseText
);
983 if (inPreferences()) {
996 exception_error("quickAddFilter", e
);
1000 function unsubscribeFeed(feed_id
, title
) {
1002 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1004 if (title
== undefined || confirm(msg
)) {
1005 notify_progress("Removing feed...");
1007 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
1009 new Ajax
.Request("backend.php", {
1011 onComplete: function(transport
) {
1013 if (dijit
.byId("feedEditDlg")) dijit
.byId("feedEditDlg").hide();
1015 if (inPreferences()) {
1018 if (feed_id
== getActiveFeedId())
1019 setTimeout("viewfeed(-5)", 100);
1029 function backend_sanity_check_callback(transport
) {
1033 if (sanity_check_done
) {
1034 fatalError(11, "Sanity check request received twice. This can indicate "+
1035 "presence of Firebug or some other disrupting extension. "+
1036 "Please disable it and try again.");
1040 if (!transport
.responseXML
) {
1042 fatalError(3, "Sanity check: Received reply is not XML",
1043 transport
.responseText
);
1048 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
1051 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1055 var error_code
= reply
.getAttribute("error-code");
1057 if (error_code
&& error_code
!= 0) {
1058 return fatalError(error_code
, reply
.getAttribute("error-msg"));
1061 console
.log("sanity check ok");
1063 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
1066 console
.log('reading init-params...');
1068 params
= JSON
.parse(params
.firstChild
.nodeValue
);
1073 console
.log("IP: " + k
+ " => " + v
);
1077 init_params
= params
;
1080 sanity_check_done
= true;
1082 init_second_stage();
1085 exception_error("backend_sanity_check_callback", e
, transport
);
1089 function has_local_storage() {
1091 return 'sessionStorage' in window
&& window
['sessionStorage'] != null;
1097 function catSelectOnChange(elem
) {
1099 /* var value = elem[elem.selectedIndex].value;
1100 var def = elem.getAttribute('default');
1102 if (value == "ADD_CAT") {
1105 dropboxSelect(elem, def);
1107 elem.selectedIndex = 0;
1113 exception_error("catSelectOnChange", e
);
1117 function quickAddCat(elem
) {
1119 var cat
= prompt(__("Please enter category title:"));
1123 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
1125 notify_progress("Loading, please wait...", true);
1127 new Ajax
.Request("backend.php", {
1129 onComplete: function (transport
) {
1130 var response
= transport
.responseXML
;
1131 var select
= response
.getElementsByTagName("select")[0];
1132 var options
= select
.getElementsByTagName("option");
1134 dropbox_replace_options(elem
, options
);
1143 exception_error("quickAddCat", e
);
1147 function genUrlChangeKey(feed
, is_cat
) {
1150 var ok
= confirm(__("Generate new syndication address for this feed?"));
1154 notify_progress("Trying to change address...", true);
1156 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
1157 "&is_cat=" + param_escape(is_cat
);
1159 new Ajax
.Request("backend.php", {
1161 onComplete: function(transport
) {
1162 var reply
= JSON
.parse(transport
.responseText
);
1163 var new_link
= reply
.link
;
1165 var e
= $('gen_feed_url');
1169 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1170 "&key=" + new_link
);
1172 e
.href
= e
.href
.replace(/\&key=.*$/,
1173 "&key=" + new_link
);
1175 new Effect
.Highlight(e
);
1180 notify_error("Could not change feed URL.");
1185 exception_error("genUrlChangeKey", e
);
1190 function labelSelectOnChange(elem
) {
1192 /* var value = elem[elem.selectedIndex].value;
1193 var def = elem.getAttribute('default');
1195 if (value == "ADD_LABEL") {
1198 dropboxSelect(elem, def);
1200 elem.selectedIndex = 0;
1202 addLabel(elem, function(transport) {
1206 var response = transport.responseXML;
1207 var select = response.getElementsByTagName("select")[0];
1208 var options = select.getElementsByTagName("option");
1210 dropbox_replace_options(elem, options);
1214 exception_error("addLabel", e);
1220 exception_error("labelSelectOnChange", e
);
1224 function dropbox_replace_options(elem
, options
) {
1227 while (elem
.hasChildNodes())
1228 elem
.removeChild(elem
.firstChild
);
1232 for (var i
= 0; i
< options
.length
; i
++) {
1233 var text
= options
[i
].firstChild
.nodeValue
;
1234 var value
= options
[i
].getAttribute("value");
1236 if (value
== undefined) value
= text
;
1238 var issel
= options
[i
].getAttribute("selected") == "1";
1240 var option
= new Option(text
, value
, issel
);
1242 if (options
[i
].getAttribute("disabled"))
1243 option
.setAttribute("disabled", true);
1245 elem
.insert(option
);
1247 if (issel
) sel_idx
= i
;
1250 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1251 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1254 exception_error("dropbox_replace_options", e
);
1258 // mode = all, none, invert
1259 function selectTableRows(id
, mode
) {
1261 var rows
= $(id
).rows
;
1263 for (var i
= 0; i
< rows
.length
; i
++) {
1267 if (row
.id
&& row
.className
) {
1268 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1269 var inputs
= rows
[i
].getElementsByTagName("input");
1271 for (var j
= 0; j
< inputs
.length
; j
++) {
1272 var input
= inputs
[j
];
1274 if (input
.getAttribute("type") == "checkbox" &&
1275 input
.id
.match(bare_id
)) {
1283 var issel
= row
.hasClassName("Selected");
1285 if (mode
== "all" && !issel
) {
1286 row
.addClassName("Selected");
1288 } else if (mode
== "none" && issel
) {
1289 row
.removeClassName("Selected");
1291 } else if (mode
== "invert") {
1294 row
.removeClassName("Selected");
1297 row
.addClassName("Selected");
1306 exception_error("selectTableRows", e
);
1311 function getSelectedTableRowIds(id
) {
1315 var elem_rows
= $(id
).rows
;
1317 for (i
= 0; i
< elem_rows
.length
; i
++) {
1318 if (elem_rows
[i
].hasClassName("Selected")) {
1319 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1325 exception_error("getSelectedTableRowIds", e
);
1331 function editFeed(feed
, event
) {
1334 return alert(__("You can't edit this kind of feed."));
1336 var query
= "backend.php?op=pref-feeds&subop=editfeed&id=" +
1341 if (dijit
.byId("feedEditDlg"))
1342 dijit
.byId("feedEditDlg").destroyRecursive();
1344 dialog
= new dijit
.Dialog({
1346 title
: __("Edit Feed"),
1347 style
: "width: 600px",
1348 execute: function() {
1349 if (this.validate()) {
1350 // console.log(dojo.objectToQuery(this.attr('value')));
1352 notify_progress("Saving data...", true);
1354 new Ajax
.Request("backend.php", {
1355 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
1356 onComplete: function(transport
) {
1367 exception_error("editFeed", e
);
1371 function feedBrowser() {
1373 var query
= "backend.php?op=dlg&id=feedBrowser";
1375 if (dijit
.byId("feedAddDlg"))
1376 dijit
.byId("feedAddDlg").hide();
1378 if (dijit
.byId("feedBrowserDlg"))
1379 dijit
.byId("feedBrowserDlg").destroyRecursive();
1381 var dialog
= new dijit
.Dialog({
1382 id
: "feedBrowserDlg",
1383 title
: __("More Feeds"),
1384 style
: "width: 600px",
1385 getSelectedFeeds: function() {
1386 var list
= $$("#browseFeedList li[id*=FBROW]");
1387 var selected
= new Array();
1389 list
.each(function(child
) {
1390 var id
= child
.id
.replace("FBROW-", "");
1392 if (child
.hasClassName('Selected')) {
1399 subscribe: function() {
1400 var selected
= this.getSelectedFeeds();
1401 var mode
= this.attr('value').mode
;
1403 if (selected
.length
> 0) {
1404 dijit
.byId("feedBrowserDlg").hide();
1406 notify_progress("Loading, please wait...", true);
1408 var query
= "?op=rpc&subop=massSubscribe&ids="+
1409 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1413 new Ajax
.Request("backend.php", {
1415 onComplete: function(transport
) {
1416 if (inPreferences()) {
1422 alert(__("No feeds are selected."));
1426 update: function() {
1427 var query
= dojo
.objectToQuery(dialog
.attr('value'));
1429 Element
.show('feed_browser_spinner');
1431 new Ajax
.Request("backend.php", {
1433 onComplete: function(transport
) {
1436 Element
.hide('feed_browser_spinner');
1438 var c
= $("browseFeedList");
1440 var reply
= JSON
.parse(transport
.responseText
);
1442 var r
= reply
['content'];
1443 var mode
= reply
['mode'];
1449 dojo
.parser
.parse("browseFeedList");
1452 Element
.show(dijit
.byId('feed_archive_remove').domNode
);
1454 Element
.hide(dijit
.byId('feed_archive_remove').domNode
);
1459 removeFromArchive: function() {
1460 var selected
= this.getSelectedFeeds();
1462 if (selected
.length
> 0) {
1464 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1467 Element
.show('feed_browser_spinner');
1469 var query
= "?op=rpc&subop=remarchived&ids=" +
1470 param_escape(selected
.toString());;
1472 new Ajax
.Request("backend.php", {
1474 onComplete: function(transport
) {
1480 execute: function() {
1481 if (this.validate()) {
1490 exception_error("editFeed", e
);