]>
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_submit_callback2(transport
) {
426 // called from prefs, reload tab
427 if (typeof active_tab
!= 'undefined' && active_tab
) {
428 selectTab(active_tab
, false);
432 if (transport
.responseText
) {
433 notify_info(transport
.responseText
);
437 function infobox_callback2(transport
) {
441 if (dijit
.byId("infoBox")) {
442 dialog
= dijit
.byId("infoBox");
445 //console.log("infobox_callback2");
449 var dtitle
= "Dialog";
451 var dlg
= transport
.responseXML
.getElementsByTagName("dlg")[0];
453 var title
= transport
.responseXML
.getElementsByTagName("title")[0];
455 title
= title
.firstChild
.nodeValue
;
457 var content
= transport
.responseXML
.getElementsByTagName("content")[0];
459 content
= content
.firstChild
.nodeValue
;
462 dialog
= new dijit
.Dialog({
465 style
: "width: 600px",
466 onCancel: function() {
469 onExecute: function() {
472 onClose: function() {
477 dialog
.attr('title', title
);
478 dialog
.attr('content', content
);
485 exception_error("infobox_callback2", e
);
489 function filterCR(e
, f
)
494 key
= window
.event
.keyCode
; //IE
496 key
= e
.which
; //firefox
499 if (typeof f
!= 'undefined') {
510 function getInitParam(key
) {
511 return init_params
[key
];
514 function setInitParam(key
, value
) {
515 init_params
[key
] = value
;
518 function fatalError(code
, msg
, ext_info
) {
521 if (!ext_info
) ext_info
= "N/A";
524 window
.location
.href
= "tt-rss.php";
525 } else if (code
== 5) {
526 window
.location
.href
= "db-updater.php";
529 if (msg
== "") msg
= "Unknown error";
531 var ebc
= $("xebContent");
535 Element
.show("dialog_overlay");
536 Element
.show("errorBoxShadow");
537 Element
.hide("xebBtn");
540 if (ext_info
.responseText
) {
541 ext_info
= ext_info
.responseText
;
546 "<div><b>Error message:</b></div>" +
547 "<pre>" + msg
+ "</pre>" +
548 "<div><b>Additional information:</b></div>" +
549 "<textarea readonly=\"1\">" + ext_info
+ "</textarea>";
554 exception_error("fatalError", e
);
558 function filterDlgCheckType(sender
) {
562 var ftype
= sender
.value
;
564 // if selected filter type is 5 (Date) enable the modifier dropbox
566 Element
.show("filterDlg_dateModBox");
567 Element
.show("filterDlg_dateChkBox");
569 Element
.hide("filterDlg_dateModBox");
570 Element
.hide("filterDlg_dateChkBox");
575 exception_error("filterDlgCheckType", e
);
580 function filterDlgCheckAction(sender
) {
584 var action
= sender
.value
;
586 var action_param
= $("filterDlg_paramBox");
589 console
.log("filterDlgCheckAction: can't find action param box!");
593 // if selected action supports parameters, enable params field
594 if (action
== 4 || action
== 6 || action
== 7) {
595 new Effect
.Appear(action_param
, {duration
: 0.5});
597 Element
.show(dijit
.byId("filterDlg_actionParam").domNode
);
598 Element
.hide(dijit
.byId("filterDlg_actionParamLabel").domNode
);
600 Element
.show(dijit
.byId("filterDlg_actionParamLabel").domNode
);
601 Element
.hide(dijit
.byId("filterDlg_actionParam").domNode
);
604 Element
.hide(action_param
);
608 exception_error("filterDlgCheckAction", e
);
613 function filterDlgCheckDate() {
615 var dialog
= dijit
.byId("filterEditDlg");
617 var reg_exp
= dialog
.attr('value').reg_exp
;
619 var query
= "?op=rpc&subop=checkDate&date=" + reg_exp
;
621 new Ajax
.Request("backend.php", {
623 onComplete: function(transport
) {
625 if (transport
.responseXML
) {
626 var result
= transport
.responseXML
.getElementsByTagName("result")[0];
628 if (result
&& result
.firstChild
) {
629 if (result
.firstChild
.nodeValue
== "1") {
630 alert(__("Date syntax appears to be correct."));
636 alert(__("Date syntax is incorrect."));
642 exception_error("filterDlgCheckDate", e
);
646 function explainError(code
) {
647 return displayDlg("explainError", code
);
650 function displayHelpInfobox(topic_id
) {
652 var url
= "backend.php?op=help&tid=" + param_escape(topic_id
);
654 var w
= window
.open(url
, "ttrss_help",
655 "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0");
659 function loading_set_progress(p
) {
661 loading_progress
+= p
;
663 if (dijit
.byId("loading_bar"))
664 dijit
.byId("loading_bar").update({progress
: loading_progress
});
666 if (loading_progress
>= 90)
670 exception_error("loading_set_progress", e
);
674 function remove_splash() {
676 if (Element
.visible("overlay")) {
677 console
.log("about to remove splash, OMG!");
678 Element
.hide("overlay");
679 console
.log("removed splash!");
683 /* function getSelectedFeedsFromBrowser() {
685 var list = $$("#browseFeedList li[id*=FBROW]");
687 var selected = new Array();
689 list.each(function(child) {
690 var id = child.id.replace("FBROW-", "");
692 if (child.hasClassName('Selected')) {
701 function transport_error_check(transport
) {
703 if (transport
.responseXML
) {
704 var error
= transport
.responseXML
.getElementsByTagName("error")[0];
707 var code
= error
.getAttribute("error-code");
708 var msg
= error
.getAttribute("error-msg");
710 fatalError(code
, msg
);
716 exception_error("check_for_error_xml", e
);
721 function strip_tags(s
) {
722 return s
.replace(/<\/?[^>]+(>|$)/g, "");
725 function truncate_string(s
, length
) {
726 if (!length
) length
= 30;
727 var tmp
= s
.substring(0, length
);
728 if (s
.length
> length
) tmp
+= "…";
732 function hotkey_prefix_timeout() {
735 var date
= new Date();
736 var ts
= Math
.round(date
.getTime() / 1000);
738 if (hotkey_prefix_pressed
&& ts
- hotkey_prefix_pressed
>= 5) {
739 console
.log("hotkey_prefix seems to be stuck, aborting");
740 hotkey_prefix_pressed
= false;
741 hotkey_prefix
= false;
742 Element
.hide('cmdline');
745 setTimeout("hotkey_prefix_timeout()", 1000);
748 exception_error("hotkey_prefix_timeout", e
);
752 function hideAuxDlg() {
754 Element
.hide('auxDlg');
756 exception_error("hideAuxDlg", e
);
761 function uploadIconHandler(rc
) {
765 notify_info("Upload complete.");
766 if (inPreferences()) {
769 setTimeout('updateFeedList(false, false)', 50);
773 notify_error("Upload failed: icon is too big.");
776 notify_error("Upload failed.");
781 exception_error("uploadIconHandler", e
);
785 function removeFeedIcon(id
) {
789 if (confirm(__("Remove stored feed icon?"))) {
790 var query
= "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id
);
794 notify_progress("Removing feed icon...", true);
796 new Ajax
.Request("backend.php", {
798 onComplete: function(transport
) {
799 notify_info("Feed icon removed.");
800 if (inPreferences()) {
803 setTimeout('updateFeedList(false, false)', 50);
810 exception_error("uploadFeedIcon", e
);
814 function uploadFeedIcon() {
818 var file
= $("icon_file");
820 if (file
.value
.length
== 0) {
821 alert(__("Please select an image file to upload."));
823 if (confirm(__("Upload new icon for this feed?"))) {
824 notify_progress("Uploading, please wait...", true);
832 exception_error("uploadFeedIcon", e
);
836 function addLabel(select
, callback
) {
840 var caption
= prompt(__("Please enter label caption:"), "");
842 if (caption
!= undefined) {
845 alert(__("Can't create label: missing caption."));
849 var query
= "?op=pref-labels&subop=add&caption=" +
850 param_escape(caption
);
853 query
+= "&output=select";
855 notify_progress("Loading, please wait...", true);
857 if (inPreferences() && !select
) active_tab
= "labelConfig";
859 new Ajax
.Request("backend.php", {
861 onComplete: function(transport
) {
864 } else if (inPreferences()) {
865 infobox_submit_callback2(transport
);
874 exception_error("addLabel", e
);
878 function quickAddFeed() {
880 var query
= "backend.php?op=dlg&id=quickAddFeed";
882 if (dijit
.byId("feedAddDlg"))
883 dijit
.byId("feedAddDlg").destroyRecursive();
885 var dialog
= new dijit
.Dialog({
887 title
: __("Subscribe to Feed"),
888 style
: "width: 600px",
889 execute: function() {
890 if (this.validate()) {
891 console
.log(dojo
.objectToQuery(this.attr('value')));
893 var feed_url
= this.attr('value').feed
;
895 notify_progress(__("Subscribing to feed..."), true);
897 new Ajax
.Request("backend.php", {
898 parameters
: dojo
.objectToQuery(this.attr('value')),
899 onComplete: function(transport
) {
902 if (!transport
.responseXML
) {
903 console
.log(transport
.responseText
);
904 alert(__("Server error while trying to subscribe to specified feed."));
908 var result
= transport
.responseXML
.getElementsByTagName('result')[0];
909 var rc
= parseInt(result
.getAttribute('code'));
913 console
.log("GOT RC: " + rc
);
918 notify_info(__("Subscribed to %s").replace("%s", feed_url
));
920 if (inPreferences()) {
923 setTimeout('updateFeedList(false, false)', 50);
927 alert(__("Specified URL seems to be invalid."));
930 alert(__("Specified URL doesn't seem to contain any feeds."));
933 notify_progress("Searching for feed urls...", true);
935 new Ajax
.Request("backend.php", {
936 parameters
: 'op=rpc&subop=extractfeedurls&url=' + param_escape(feed_url
),
937 onComplete: function(transport
, dialog
, feed_url
) {
939 if (!transport
.responseXML
) {
940 console
.log(transport
.responseText
);
941 alert(__("Server error while trying to query feed URLs."));
947 var result
= transport
.responseXML
.getElementsByTagName('urls')[0];
948 var feeds
= JSON
.parse(result
.firstChild
.nodeValue
);
950 console
.log(transport
.responseText
);
952 var select
= dijit
.byId("feedDlg_feedContainerSelect");
954 while (select
.getOptions().length
> 0)
955 select
.removeOption(0);
958 for (var feedUrl
in feeds
) {
959 select
.addOption({value
: feedUrl
, label
: feeds
[feedUrl
]});
963 // if (count > 5) count = 5;
964 // select.size = count;
966 Effect
.Appear('feedDlg_feedsContainer', {duration
: 0.5});
971 alert(__("Couldn't download the specified URL."));
974 alert(__("You are already subscribed to this feed."));
979 exception_error("subscribeToFeed", e
);
990 exception_error("quickAddFeed", e
);
994 function quickAddFilter() {
996 var query
= "backend.php?op=dlg&id=quickAddFilter";
998 if (dijit
.byId("filterEditDlg"))
999 dijit
.byId("filterEditDlg").destroyRecursive();
1001 dialog
= new dijit
.Dialog({
1002 id
: "filterEditDlg",
1003 title
: __("Create Filter"),
1004 style
: "width: 600px",
1005 execute: function() {
1006 if (this.validate()) {
1008 var query
= "?op=rpc&subop=verifyRegexp®_exp=" +
1009 param_escape(dialog
.attr('value').reg_exp
);
1011 notify_progress("Verifying regular expression...");
1013 new Ajax
.Request("backend.php", {
1015 onComplete: function(transport
) {
1016 handle_rpc_reply(transport
);
1017 var response
= transport
.responseXML
;
1020 var s
= response
.getElementsByTagName("status")[0].firstChild
.nodeValue
;
1024 if (s
== "INVALID") {
1025 alert("Match regular expression seems to be invalid.");
1028 notify_progress("Saving data...", true);
1030 console
.log(dojo
.objectToQuery(dialog
.attr('value')));
1032 new Ajax
.Request("backend.php", {
1033 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
1034 onComplete: function(transport
) {
1036 notify_info(transport
.responseText
);
1037 if (inPreferences()) {
1050 exception_error("quickAddFilter", e
);
1054 function unsubscribeFeed(feed_id
, title
) {
1056 var msg
= __("Unsubscribe from %s?").replace("%s", title
);
1058 if (title
== undefined || confirm(msg
)) {
1059 notify_progress("Removing feed...");
1061 var query
= "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
;
1063 new Ajax
.Request("backend.php", {
1065 onComplete: function(transport
) {
1067 if (dijit
.byId("feedEditDlg")) dijit
.byId("feedEditDlg").hide();
1069 if (inPreferences()) {
1072 if (feed_id
== getActiveFeedId())
1073 setTimeout("viewfeed(-5)", 100);
1083 function backend_sanity_check_callback(transport
) {
1087 if (sanity_check_done
) {
1088 fatalError(11, "Sanity check request received twice. This can indicate "+
1089 "presence of Firebug or some other disrupting extension. "+
1090 "Please disable it and try again.");
1094 if (!transport
.responseXML
) {
1096 fatalError(3, "Sanity check: Received reply is not XML",
1097 transport
.responseText
);
1102 var reply
= transport
.responseXML
.getElementsByTagName("error")[0];
1105 fatalError(3, "Sanity check: invalid RPC reply", transport
.responseText
);
1109 var error_code
= reply
.getAttribute("error-code");
1111 if (error_code
&& error_code
!= 0) {
1112 return fatalError(error_code
, reply
.getAttribute("error-msg"));
1115 console
.log("sanity check ok");
1117 var params
= transport
.responseXML
.getElementsByTagName("init-params")[0];
1120 console
.log('reading init-params...');
1122 params
= JSON
.parse(params
.firstChild
.nodeValue
);
1127 console
.log("IP: " + k
+ " => " + v
);
1131 init_params
= params
;
1134 sanity_check_done
= true;
1136 init_second_stage();
1139 exception_error("backend_sanity_check_callback", e
, transport
);
1143 function has_local_storage() {
1145 return 'sessionStorage' in window
&& window
['sessionStorage'] != null;
1151 function catSelectOnChange(elem
) {
1153 /* var value = elem[elem.selectedIndex].value;
1154 var def = elem.getAttribute('default');
1156 if (value == "ADD_CAT") {
1159 dropboxSelect(elem, def);
1161 elem.selectedIndex = 0;
1167 exception_error("catSelectOnChange", e
);
1171 function quickAddCat(elem
) {
1173 var cat
= prompt(__("Please enter category title:"));
1177 var query
= "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat
);
1179 notify_progress("Loading, please wait...", true);
1181 new Ajax
.Request("backend.php", {
1183 onComplete: function (transport
) {
1184 var response
= transport
.responseXML
;
1185 var select
= response
.getElementsByTagName("select")[0];
1186 var options
= select
.getElementsByTagName("option");
1188 dropbox_replace_options(elem
, options
);
1197 exception_error("quickAddCat", e
);
1201 function genUrlChangeKey(feed
, is_cat
) {
1204 var ok
= confirm(__("Generate new syndication address for this feed?"));
1208 notify_progress("Trying to change address...", true);
1210 var query
= "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed
) +
1211 "&is_cat=" + param_escape(is_cat
);
1213 new Ajax
.Request("backend.php", {
1215 onComplete: function(transport
) {
1216 var new_link
= transport
.responseXML
.getElementsByTagName("link")[0];
1218 var e
= $('gen_feed_url');
1222 new_link
= new_link
.firstChild
.nodeValue
;
1224 e
.innerHTML
= e
.innerHTML
.replace(/\&key=.*$/,
1225 "&key=" + new_link
);
1227 e
.href
= e
.href
.replace(/\&key=.*$/,
1228 "&key=" + new_link
);
1230 new Effect
.Highlight(e
);
1235 notify_error("Could not change feed URL.");
1240 exception_error("genUrlChangeKey", e
);
1245 function labelSelectOnChange(elem
) {
1247 /* var value = elem[elem.selectedIndex].value;
1248 var def = elem.getAttribute('default');
1250 if (value == "ADD_LABEL") {
1253 dropboxSelect(elem, def);
1255 elem.selectedIndex = 0;
1257 addLabel(elem, function(transport) {
1261 var response = transport.responseXML;
1262 var select = response.getElementsByTagName("select")[0];
1263 var options = select.getElementsByTagName("option");
1265 dropbox_replace_options(elem, options);
1269 exception_error("addLabel", e);
1275 exception_error("labelSelectOnChange", e
);
1279 function dropbox_replace_options(elem
, options
) {
1282 while (elem
.hasChildNodes())
1283 elem
.removeChild(elem
.firstChild
);
1287 for (var i
= 0; i
< options
.length
; i
++) {
1288 var text
= options
[i
].firstChild
.nodeValue
;
1289 var value
= options
[i
].getAttribute("value");
1291 if (value
== undefined) value
= text
;
1293 var issel
= options
[i
].getAttribute("selected") == "1";
1295 var option
= new Option(text
, value
, issel
);
1297 if (options
[i
].getAttribute("disabled"))
1298 option
.setAttribute("disabled", true);
1300 elem
.insert(option
);
1302 if (issel
) sel_idx
= i
;
1305 // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
1306 if (sel_idx
>= 0) elem
.selectedIndex
= sel_idx
;
1309 exception_error("dropbox_replace_options", e
);
1313 // mode = all, none, invert
1314 function selectTableRows(id
, mode
) {
1316 var rows
= $(id
).rows
;
1318 for (var i
= 0; i
< rows
.length
; i
++) {
1322 if (row
.id
&& row
.className
) {
1323 var bare_id
= row
.id
.replace(/^[A-Z]*?-/, "");
1324 var inputs
= rows
[i
].getElementsByTagName("input");
1326 for (var j
= 0; j
< inputs
.length
; j
++) {
1327 var input
= inputs
[j
];
1329 if (input
.getAttribute("type") == "checkbox" &&
1330 input
.id
.match(bare_id
)) {
1338 var issel
= row
.hasClassName("Selected");
1340 if (mode
== "all" && !issel
) {
1341 row
.addClassName("Selected");
1343 } else if (mode
== "none" && issel
) {
1344 row
.removeClassName("Selected");
1346 } else if (mode
== "invert") {
1349 row
.removeClassName("Selected");
1352 row
.addClassName("Selected");
1361 exception_error("selectTableRows", e
);
1366 function getSelectedTableRowIds(id
) {
1370 var elem_rows
= $(id
).rows
;
1372 for (i
= 0; i
< elem_rows
.length
; i
++) {
1373 if (elem_rows
[i
].hasClassName("Selected")) {
1374 var bare_id
= elem_rows
[i
].id
.replace(/^[A-Z]*?-/, "");
1380 exception_error("getSelectedTableRowIds", e
);
1386 function editFeed(feed
, event
) {
1389 return alert(__("You can't edit this kind of feed."));
1391 var query
= "backend.php?op=pref-feeds&subop=editfeed&id=" +
1396 if (dijit
.byId("feedEditDlg"))
1397 dijit
.byId("feedEditDlg").destroyRecursive();
1399 dialog
= new dijit
.Dialog({
1401 title
: __("Edit Feed"),
1402 style
: "width: 600px",
1403 execute: function() {
1404 if (this.validate()) {
1405 // console.log(dojo.objectToQuery(this.attr('value')));
1407 notify_progress("Saving data...", true);
1409 new Ajax
.Request("backend.php", {
1410 parameters
: dojo
.objectToQuery(dialog
.attr('value')),
1411 onComplete: function(transport
) {
1422 exception_error("editFeed", e
);
1426 function feedBrowser() {
1428 var query
= "backend.php?op=dlg&id=feedBrowser";
1430 if (dijit
.byId("feedAddDlg"))
1431 dijit
.byId("feedAddDlg").hide();
1433 if (dijit
.byId("feedBrowserDlg"))
1434 dijit
.byId("feedBrowserDlg").destroyRecursive();
1436 var dialog
= new dijit
.Dialog({
1437 id
: "feedBrowserDlg",
1438 title
: __("More Feeds"),
1439 style
: "width: 600px",
1440 getSelectedFeeds: function() {
1441 var list
= $$("#browseFeedList li[id*=FBROW]");
1442 var selected
= new Array();
1444 list
.each(function(child
) {
1445 var id
= child
.id
.replace("FBROW-", "");
1447 if (child
.hasClassName('Selected')) {
1454 subscribe: function() {
1455 var selected
= this.getSelectedFeeds();
1456 var mode
= this.attr('value').mode
;
1458 if (selected
.length
> 0) {
1459 dijit
.byId("feedBrowserDlg").hide();
1461 notify_progress("Loading, please wait...", true);
1463 var query
= "?op=rpc&subop=massSubscribe&ids="+
1464 param_escape(selected
.toString()) + "&mode=" + param_escape(mode
);
1468 new Ajax
.Request("backend.php", {
1470 onComplete: function(transport
) {
1472 var nf
= transport
.responseXML
.getElementsByTagName('num-feeds')[0];
1473 var nf_value
= nf
.getAttribute("value");
1475 notify_info(__("Subscribed to %d feed(s).").replace("%d", nf_value
));
1477 if (inPreferences()) {
1483 alert(__("No feeds are selected."));
1487 update: function() {
1488 var query
= dojo
.objectToQuery(dialog
.attr('value'));
1490 Element
.show('feed_browser_spinner');
1492 new Ajax
.Request("backend.php", {
1494 onComplete: function(transport
) {
1497 Element
.hide('feed_browser_spinner');
1499 var c
= $("browseFeedList");
1500 var r
= transport
.responseXML
.getElementsByTagName("content")[0];
1501 var nr
= transport
.responseXML
.getElementsByTagName("num-results")[0];
1502 var mode
= transport
.responseXML
.getElementsByTagName("mode")[0];
1505 c
.innerHTML
= r
.firstChild
.nodeValue
;
1508 dojo
.parser
.parse("browseFeedList");
1510 if (parseInt(mode
.getAttribute("value")) == 2) {
1511 Element
.show(dijit
.byId('feed_archive_remove').domNode
);
1513 Element
.hide(dijit
.byId('feed_archive_remove').domNode
);
1518 removeFromArchive: function() {
1519 var selected
= this.getSelectedFeeds();
1521 if (selected
.length
> 0) {
1523 var pr
= __("Remove selected feeds from the archive? Feeds with stored articles will not be removed.");
1526 Element
.show('feed_browser_spinner');
1528 var query
= "?op=rpc&subop=remarchived&ids=" +
1529 param_escape(selected
.toString());;
1531 new Ajax
.Request("backend.php", {
1533 onComplete: function(transport
) {
1539 execute: function() {
1540 if (this.validate()) {
1549 exception_error("editFeed", e
);