PageRenderTime 64ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/templates/we1rdo/js/scripts.js

https://github.com/elstenaar86/spotweb
JavaScript | 1594 lines | 1223 code | 218 blank | 153 comment | 279 complexity | ec69f1547554f5894df13a3580c359cb MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, MPL-2.0-no-copyleft-exception, 0BSD, Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. $.address.init(function() {
  2. $('.spotlink').address();
  3. }).externalChange(
  4. function(event) {
  5. basePATH = location.href.replace('#' + $.address.value(), '');
  6. if ($.address.value() == '/' && basePATH.indexOf('/?page=getspot') < 0 && basePATH.indexOf('/details/') < 0) {
  7. closeDetails(0);
  8. var currentSpot = $('table.spots tr.active');
  9. if ((currentSpot) && (currentSpot.offset() != null)) {
  10. if (currentSpot.offset().top > $(window).height()) {
  11. $(document).scrollTop($('table.spots tr.active').offset().top - 50);
  12. } // if
  13. } // if
  14. } else if ($.address.value() != '/') openSpot($('table.spots tr.active a.spotlink'), $.address.value());
  15. });
  16. $(function(){
  17. // console.time("10th-ready");
  18. //ready
  19. $("a.spotlink").click(function(e) { e.preventDefault(); });
  20. $('.showTipTip a.spotlink').each(applyTipTip);
  21. if(navigator.userAgent.toLowerCase().indexOf('chrome')>-1)$('a.spotlink').mouseup(function(e){if(e.which==2||(e.metaKey||e.ctrlKey)&&e.which==1){$(this).attr('rel','address:');}});
  22. $("a[href^='http']").attr('target','_blank');
  23. $("#filterform input").keypress(function (e) {
  24. if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
  25. $('form#filterform').find('input[type=submit].default').click();
  26. return false;
  27. } else {
  28. return true;
  29. }
  30. });
  31. // console.timeEnd("10th-ready");
  32. });
  33. // createBaseURL
  34. function createBaseURL() {
  35. var baseURL = '$HTTP_S://'+window.location.hostname+window.location.pathname;
  36. if (window.location.port != '') {
  37. var baseURL = '$HTTP_S://'+window.location.hostname+':'+window.location.port+window.location.pathname;
  38. }
  39. return baseURL;
  40. }
  41. // Detecteer aanwezigheid scrollbar binnen spotinfo pagina
  42. function detectScrollbar() {
  43. var $divDetails = $("div#details");
  44. if (($divDetails) && ($divDetails.offset() != null)) {
  45. if(($divDetails.outerHeight() + $divDetails.offset().top <= $(window).height())) {
  46. $divDetails.addClass("noscroll");
  47. } else {
  48. $divDetails.removeClass("noscroll");
  49. }
  50. } // if
  51. }
  52. // openSpot in overlay
  53. function openSpot(id,url) {
  54. if (!spotweb_security_allow_spotdetail) {
  55. return false;
  56. } // if
  57. if($("#overlay").is(":visible")) {
  58. $("#overlay").addClass('notrans');
  59. }
  60. $("table.spots tr.active").removeClass("active");
  61. $(id).parent().parent().addClass('active');
  62. $("table.spots tr.active td.title").removeClass("new");
  63. if ($(id).attr('rel') ) {
  64. openNewWindow();
  65. setTimeout("$('a.spotlink').removeAttr('rel');",1);
  66. return false;
  67. } //chrome
  68. var messageid = url.split("=")[2];
  69. $("#overlay").addClass('loading');
  70. $("#overlay").empty().show();
  71. var scrollLocation = $(document).scrollTop();
  72. $("#overlay").load(url+' #details', function() {
  73. $("div.container").removeClass("visible").addClass("hidden");
  74. $("#overlay").removeClass('loading notrans');
  75. $("body").addClass("spotinfo");
  76. if($("#overlay").children().size() == 0) {
  77. alert("<t>Error while loading this page, you will be returned automaticly to the mainview</t>");
  78. closeDetails(scrollLocation);
  79. }
  80. $("a.closeDetails").click(function(){
  81. $.address.value("");
  82. if ($('table.spots tr.active').offset().top > $(window).height())scrollLocation = $('table.spots tr.active').offset().top - 50;
  83. closeDetails(scrollLocation);
  84. });
  85. $("a[href^='http']").attr('target','_blank');
  86. $(window).bind("resize", detectScrollbar);
  87. postCommentsForm();
  88. postReportForm();
  89. postBlacklistForm();
  90. if (spotweb_retrieve_commentsperpage > 0) {
  91. loadComments(messageid,spotweb_retrieve_commentsperpage,'0');
  92. } // if
  93. loadSpotImage();
  94. });
  95. }
  96. /*
  97. * Refresht een tab in een bepaalde tab lijst,
  98. * kan als callback gegeven worden aan showDialog()
  99. */
  100. function refreshTab(tabName) {
  101. var tab = $('#' + tabName);
  102. var selected = tab.tabs('option', 'selected');
  103. tab.tabs('load', selected);
  104. } // refreshTab
  105. /*
  106. * Helper function to open a dialog, a couple of parameters are required.
  107. *
  108. * divid = id of a dummy div which should be used to create a dialog
  109. * title = title of the dialogbox
  110. * url = URL of the HTML content to load into the dialog
  111. * formname = Formname, necessary to attach the submit buttons
  112. * buttonClick = Function to be called when the submit button is pressed
  113. * successAction = choice of 'autoclose', 'showresultonly', 'reload'
  114. * closeCb = Function which should be called when the dialog is closed
  115. * openCb = Function which should be called when the HTML content of the dialog is loaded
  116. */
  117. function openDialog(divid, title, url, formname, buttonClick, successAction, closeCb, openCb) {
  118. var $dialdiv = $("#" + divid);
  119. if (!$dialdiv.is(".ui-dialog-content")) {
  120. // en nu kunnen we de dialog wel tonen
  121. $dialdiv.dialog( {
  122. title: title,
  123. autoOpen: false,
  124. resizable: false,
  125. position: 'center',
  126. stack: true,
  127. closeOnEscape: true,
  128. height: 'auto',
  129. width: 'auto',
  130. modal: true
  131. } );
  132. } // if
  133. // Update de dialogs' title, de tweede manier is er omdat het niet altijd goed
  134. // werkt met de 1e methode
  135. $dialdiv.dialog("option", 'title', title);
  136. $("span.ui-dialog-title").text(title);
  137. /* submit button handler */
  138. if (!buttonClick) {
  139. var buttonClick = function() {
  140. // In deze context is 'this' de submit button waarop gedrukt is,
  141. // dus die data voegen we gewoon aan de post data toe.
  142. var formdata = $(this).attr("name") + "=" + $(this).val();
  143. formdata = $(this.form).serialize() + "&" + formdata;
  144. // post de data
  145. $.ajax({
  146. type: "POST",
  147. url: this.form.action,
  148. dataType: "xml",
  149. data: formdata,
  150. success: function(xml) {
  151. var $dialdiv = $("#"+divid)
  152. var result = $(xml).find('result').text();
  153. if ((result == 'success') && (successAction == 'autoclose')) {
  154. $dialdiv.dialog('close');
  155. $dialdiv.empty();
  156. if (closeCb) {
  157. closeCb();
  158. } // if
  159. } else {
  160. /* We herladen de content zodat eventuele dialog wijzigingen duidelijk zijn */
  161. if (successAction == 'reload') {
  162. loadDialogContent(false);
  163. } // if
  164. if ((successAction == 'showresultsonly') && (result == 'success')) {
  165. $dialdiv.empty();
  166. /* Create the empty elements to show the errors/information in */
  167. $dialdiv.html("<ul class='formerrors'></ul><ul class='forminformation'></ul>");
  168. } // if
  169. var $formerrors = $dialdiv.find("ul.formerrors");
  170. $formerrors.empty();
  171. $('errors', xml).each(function() {
  172. $formerrors.append("<li>" + $(this).text() + "</li>");
  173. }); // each
  174. // Add the information items to the form
  175. var $forminfo = $dialdiv.find("ul.forminformation");
  176. $forminfo.empty();
  177. $('info', xml).each(function() {
  178. $forminfo.append("<li>" + $(this).text() + "</li>");
  179. }); // each
  180. } // if post was not succesful
  181. } // success()
  182. }); // ajax call om de form te submitten
  183. return false; // standaard button submit supressen
  184. } // buttonClick
  185. } // if not defined
  186. /*
  187. * definieer een dialog loader functie welke tegelijkertijd
  188. * de submit buttons attached, deze wordt namelijk aangeroepen
  189. * als een dialog submit succesvol is, maar de dialog niet gesloten
  190. * mag worden. Dat is namelijk de simpelste manier om de content
  191. * te refreshen
  192. */
  193. function loadDialogContent(async) {
  194. /* en laad de werkelijke content */
  195. $.ajax({
  196. type: "GET",
  197. dataType: "html",
  198. async: async,
  199. url: url,
  200. data: {},
  201. success: function(response) {
  202. // Laad de content van de pagina in de dialog zodat we die daarna
  203. // kunnen laten zien
  204. var $dialdiv = $("#" + divid);
  205. $dialdiv.empty().html(response);
  206. // sla de geladen url op zodat we het resultaat zien
  207. $dialdiv.data('dialogurl', url);
  208. // we vragen vervolgens alle submit buttons op, hier gaan we dan een
  209. // form submit handler aan vast knopen. Dit is nodig omdat standaard
  210. // de form submit handler van jquery niet weet op welke knop er gedrukt
  211. // is, dus moeten we wat doen om dat duidelijk te krijgen.
  212. //var $buttons = $("form." + formname + " input[type='submit']");
  213. var $buttons = $("#" + divid + " input[type='submit']");
  214. $buttons.click(buttonClick)
  215. // Call the open callback
  216. if (openCb) {
  217. openCb();
  218. } // if
  219. // en toon de dialog
  220. $dialdiv.dialog('open');
  221. return false; // standaard link actie voor openen dialog supressen
  222. } // success function
  223. }); // ajax call
  224. } // loadDialogContent
  225. // en laad de content
  226. loadDialogContent(true);
  227. return false;
  228. } // openDialog
  229. // Open spot in los scherm
  230. function openNewWindow() {
  231. url = $('table.spots tr.active a.spotlink').attr("onclick").toString().match(/"(.*?)"/)[1];
  232. window.open(url);
  233. }
  234. // En maak de overlay onzichtbaar
  235. function closeOverlay() {
  236. $("div.container").removeClass("hidden").addClass("visible");
  237. $("#overlay").hide();
  238. $("#details").remove();
  239. } // closeOverlay
  240. // Sluit spotinfo overlay
  241. function closeDetails(scrollLocation) {
  242. closeOverlay();
  243. $("body").removeClass("spotinfo");
  244. $(document).scrollTop(scrollLocation);
  245. }
  246. // Laadt nieuwe spots in overzicht wanneer de onderkant wordt bereikt
  247. $(function(){
  248. //ready
  249. // console.time("2nd-ready");
  250. var pagenr = $('#nextPage').val();
  251. $(window).scroll(function() {
  252. var url = '?direction=next&data[spotsonly]=1&pagenr='+pagenr+$('#getURL').val()+' #spots';
  253. if($(document).scrollTop() >= $(document).height() - $(window).height() && $(document).height() >= $(window).height() && pagenr > 0 && $("#overlay").is(':hidden')) {
  254. if(!($("div.spots").hasClass("full"))) {
  255. var scrollLocation = $("div.container").scrollTop();
  256. $("#overlay").show().addClass('loading');
  257. $("div#overlay").load(url, function() {
  258. if($("div#overlay tbody#spots").children().size() < $('#perPage').val()) {
  259. $("table.footer").remove();
  260. $("div.spots").addClass("full");
  261. }
  262. $("#overlay").hide().removeClass('loading');
  263. $("tbody#spots").append($($("div#overlay tbody#spots").html()).fadeIn('slow'));
  264. $("div#overlay").empty();
  265. $("a.spotlink").click(function(e) { e.preventDefault(); });
  266. $(".showTipTip a.spotlink").each(applyTipTip);
  267. pagenr++;
  268. $("td.next > a").attr("href", url);
  269. $("div.container").scrollTop(scrollLocation);
  270. });
  271. }
  272. }
  273. });
  274. // console.timeEnd("2nd-ready");
  275. });
  276. // Haal de comments op en zet ze per batch op het scherm
  277. function loadComments(messageid,perpage,pagenr) {
  278. if (!spotweb_security_allow_view_comments) {
  279. return false;
  280. } // if
  281. var xhr = null;
  282. xhr = $.get('?page=render&tplname=comment&messageid='+messageid+'&pagenr='+pagenr+'&perpage='+perpage, function(html) {
  283. count = $(html+' > li').length / 2;
  284. if (count == 0 && pagenr == 0) {
  285. $("#commentslist").append("<li class='nocomments'><t>No (verified) comments found.</t></li>");
  286. } else {
  287. $("span.commentcount").html('# '+$("#commentslist").children().not(".addComment").size());
  288. }
  289. $("#commentslist").append($(html).fadeIn('slow'));
  290. $("#commentslist > li:nth-child(even)").addClass('even');
  291. $("#commentslist > li.addComment").next().addClass('firstComment');
  292. pagenr++;
  293. if (count >= 1) {
  294. loadComments(messageid,perpage,pagenr);
  295. } else {
  296. detectScrollbar();
  297. }
  298. });
  299. $("a.closeDetails").click(function() { xhr.abort() });
  300. }
  301. function postReportForm() {
  302. $("form.postreportform").submit(function(){
  303. new spotPosting().postReport(this,postReportUiStart,postReportUiDone);
  304. return false;
  305. });
  306. }
  307. function blacklistSpotterId(spotterId) {
  308. $("input[name='blacklistspotterform[spotterid]']").val(spotterId);
  309. $('form.blacklistspotterform').submit();
  310. } // blacklistSpotterId
  311. function whitelistSpotterId(spotterId) {
  312. $("input[name='blacklistspotterform[spotterid]']").val(spotterId);
  313. $("input[name='blacklistspotterform[idtype]']").val('2');
  314. $("input[name='blacklistspotterform[origin]']").val('Whitelisted by user');
  315. $('form.blacklistspotterform').submit();
  316. } // blacklistSpotterId
  317. function validateNntpServerSetting(settingsForm, serverArrayId) {
  318. $("#servertest_" + serverArrayId + "_loading").show();
  319. var formData = 'data[host]=' + settingsForm.elements[settingsForm.name + '[' + serverArrayId + '][host]'].value;
  320. if (settingsForm.elements[settingsForm.name + '[' + serverArrayId + '][enc][switch]'].checked) {
  321. formData += '&data[enc]=' + settingsForm.elements[settingsForm.name + '[' + serverArrayId + '][enc][select]'].value;
  322. } // if
  323. formData += '&data[port]=' + settingsForm.elements[settingsForm.name + '[' + serverArrayId + '][port]'].value;
  324. formData += '&data[user]=' + settingsForm.elements[settingsForm.name + '[' + serverArrayId + '][user]'].value;
  325. formData += '&data[pass]=' + settingsForm.elements[settingsForm.name + '[' + serverArrayId + '][pass]'].value;
  326. $.ajax({
  327. type: "POST",
  328. url: "?page=render&tplname=validatenntp",
  329. dataType: "xml",
  330. data: formData,
  331. success: function(xml) {
  332. var result = $(xml).find('result').text();
  333. $("#servertest_" + serverArrayId + "_loading").hide();
  334. /* Remove existing style and contents from from the string */
  335. $("#servertest_" + serverArrayId + "_result")
  336. .removeClass("servertest_" + serverArrayId + "_result_success")
  337. .removeClass("servertest_" + serverArrayId + "_result_fail")
  338. .empty();
  339. if (result == 'success') {
  340. $("#servertest_" + serverArrayId + "_result")
  341. .addClass("servertest_" + serverArrayId + "_result_success")
  342. .text("OK");
  343. } else {
  344. $("#servertest_" + serverArrayId + "_result")
  345. .addClass("servertest_" + serverArrayId + "_result_fail")
  346. .text($(xml).find('error').text());
  347. } // else
  348. } // success
  349. }); // ajax call om de form te submitten
  350. return false;
  351. } // validateNntpServerSetting
  352. function postBlacklistForm() {
  353. $("form.blacklistspotterform").submit(function(){
  354. formdata = $(this).serialize();
  355. $.ajax({
  356. type: "POST",
  357. url: this.action,
  358. dataType: "xml",
  359. data: formdata,
  360. success: function(xml) {
  361. $(".blacklistuserlink_" + $("input[name='blacklistspotterform[spotterid]']").val()).remove();
  362. } // success
  363. }); // ajax call om de form te submitten
  364. return false;
  365. }); // submit
  366. } // postBlacklistForm
  367. // Load post comment form
  368. function postCommentsForm() {
  369. $("li.addComment a.togglePostComment").click(function(){
  370. if($("li.addComment div").is(":hidden")) {
  371. $("li.addComment div").slideDown(function(){
  372. detectScrollbar();
  373. });
  374. $("li.addComment a.togglePostComment span").addClass("up").parent().attr("title", "<t>Add comment (hide)</t>");
  375. } else {
  376. $("li.addComment div").slideUp(function(){
  377. detectScrollbar();
  378. });
  379. $("li.addComment a.togglePostComment span").removeClass("up").parent().attr("title", "<t>Add comment (show)</t>");
  380. }
  381. });
  382. for (i=1; i<=10; i++) {
  383. $("li.addComment dd.rating").append("<span id='ster"+i+"'></span>");
  384. sterStatus(i, 0);
  385. }
  386. var rating = 0;
  387. $("li.addComment dd.rating span").click(function() {
  388. if($(this).index() == rating) {
  389. rating = 0;
  390. } else {
  391. rating = $(this).index();
  392. }
  393. $("li.addComment dd.rating span").each(function(){
  394. sterStatus($(this).index(), rating);
  395. });
  396. $("li.addComment input[name='postcommentform[rating]']").val(rating);
  397. });
  398. function sterStatus(id, rating) {
  399. if (id == 1) { ster = '<t>star</t>'; } else { ster = '<t>stars</t>'; }
  400. if (id < rating) {
  401. $("span#ster"+id).addClass("active").attr('title', '<t>Rate spot</t> '+id+' '+ster);
  402. } else if (id == rating) {
  403. if (id == 1) {
  404. $("span#ster"+id).addClass("active").attr('title', "<t>Don't give any star</t>");
  405. } else {
  406. $("span#ster"+id).addClass("active").attr('title', "<t>Don't give any stars</t>");
  407. } // if
  408. } else {
  409. $("span#ster"+id).removeClass("active").attr('title', '<t>Rate spot</t> '+id+' '+ster);
  410. }
  411. }
  412. $("form.postcommentform").submit(function(){
  413. new spotPosting().postComment(this,postCommentUiStart,postCommentUiDone);
  414. return false;
  415. });
  416. }
  417. // Laadt de spotImage wanneer spotinfo wordt geopend
  418. function loadSpotImage() {
  419. if (!spotweb_security_allow_view_spotimage) {
  420. return false;
  421. } // if
  422. $('img.spotinfoimage').hide();
  423. $('a.postimage').addClass('loading');
  424. $('img.spotinfoimage').load(function() {
  425. $('a.postimage').removeClass('loading');
  426. $(this).show();
  427. $('a.postimage').css({
  428. 'width': $("img.spotinfoimage").width(),
  429. 'height': $("img.spotinfoimage").height()
  430. })
  431. $('a.postimage').attr('title', '<t>Click on this image to show real size (i)</t>');
  432. detectScrollbar();
  433. })
  434. .each(function() {
  435. // From the jQuery comments: http://api.jquery.com/load-event/
  436. if (this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) {
  437. $(this).trigger("load");
  438. }
  439. });
  440. }
  441. function toggleImageSize() {
  442. if($("img.spotinfoimage").hasClass("full")) {
  443. $("img.spotinfoimage").removeClass("full");
  444. $("img.spotinfoimage").removeAttr("style");
  445. $('a.postimage').attr('title', '<t>Click on this image to show real size (i)</t>');
  446. } else {
  447. $('a.postimage').attr('title', '<t>Click image to reduce</t>');
  448. $("img.spotinfoimage").addClass("full");
  449. $("img.spotinfoimage").css({
  450. 'max-width': $("div#overlay").width() - 5,
  451. 'max-height': $("div#overlay").height() - 35
  452. });
  453. }
  454. }
  455. // Bind keys to functions
  456. $(function(){
  457. // console.time("3rd-ready");
  458. //ready
  459. $('table.spots tbody tr').first().addClass('active');
  460. var $document = $(document);
  461. $document.bind('keydown', 'k', function(){if(!($("div#overlay").hasClass("loading"))) {spotNav('prev')}});
  462. $document.bind('keydown', 'j', function(){if(!($("div#overlay").hasClass("loading"))) {spotNav('next')}});
  463. $document.bind('keydown', 'o', function(){if($("#overlay").is(':hidden')){$('table.spots tbody tr.active .title a.spotlink').click()}});
  464. $document.bind('keydown', 'return', function(){if($("#overlay").is(':hidden')){$('table.spots tbody tr.active .title a.spotlink').click()}});
  465. $document.bind('keydown', 'u', function(){$("a.closeDetails").click()});
  466. $document.bind('keydown', 'esc', function(){$("a.closeDetails").click()});
  467. $document.bind('keydown', 'i', toggleImageSize);
  468. $document.bind('keydown', 's', function(){if($("#overlay").is(':visible') || $('#details').hasClass("external")) {$("#details a.sabnzbd-button").click()} else {$("tr.active a.sabnzbd-button").click()}});
  469. $document.bind('keydown', 'n', function(){if($("#overlay").is(':visible') || $('#details').hasClass("external")) {location.href = $("#details a.nzb").attr('href')} else if($("th.nzb").is(":visible")) {location.href = $("tr.active a.nzb").attr('href')}});
  470. $document.bind('keydown', 'w', function(){if($("#overlay").is(':visible') || $('#details').hasClass("external")) {$("#details th.watch a:visible").click()} else if($("div.spots").hasClass("watchlist")) {location.href = $("tr.active td.watch a").attr('href')} else {$("tr.active td.watch a:visible").click()}});
  471. $document.bind('keydown', 't', function(){openNewWindow()});
  472. $document.bind('keydown', 'h', function(){location.href = '?search[tree]=&search[unfiltered]=true'});
  473. $document.bind('keydown', 'm', downloadMultiNZB);
  474. $document.bind('keydown', 'c', checkMultiNZB);
  475. // console.timeEnd("3rd-ready");
  476. });
  477. // Keyboard navigation functions
  478. function spotNav(direction) {
  479. var current = $('table.spots tbody tr.active');
  480. var prev = current.prevUntil('tr.header').first();
  481. var next = current.next().first();
  482. if (direction == 'prev' && prev.size() == 1) {
  483. current.removeClass('active');
  484. prev.addClass('active');
  485. if($("#overlay").is(':visible')) {
  486. $("div.container").removeClass("hidden").addClass("visible");
  487. $(document).scrollTop($('table.spots tr.active').offset().top - 50);
  488. $('table.spots tbody tr.active .title a.spotlink').click();
  489. }
  490. } else if (direction == 'next' && next.size() == 1) {
  491. current.removeClass('active');
  492. next.addClass('active');
  493. if($("#overlay").is(':visible')) {
  494. $("div.container").removeClass("hidden").addClass("visible");
  495. $(document).scrollTop($('table.spots tr.active').offset().top - 50);
  496. $("table.spots tbody tr.active .title a.spotlink").click();
  497. }
  498. }
  499. if($("#overlay").is(':hidden')) {$(document).scrollTop($('table.spots tr.active').offset().top - 50)}
  500. }
  501. /*
  502. * Initializes the user preferences screen
  503. */
  504. function initializeUserPreferencesScreen() {
  505. $("#edituserpreferencetabs").tabs();
  506. /* If the user preferences tab is loaded, make the filters sortable */
  507. $('#edituserpreferencetabs').bind('tabsload', function(event, ui) {
  508. bindSelectedSortableFilter();
  509. });
  510. $('#nzbhandlingselect').change(function() {
  511. $('#nzbhandling-fieldset-localdir, #nzbhandling-fieldset-runcommand, #nzbhandling-fieldset-sabnzbd, #nzbhandling-fieldset-nzbget').hide();
  512. var selOpt = $(this).find('option:selected').data('fields').split(' ');
  513. $.each(selOpt, function(index) {
  514. $('#nzbhandling-fieldset-' + selOpt[index]).show();
  515. }); // each
  516. }); // change
  517. // roep de change handler aan zodat alles goed staat
  518. $('#nzbhandlingselect').change();
  519. /* Attach the hide/show functionalitity to the checkboxes who want it */
  520. attachEnablerBehaviour();
  521. $('#twitter_request_auth').click(function(){
  522. $('#twitter_result').html(loading);
  523. $.get(BaseURL+"?page=twitteroauth", function (data){window.open(data)}).complete(function() {
  524. $('#twitter_result').html('<t><b>Step 2</b?:<br />Please fill below your PIN-number that twitter has given you and validate this.</t><br /><input type="text" name="twitter_pin" id="twitter_pin">');
  525. });
  526. $(this).replaceWith('<input type="button" id="twitter_verify_pin" value="<t>Validate PIN</t>">');
  527. });
  528. $('#twitter_verify_pin').live('click', function(){
  529. var pin = $("#twitter_pin").val();
  530. $('#twitter_result').html(loading);
  531. $.get(BaseURL+"?page=twitteroauth", {'action':'verify', 'pin':pin}, function(data){ $('#twitter_result').html(data); });
  532. });
  533. $('#twitter_remove').click(function(){
  534. $('#twitter_result').html(loading);
  535. $.get(BaseURL+"?page=twitteroauth", {'action': 'remove'}, function(data){ $('#twitter_result').html(data); });
  536. });
  537. } // initializeUserPreferencesScreen
  538. /*
  539. * Some checkboxes behave as an 'hide/show' button for extra settings
  540. * we want to add the behaviour to those buttons
  541. */
  542. function attachEnablerBehaviour() {
  543. $(".enabler").each(function(){
  544. if (!$(this).prop('checked'))
  545. $('#content_'+$(this).attr('id')).hide();
  546. });
  547. $(".enabler").click(function() {
  548. if ($(this).prop('checked'))
  549. $('#content_'+$(this).attr('id')).show();
  550. else
  551. $('#content_'+$(this).attr('id')).hide();
  552. });
  553. } // attachEnablerBehaviour
  554. $(document).ready(function() {
  555. // console.time("4th-ready");
  556. //ready
  557. var BaseURL = createBaseURL();
  558. var loading = '<img src="'+BaseURL+'templates/we1rdo/img/loading.gif" height="16" width="16" />';
  559. $("#usermanagementtabs").tabs();
  560. $("#editsettingstab").tabs();
  561. attachEnablerBehaviour();
  562. initializeUserPreferencesScreen();
  563. // console.timeEnd("4th-ready");
  564. });
  565. // Regel positie en gedrag van sidebar (fixed / relative)
  566. $().ready(function() {
  567. // console.time("5th-ready");
  568. //ready
  569. $('#filterscroll').bind('change', function() {
  570. var scrolling = $(this).is(':checked');
  571. $.cookie('scrolling', scrolling, { path: '', expires: $COOKIE_EXPIRES, domain: '$COOKIE_HOST' });
  572. toggleScrolling(scrolling);
  573. });
  574. var scrolling = $.cookie("scrolling");
  575. toggleScrolling(scrolling);
  576. // console.timeEnd("5th-ready");
  577. });
  578. function toggleScrolling(state) {
  579. if (state == true || state == 'true') {
  580. $('#filterscroll').attr({checked:'checked', title:'<t>Do not always make the sidebar visible</t>'});
  581. $('body').addClass('fixed');
  582. } else {
  583. $('#filterscroll').attr({title:'<t>Make sidebar always visible</t>'});
  584. $('body').removeClass('fixed');
  585. }
  586. }
  587. // Sidebar items in/uitklapbaar maken
  588. function getSidebarState() {
  589. var data = new Array();
  590. $("div#filter > a.viewState").each(function(index) {
  591. var state = $(this).next().css("display");
  592. data.push({"count": index, "state": state});
  593. });
  594. $.cookie("sidebarVisibility", JSON.stringify(data), { path: '', expires: $COOKIE_EXPIRES, domain: '$COOKIE_HOST' });
  595. }
  596. $(function(){
  597. // console.time("6th-ready");
  598. //ready
  599. var data = jQuery.parseJSON($.cookie("sidebarVisibility"));
  600. if(data == null) {
  601. getSidebarState();
  602. var data = jQuery.parseJSON($.cookie("sidebarVisibility"));
  603. }
  604. $.each(data, function(i, value) {
  605. $("div#filter > a.viewState").eq(value.count).next().css("display", value.state);
  606. if(value.state != "none") {
  607. $("div#filter > a.viewState").eq(value.count).children("h4").children("span").removeClass("down").addClass("up");
  608. } else {
  609. $("div#filter > a.viewState").eq(value.count).children("h4").children("span").removeClass("up").addClass("down");
  610. }
  611. });
  612. // console.timeEnd("6th-ready");
  613. });
  614. function toggleSidebarItem(id) {
  615. var hide = $(id).next();
  616. $(hide).toggle();
  617. $(id).children("h4").children("span").toggleClass("up down");
  618. getSidebarState()
  619. }
  620. // Geavanceerd zoeken op juiste moment zichtbaar / onzichtbaar maken
  621. $(function(){
  622. // console.time("7th-ready");
  623. //ready
  624. $("input.searchbox").focus(function(){
  625. if($("form#filterform .advancedSearch").is(":hidden")) {
  626. toggleSidebarPanel('.advancedSearch');
  627. }
  628. });
  629. $("input[name='search[unfiltered]']").attr('checked') ? $("div#tree").hide() : $("div#tree").show();
  630. $("input[name='search[unfiltered]']").click(function() {
  631. if($("div#tree").is(":visible")) {
  632. $("div#tree").hide();
  633. $("ul.clearCategories label").html('<t>Use categories</t>');
  634. } else {
  635. $("div#tree").show();
  636. $("ul.clearCategories label").html("<t>Don't use categories</t>");
  637. }
  638. });
  639. // console.timeEnd("7th-ready");
  640. });
  641. // Pas sorteervolgorde aan voor datum
  642. $(function(){
  643. // console.time("8th-ready");
  644. //ready
  645. $("ul.sorting input").click(function() {
  646. if($(this).val() == 'stamp' || $(this).val() == 'commentcount' || $(this).val() == 'spotrating') {
  647. $("div.advancedSearch input[name=sortdir]").attr("value", "DESC");
  648. } else {
  649. $("div.advancedSearch input[name=sortdir]").attr("value", "ASC");
  650. }
  651. });
  652. // console.timeEnd("8th-ready");
  653. });
  654. // sidebarPanel zichtbaar maken / verbergen
  655. function toggleSidebarPanel(id) {
  656. if($(id).is(":visible")) {
  657. $(id).fadeOut();
  658. } else {
  659. if($(".sidebarPanel").is(":visible")) {
  660. $(".sidebarPanel").fadeOut();
  661. $(id).fadeIn();
  662. } else {
  663. $(id).fadeIn();
  664. }
  665. if(id == ".sabnzbdPanel") {
  666. updateSabPanel(1,5);
  667. }
  668. }
  669. }
  670. // SabNZBd knop; url laden via ajax (regel loading en succes status)
  671. function downloadSabnzbd(id,url) {
  672. $(".sab_"+id).removeClass("succes").addClass("loading");
  673. /* This is a cross-domain request, so success will never be called */
  674. $.get(url, function(data, textStatus, jqXHR) {
  675. $(".sab_"+id).removeClass("loading").addClass("succes");
  676. });
  677. setTimeout( function() { $(".sab_"+id).removeClass("loading").addClass("succes"); }, 2000);
  678. }
  679. // Voorzie de span.newspots van link naar nieuwe spots binnen het filter
  680. function gotoNew(url) {
  681. $("a").click(function(){ return false; });
  682. window.location = url+'&search[value][]=New:0';
  683. }
  684. // Voorzie de span.newspots van link naar spots binnen het filter
  685. function gotoFilteredCategory(url) {
  686. $("a").click(function(){ return false; });
  687. window.location = url;
  688. }
  689. // Toevoegen en verwijderen van spots aan watchlist
  690. function toggleWatchSpot(spot,action,spot_id) {
  691. // Add/remove watchspot
  692. $.get("?search[tree]=&search[unfiltered]=true&search[value][]=Watch:0&action="+action+"&messageid="+spot);
  693. // Switch buttons
  694. $('.watchremove_'+spot_id).toggle();
  695. $('.watchadd_'+spot_id).toggle();
  696. }
  697. // MultiNZB download knop
  698. function multinzb() {
  699. var count = $('td.multinzb input[type="checkbox"]:checked').length;
  700. if(count == 0) {
  701. $('div.notifications').fadeOut();
  702. } else {
  703. $('div.notifications').fadeIn();
  704. if(count == 1) {
  705. $('span.count').html('<t>Download 1 spot</t>');
  706. } else {
  707. $('span.count').html('<t>Download %1 spots</t>'.replace('%1', count));
  708. }
  709. }
  710. }
  711. function uncheckMultiNZB() {
  712. $("table.spots input[type=checkbox]").attr("checked", false);
  713. $('div.notifications').fadeOut();
  714. }
  715. function checkMultiNZB() {
  716. if($("tr.active input[type=checkbox]").is(":checked")) {
  717. $("tr.active input[type=checkbox]").attr('checked', false);
  718. multinzb()
  719. } else {
  720. $("tr.active input[type=checkbox]").attr('checked', true);
  721. multinzb()
  722. }
  723. }
  724. function downloadMultiNZB() {
  725. var count = $('td.multinzb input[type="checkbox"]:checked').length;
  726. if(count > 0) {
  727. var url = '?page=getnzb';
  728. $('td.multinzb input[type=checkbox]:checked').each(function() {
  729. url += '&messageid%5B%5D='+$(this).val();
  730. });
  731. window.location = url;
  732. $("table.spots input[type=checkbox]").attr("checked", false);
  733. multinzb();
  734. }
  735. }
  736. // Toggle filter visibility
  737. $(function(){
  738. // console.time("9th-ready");
  739. //ready
  740. var data = jQuery.parseJSON($.cookie("filterVisiblity"));
  741. if(data != null) {
  742. $.each(data, function(i, value) {
  743. $("ul.subfilterlist").parent().eq(value.count).children("ul").css("display", value.state);
  744. if(value.state == "block") {
  745. $("ul.subfilterlist").parent().eq(value.count).children("a").children("span.toggle").css("background-position", "-77px -98px");
  746. $("ul.subfilterlist").parent().eq(value.count).children("a").children("span.toggle").attr("title", "<t>Collapse filter</t>");
  747. } else {
  748. $("ul.subfilterlist").parent().eq(value.count).children("a").children("span.toggle").css("background-position", "-90px -98px");
  749. $("ul.subfilterlist").parent().eq(value.count).children("a").children("span.toggle").attr("title", "<t>Expand filter</t>");
  750. }
  751. });
  752. }
  753. // console.timeEnd("9th-ready");
  754. });
  755. function toggleFilter(id) {
  756. $(id).parent().click(function(){ return false; });
  757. var ul = $(id).parent().next();
  758. if($(ul).is(":visible")) {
  759. ul.hide();
  760. ul.prev().children("span.toggle").css("background-position", "-90px -98px");
  761. ul.prev().children("span.toggle").attr("title", "<t>Expand filter</t>");
  762. } else {
  763. ul.show();
  764. ul.prev().children("span.toggle").css("background-position", "-77px -98px");
  765. ul.prev().children("span.toggle").attr("title", "<t>Collapse filter</t>");
  766. }
  767. var data = new Array();
  768. $("ul.subfilterlist").each(function(index) {
  769. var state = $(this).css("display");
  770. data.push({"count": index, "state": state});
  771. });
  772. $.cookie("filterVisiblity", JSON.stringify(data), { path: '', expires: $COOKIE_EXPIRES, domain: '$COOKIE_HOST' });
  773. }
  774. // Maintenance buttons
  775. $(function(){
  776. $("ul.maintenancebox a.retrievespots").click(function(){return false});
  777. $("ul.maintenancebox a.erasedownloads").click(function(){return false});
  778. $("ul.maintenancebox a.markasread").click(function(){return false});
  779. });
  780. function retrieveSpots() {
  781. var url = $("ul.maintenancebox a.retrievespots").attr("href");
  782. $("li.info").html("<img src='templates/we1rdo/img/loading.gif' />");
  783. $.get(url, function(data) {
  784. setTimeout( function() { $("li.info").html("<t>New spots retrieved</t>") }, 1000);
  785. setTimeout( function() { location.reload() }, 2000);
  786. });
  787. }
  788. function eraseDownloads() {
  789. var url = $("ul.maintenancebox a.erasedownloads").attr("href");
  790. $("li.info").html("<img src='templates/we1rdo/img/loading.gif' />");
  791. $.get(url, function(data) {
  792. setTimeout( function() { $("li.info").html("<t>Erased downloadhistory</t>") }, 1000);
  793. setTimeout( function() { location.reload() }, 2000);
  794. });
  795. }
  796. function markAsRead() {
  797. var url = $("ul.maintenancebox a.markasread").attr("href");
  798. $("li.info").html("<img src='templates/we1rdo/img/loading.gif' />");
  799. $.get(url, function(data) {
  800. setTimeout( function() { $("li.info").html("<t>Marked everything as read</t>") }, 1000);
  801. setTimeout( function() { location.reload() }, 2000);
  802. });
  803. }
  804. function ajaxSubmitFormWithCb(url, tbutton, cb) {
  805. var formdata = $(tbutton).attr("name") + "=" + $(tbutton).val();
  806. formdata = $(tbutton.form).serialize() + "&" + formdata;
  807. // post de data
  808. $.ajax({
  809. type: "POST",
  810. url: url, // '?page=editfilter',
  811. dataType: "html",
  812. data: formdata,
  813. success: function(xml) {
  814. // alert(xml);
  815. cb(xml);
  816. } // success
  817. }); // ajax call om de form te submitten
  818. } // ajaxSubmitFormWithCb
  819. function requestNewUserApiKeyCbHandler(xml) {
  820. var result = $(xml).find('newapikey').text();
  821. $(".apikeyinputfield").val(result);
  822. } // requestNewUserApiKeyCbHandler
  823. function userLogout() {
  824. var url = createBaseURL() + '?page=logout';
  825. $.ajax({
  826. type: "GET",
  827. url: url,
  828. async: false,
  829. dataType: "xml",
  830. success: function(msg) {
  831. window.location.reload();
  832. }
  833. });
  834. } // userLogout
  835. // SabNZBd actions
  836. function sabBaseURL() {
  837. var apikey = $("div.sabnzbdPanel input.apikey").val();
  838. var sabBaseURL = createBaseURL()+'?page=nzbhandlerapi&nzbhandlerapikey='+apikey;
  839. return sabBaseURL;
  840. }
  841. function sabActions(start,limit,action,slot) {
  842. var baseURL = sabBaseURL();
  843. if(action == 'pause') {
  844. var url = baseURL+'&action=pause&id'+slot;
  845. $.get(url, function(){
  846. updateSabPanel(start,limit);
  847. });
  848. } else if(action == 'resume') {
  849. var url = baseURL+'&action=resume&id'+slot;
  850. $.get(url, function(){
  851. updateSabPanel(start,limit);
  852. });
  853. } else if(action == 'speedlimit') {
  854. var limit = $("td.speedlimit input[name=speedLimit]").val();
  855. var url = baseURL+'&action=setspeedlimit&limit='+limit;
  856. $.get(url, function(){
  857. updateSabPanel(start,limit);
  858. });
  859. } else if(action == 'up') {
  860. var url = baseURL+'&action=moveup&id='+slot;
  861. $.get(url, function(){
  862. updateSabPanel(start,limit);
  863. });
  864. } else if(action == 'down') {
  865. var url = baseURL+'&action=movedown&id='+slot;
  866. $.get(url, function(){
  867. updateSabPanel(start,limit);
  868. });
  869. } else if(action == 'delete') {
  870. var url = baseURL+'&action=delete&id='+slot;
  871. $.get(url, function(){
  872. updateSabPanel(start,limit);
  873. });
  874. } else if(action == 'pausequeue') {
  875. var url = baseURL+'&action=pausequeue';
  876. $.get(url, function(){
  877. updateSabPanel(start,limit);
  878. });
  879. } else if(action == 'resumequeue') {
  880. var url = baseURL+'&action=resumequeue';
  881. $.get(url, function(){
  882. updateSabPanel(start,limit);
  883. });
  884. }
  885. }
  886. // Text toevoegen aan id (Smiley's)
  887. function addText(text,element_id) {
  888. document.getElementById(element_id).value += text;
  889. document.getElementById(element_id).focus();
  890. }
  891. function drawGraph(currentSpeed,interval) {
  892. var numXLabels = 8;
  893. var numYLabels = 5;
  894. if($("table.sabGraphData tbody > tr").size() == 1) {
  895. // maak juiste hoeveelheid data rijen aan (afhankelijk van numXLabels
  896. $("table.sabGraphData").empty();
  897. i = 0;
  898. for (i = 0; i <= numXLabels; i++) {
  899. $("table.sabGraphData").append("<tr><td>0.00</td></tr>");
  900. }
  901. }
  902. // vul de juiste rijen met de juiste data
  903. if($("table.sabGraphData td:empty").size() != 0) {
  904. $("table.sabGraphData td:empty").first().html(currentSpeed);
  905. } else {
  906. $("table.sabGraphData td").first().remove();
  907. $("table.sabGraphData").append("<tr><td>"+currentSpeed+"</td></tr>");
  908. }
  909. var elem = $("canvas#graph");
  910. elem.width = $("canvas#graph").width();
  911. elem.height = $("canvas#graph").height();
  912. var offset = {
  913. "top": 6,
  914. "right": 6,
  915. "bottom": 18,
  916. "left": 30
  917. };
  918. var graph = {
  919. "width": elem.width - offset.right - offset.left,
  920. "height": elem.height - offset.bottom - offset.top
  921. };
  922. var axisSpacing = {
  923. "x": 8,
  924. "y": 6
  925. };
  926. var intervalWidth = (elem.width - offset.left - offset.right) / numXLabels;
  927. var context = elem[0].getContext("2d");
  928. var speed = new Array();
  929. $("table.sabGraphData td").each(function(){
  930. speed.push({
  931. "count": $(this).index(),
  932. "value": $(this).text()
  933. });
  934. });
  935. var maxspeed = 0;
  936. var i = 0;
  937. for (i = 0; i <= numXLabels; i++) {
  938. if(Math.round(speed[i].value) >= Math.round(maxspeed)) {
  939. var maxspeed = speed[i].value;
  940. }
  941. };
  942. var speedAxis = new Array();
  943. var i = 0;
  944. for (i = 0; i <= numYLabels; i++) {
  945. speedAxis.push({
  946. "count": i,
  947. "posx": offset.left - axisSpacing.x,
  948. "posy": (elem.height-offset.bottom-offset.top) - (elem.height-offset.bottom-offset.top) * i/numYLabels + offset.top,
  949. "value": Math.round(maxspeed * i/numYLabels)
  950. });
  951. };
  952. var interval = interval / 1000;
  953. var timeAxis = new Array();
  954. var i = 0;
  955. for (i = 0; i <= numXLabels; i++) {
  956. timeAxis.push({
  957. "count": i,
  958. "posx": intervalWidth * i + offset.left,
  959. "posy": elem.height - offset.bottom + axisSpacing.y,
  960. "value": interval * i
  961. });
  962. };
  963. context.clearRect(0, 0, elem.width, elem.height);
  964. if(context) {
  965. // draw graph background
  966. context.shadowColor = "#777";
  967. context.shadowBlur = 0;
  968. context.fillStyle = "#eee";
  969. context.fillRect(offset.left, offset.top, graph.width, graph.height);
  970. // draw axis
  971. context.fillStyle = "#000";
  972. context.strokeStyle = "#fff";
  973. context.lineWidth = 2;
  974. context.shadowBlur = 3;
  975. context.beginPath();
  976. context.moveTo(offset.left, offset.top);
  977. context.lineTo(offset.left, elem.height - offset.bottom);
  978. context.lineTo(elem.width - offset.right, elem.height - offset.bottom);
  979. context.stroke();
  980. // draw axis labels
  981. context.shadowBlur = 0;
  982. $.each(speedAxis, function(i, value) {
  983. context.save();
  984. context.beginPath();
  985. context.moveTo(offset.left - 3, value.posy);
  986. context.lineTo(elem.width - offset.right, value.posy);
  987. context.stroke();
  988. if(maxspeed != 0 || value.count == 0) {
  989. context.shadowBlur = 0;
  990. context.textBaseline = "middle";
  991. context.textAlign = "end";
  992. context.fillText(value.value, value.posx, value.posy);
  993. }
  994. context.restore();
  995. });
  996. $.each(timeAxis, function(i, value) {
  997. context.save();
  998. context.beginPath();
  999. context.moveTo(value.posx, elem.height - offset.bottom);
  1000. context.lineTo(value.posx, elem.height - offset.bottom + 3);
  1001. context.stroke();
  1002. context.textBaseline = "top";
  1003. context.textAlign = "center";
  1004. context.fillText(value.value, value.posx, value.posy);
  1005. context.restore();
  1006. });
  1007. // draw graph
  1008. context.fillStyle = "#219727";
  1009. context.shadowBlur = 3;
  1010. var speedData = new Array();
  1011. var i = 0;
  1012. for (i = 0; i <= numXLabels; i++) {
  1013. speedData.push({
  1014. "count": i,
  1015. "posx": offset.left + i*intervalWidth,
  1016. "posy": (graph.height + offset.top) - (speed[i].value / maxspeed) * graph.height
  1017. });
  1018. };
  1019. context.beginPath();
  1020. context.moveTo(offset.left, elem.height - offset.bottom);
  1021. $.each(speedData, function(i, value) {
  1022. context.lineTo(value.posx, value.posy);
  1023. });
  1024. context.lineTo(offset.left + graph.width, offset.top + graph.height);
  1025. context.lineTo(offset.left, offset.top + graph.height);
  1026. context.fill();
  1027. context.stroke();
  1028. }
  1029. }
  1030. function updateSabPanel(start,limit) {
  1031. var baseURL = sabBaseURL();
  1032. var url = baseURL+'&action=getstatus';
  1033. $.getJSON(url, function(json){
  1034. var queue = json.queue;
  1035. if(queue.paused) {var state = "resume";} else {var state = "pause";}
  1036. $("table.sabInfo td.state").html("<strong>"+queue.status+"</strong> (<a class='state' title='"+state+"'>"+state+"</a>)");
  1037. $("table.sabInfo td.state a.state").click(function(){
  1038. if(timeOut) {clearTimeout(timeOut)};
  1039. sabActions(start,limit,state+"queue");
  1040. });
  1041. $("table.sabInfo td.diskspace").html("<strong title='<t>Free space (complete)</t>'>"+queue.freediskspace+"</strong> / <strong title='<t>Totale space (complete)</t>'>"+queue.totaldiskspace+"</strong> <t>GB</t>");
  1042. $("table.sabInfo td.speed").html("<strong>"+(queue.bytepersec/1024).toFixed(2)+"</strong> <t>KB/s</t>");
  1043. $("table.sabInfo td.speedlimit").html("<input type='text' name='speedLimit' value='"+(queue.speedlimit!=0?queue.speedlimit:"")+"'><label><t>KB/s</t></label>");
  1044. $("td.speedlimit input[name=speedLimit]").focus(function(){
  1045. $(this).addClass("hasFocus");
  1046. });
  1047. $("td.speedlimit input[name=speedLimit]").keyup(function(e) {
  1048. if(e.keyCode == 13) {
  1049. if(timeOut) {clearTimeout(timeOut)};
  1050. sabActions(start,limit,'speedlimit');
  1051. }
  1052. });
  1053. $("td.speedlimit input[name=speedLimit]").blur(function(){
  1054. if(timeOut) {clearTimeout(timeOut)};
  1055. sabActions(start,limit,'speedlimit');
  1056. });
  1057. var hours = Math.floor(queue.secondsremaining / 3600);
  1058. var minutes = pad_zeros(Math.floor((queue.secondsremaining - (hours * 3600)) / 60),2);
  1059. var seconds = pad_zeros((queue.secondsremaining % 60),2);
  1060. $("table.sabInfo td.timeleft").html("<strong>"+hours+":"+minutes+":"+seconds+"</strong>");
  1061. var eta = "-";
  1062. if (queue.secondsremaining != 0)
  1063. {
  1064. var estimate = new Date();
  1065. estimate.setSeconds(estimate.getSeconds() + queue.secondsremaining);
  1066. eta = estimate.toLocaleString();
  1067. }
  1068. $("table.sabInfo td.eta").html("<strong>"+eta+"</strong>");
  1069. $("table.sabInfo td.mb").html("<strong>"+queue.mbremaining+"</strong> / <strong>"+queue.mbsize+"</strong> <t>MB</t>");
  1070. // make sure we don't try to show more items than available in the queue
  1071. while (start > queue.nrofdownloads) {start -= limit;}
  1072. // a start value lower than one is invalid
  1073. if (start < 1) {start = 1;}
  1074. var end = start+limit-1;
  1075. $("table.sabQueue").empty();
  1076. if(queue.nrofdownloads == 0) {
  1077. $("table.sabQueue").html("<tr><td class='info'><t>No items in queue</t></td></tr>");
  1078. } else {
  1079. var index = 0;
  1080. $.each(queue.slots, function(){
  1081. var slot = this;
  1082. index++;
  1083. if ((index >= start) && (index <= end))
  1084. {
  1085. if(slot.percentage == 0) {var progress = " empty"} else {var progress = "";}
  1086. $("table.sabQueue").append("<tr class='title "+index+"'><td><span class='move'><a class='up' title='<t>Up</t>'></a><a class='down' title='<t>Down</t>'></a></span><span class='delete'><a title='<t>Delete from queue</t>'></a></span><strong>"+index+".</strong><span class='title'>"+slot.filename+"</span></td></tr>");
  1087. $("table.sabQueue").append("<tr class='progressBar'><td><div class='progressBar"+progress+"' title='"+slot.mbremaining+" / "+slot.mbsize+" MB' style='width:"+slot.percentage+"%'></div></td></tr>");
  1088. $("table.sabQueue tr."+index+" a.up").click(function(){
  1089. if(timeOut) {clearTimeout(timeOut)};
  1090. sabActions(start,limit,'up', slot.id);
  1091. });
  1092. $("table.sabQueue tr."+index+" a.down").click(function(){
  1093. if(timeOut) {clearTimeout(timeOut)};
  1094. sabActions(start,limit,'down', slot.id);
  1095. });
  1096. $("table.sabQueue tr."+index+" span.delete a").click(function(){
  1097. if(timeOut) {clearTimeout(timeOut)};
  1098. if(start+1 > queue.nrofdownloads-1) {
  1099. sabActions(start-(limit-start),limit-(limit-start),'delete', slot.id);
  1100. } else {
  1101. sabActions(start,limit,'delete', slot.id);
  1102. }
  1103. });
  1104. }
  1105. });
  1106. }
  1107. if(queue.nrofdownloads != 0 && queue.nrofdownloads > end) {
  1108. $("table.sabQueue").append("<tr class='nav'><td><t>Show %1 till %2 from a total of %3 results</t></td></tr>".replace('%1', start).replace('%2', end).replace('%3', queue.nrofdownloads));
  1109. } else if(queue.nrofdownloads != 0 && end > queue.nrofdownloads) {
  1110. if(queue.nrofdownloads == 1) {
  1111. $("table.sabQueue").append("<tr class='nav'><td><t>Show 1 result</t></td></tr>");
  1112. } else {
  1113. $("table.sabQueue").append("<tr class='nav'><td><t>Show %1 till %2 from a total of %3 results</t></td></tr>".replace('%1', start).replace('%2', queue.nrofdownloads).replace('%3', queue.nrofdownloads));
  1114. }
  1115. } else if(queue.nrofdownloads != 0 && end == queue.nrofdownloads) {
  1116. $("table.sabQueue").append("<tr class='nav'><td><t>Show %1 till %2 from a total of %3 results/t></td></tr>".replace('%1', start).replace('%2', end).replace('%3', queue.nrofdownloads));
  1117. }
  1118. if(queue.nrofdownloads == 1) {
  1119. $("table.sabQueue tr.title td span.move").hide();
  1120. } else {
  1121. if (start == 1){
  1122. $("table.sabQueue tr.title td span.move").first().css('padding', '2px 4px 3px 0').children("a.up").hide();
  1123. }
  1124. if (end >= queue.nrofdownloads){
  1125. $("table.sabQueue tr.title td span.move").last().css('padding', '2px 4px 3px 0').children("a.down").hide();
  1126. }
  1127. }
  1128. if(start > 1) {
  1129. $("table.sabQueue tr.nav td").prepend("<a class='prev' title='<t>Previous</t>'>&lt;&lt;</a> ");
  1130. }
  1131. if(queue.nrofdownloads > end) {
  1132. $("table.sabQueue tr.nav td").append(" <a class='next' title='<t>Next</t>'>&gt;&gt;</a>");
  1133. }
  1134. $("table.sabQueue tr.nav a").click(function(){
  1135. if(timeOut) {clearTimeout(timeOut)}
  1136. if($(this).hasClass("prev")) {
  1137. updateSabPanel(start-limit,limit);
  1138. } else if($(this).hasClass("next")) {
  1139. updateSabPanel(start+limit,limit);
  1140. }
  1141. });
  1142. $("tr.title td span.title").mouseenter(function(){
  1143. $(this).addClass("hover");
  1144. }).mouseleave(function(){
  1145. if($(this).hasClass("hover")) {
  1146. if(timeOut) {clearTimeout(timeOut)}
  1147. $(this).removeClass("hover");
  1148. updateSabPanel(start,limit);
  1149. }
  1150. });
  1151. var interval = 5000;
  1152. drawGraph(queue.bytepersec/1024, interval);
  1153. var timeOut = setTimeout(function(){
  1154. if($("div.sabnzbdPanel").is(":visible") && !($("td.speedlimit input[name=speedLimit]").hasClass("hasFocus")) && !($("tr.title td span.title").hasClass("hover"))) {
  1155. updateSabPanel(start,limit);
  1156. }
  1157. }, interval);
  1158. });
  1159. }
  1160. /*
  1161. * Haalt uit een bestaande filter URL de opgegeven filter via
  1162. * string replacement
  1163. */
  1164. function removeFilter(href, fieldname, operator, value) {
  1165. href = unescape(href).replace(/\+/g, ' ');
  1166. return href.replace('search[value][]=' + fieldname + ':' + operator + ':' + value, '');
  1167. } // removeFilter
  1168. /*
  1169. * Submit het zoek formulier
  1170. */
  1171. function submitFilterBtn(searchform) {
  1172. var valelems = searchform.elements['search[value][]'];
  1173. // We zetten nu de filter om naar een moderner soort filter
  1174. for (var i=0; i < searchform.elements['search[type]'].length; i++) {
  1175. if (searchform.elements['search[type]'][i].checked) {
  1176. var rad_val = searchform.elements['search[type]'][i].value;
  1177. } // if
  1178. } // for
  1179. //
  1180. // we voegen nu onze input veld als hidden waarde toe zodat we
  1181. // altijd op dezelfde manier de query parameters opbouwen.
  1182. //
  1183. // Als er geen textfilter waarde is, submitten we hem ook niet
  1184. if (searchform.elements['search[text]'].value.trim().length > 0) {
  1185. $('<input>').attr({
  1186. type: 'hidden',
  1187. name: 'search[value][]',
  1188. value: rad_val + ':=:' + searchform.elements['search[text]'].value
  1189. }).appendTo('form#filterform');
  1190. } // if
  1191. // en vewijder de oude manier
  1192. $('form#filterform').find('input[name=search\\[text\\]]').remove();
  1193. $('form#filterform').find('input[name=search\\[type\\]]').remove();
  1194. // nu selecteren we alle huidige search values, als de include filters
  1195. // knop is ingedrukt dan doen we er niks mee, anders filteren we die
  1196. if ($('#searchfilter-includeprevfilter-toggle').val() != 'true') {
  1197. $('form#filterform [data-currentfilter="true"]').each(function(index, value) {
  1198. $(value).remove();
  1199. });
  1200. } // if
  1201. // eventueel lege values die gesubmit worden door de age dropdown
  1202. // ook filteren
  1203. $('form#filterform').find('select[name=search\\[value\\]\\[\\]]').filter(':input[value=""]').remove();
  1204. // de checkbox die aangeeft of we willen filteren of niet moeten we ook niet submitten
  1205. $('#searchfilter-includeprevfilter-toggle').remove();
  1206. // als de slider niet gewijzigd is van de default waardes, dan submitten
  1207. // we heel de slider niet
  1208. if ($('#min-filesize').val() == 'filesize:>:0') {
  1209. $('form#filterform').find('#min-filesize').remove();
  1210. } // if
  1211. if ($('#max-filesize').val() == 'filesize:<:375809638400') {
  1212. $('form#filterform').find('#max-filesize').remove();
  1213. } // if
  1214. // we use 21 reports as a magic value to say 'disable reporting'
  1215. if ($('#max-reportcount').val() == 'reportcount:<=:21') {
  1216. $('form#filterform').find('#max-reportcount').remove();
  1217. } // if
  1218. return true;
  1219. } // submitFilterBtn
  1220. function format_size(size) {
  1221. var sizes = ['<t>B</t>', '<t>KB</t>', '<t>MB</t>', '<t>GB</t>', '<t>TB</t>', '<t>PB</t>', '<t>EB</t>', '<t>ZB</t>', '<t>YB</t>'];
  1222. var i = 0;
  1223. while(size >= 1024) {
  1224. size /= 1024;
  1225. ++i;
  1226. }
  1227. return size.toFixed(1) + ' ' + sizes[i];
  1228. }
  1229. function pad_zeros(num, size) {
  1230. var s = num+"";
  1231. while (s.length < size) s = "0" + s;
  1232. return s;
  1233. }
  1234. function bindSelectedSortableFilter() {
  1235. /* Koppel de nestedSortable aan de sortablefilterlist */
  1236. var $sortablefilterlist = $('#sortablefilterlist');
  1237. if ($sortablefilterlist) {
  1238. $sortablefilterlist.nestedSortable({
  1239. opacity: .6,
  1240. tabSize: 15,
  1241. forcePlaceholderSize: true,
  1242. forceHelperSize: true,
  1243. maxLevels: 4,
  1244. helper: 'clone',
  1245. items: 'li',
  1246. tabSize: 25,
  1247. listType: 'ul',
  1248. handle: 'div',
  1249. placeholder: 'placeholder',
  1250. revert: 250,
  1251. tolerance: 'pointer',
  1252. update: function() {
  1253. var serialized = $sortablefilterlist.nestedSortable('serialize');
  1254. var formdata = 'editfilterform[xsrfid]=' + editfilterformcsrfcookie + '&editfilterform[submitreorder]=true&' + serialized;
  1255. // post de data
  1256. $.ajax({
  1257. type: "POST",
  1258. url: '?page=editfilter',
  1259. dataType: "html",
  1260. data: formdata,
  1261. success: function(xml) {
  1262. // alert(xml);
  1263. } // success
  1264. }); // ajax call om de form te submitten
  1265. }
  1266. });
  1267. } // if
  1268. } // bindSelectedSortableFilter
  1269. /*
  1270. * Function to load the ?page=catsjson data into an
  1271. * selectbox given by the system
  1272. */
  1273. function loadCategoryIntoSelectbox(selectId, titleElm, data, async, doClear) {
  1274. var $selectbox = $("#" + selectId);
  1275. if (titleElm) {
  1276. var $titleElm = $("#" + titleElm);
  1277. } else {
  1278. var $titleElm = null;
  1279. } // else
  1280. if ($selectbox.data('fromurl') == $.toJSON(data)) {
  1281. return ;
  1282. } // if
  1283. $.ajax({
  1284. type: "GET",
  1285. url: "?page=catsjson",
  1286. data: data,
  1287. async: async,
  1288. dataType: "json",
  1289. success: function(msg) {
  1290. $selectbox.data('fromurl', $.toJSON(data));
  1291. var htmlData = '';
  1292. if ($titleElm) {
  1293. $titleElm.text(msg.title);
  1294. } else {
  1295. htmlData += '<optgroup label="' + msg.title + '">';
  1296. } // else
  1297. if (doClear) {
  1298. $selectbox.empty();
  1299. } // if
  1300. $.each(msg.items, function(index, item) {
  1301. htmlData += '<option value="' + index + '">' + item + '</option>';
  1302. });
  1303. if (!$titleElm) {
  1304. htmlData += '</optgroup>';
  1305. } // if
  1306. $selectbox.append(htmlData);
  1307. $selectbox[0].selected = 0;
  1308. if ($selectbox[0].options.length < 2) {
  1309. if ($titleElm) { $titleElm.hide(); }
  1310. $selectbox.hide();
  1311. } else {
  1312. if ($titleElm) { $titleElm.show(); }
  1313. $selectbox.show();
  1314. } // else
  1315. },
  1316. error: function() {
  1317. alert("Failed to loa…

Large files files are truncated, but you can click here to view the full file