123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- window.setInterval(function(){
- refreshUpDownTotal();
- refreshList();
- }, 5000);
- $(document).ready(function() {
- $.ajaxSetup({ cache: false });
- $(".share-torrent").click(function() {
- var hash = $(this).attr("data-torrent-id");
- $.ajax({
- type: "POST",
- url: "share",
- data: { hash: hash }
- })
- .done(function( msg ) {
- var resp = $.parseJSON(msg);
- $(".share-torrent-link").val(resp.url);
- $(".share-torrent-name").text(resp.name);
- $('#shareModal').foundation('reveal', 'open');
- });
- });
- $(".del-torrent").click(function() {
- var hash = $(this).attr("data-torrent-id");
- var obj = $(this);
- $.ajax({
- type: "POST",
- url: "api/delete",
- data: { hash: hash }
- })
- .done(function( msg ) {
- if( msg == "OK" ) {
- obj.parent().parent().fadeOut("slow", function(){
- alertify.success("Torrent deleted !");
- obj.parent().parent().remove();
- });
- } else {
- alertify.error("There is an error, I can't delete this torrent :(");
- }
- });
- });
- $("#form-add-link").submit(function ( event ){
- // Stop form from submitting normally
- event.preventDefault();
- // Get some values from elements on the page:
- var $form = $( this ),
- torrent = $form.find( "input[name='link']" ).val(),
- url = $form.attr( "action" );
- // Send the data using post
- var posting = $.post( url, { link: torrent } );
- // Put the results in a div
- posting.done(function( data ) {
- alertify.success( data );
- });
- });
-
- refreshList();
- refreshUpDownTotal();
- diskInfo();
- });
- function refreshUpDownTotal() {
- $.getJSON( "api/get_updown_total", function( data ) {
- $("#up-info").text(bytesToSize(data["up"], true));
- $("#down-info").text(bytesToSize(data["down"], true));
- });
- }
- function refreshList(){
- $.getJSON( "api/get_list", function ( data ) {
- $.each( data, function( key, val ) {
- percent = (val['completed_bytes'] / val['size_bytes']) * 100;
-
- if(percent == 100) {
- space = bytesToSize(val['size_bytes'], false);
- } else {
- space = bytesToSize(val['completed_bytes'], false) + ' | ' + bytesToSize(val['size_bytes'], false);
- }
-
- $("tr[data-torrent-id='" + val['hash'] + "'] > td.name").css('background', 'linear-gradient(to right, #43ac6a ' + percent + '%, #f9f9f9 ' + percent + '%, #f9f9f9');
- $("tr[data-torrent-id='" + val['hash'] + "'] > td > span.space").html(space);
- $("tr[data-torrent-id='" + val['hash'] + "'] > td.ratio").html(val['ratio']/1000);
- $("tr[data-torrent-id='" + val['hash'] + "'] > td.downspeed").html(bytesToSize(val['down'], true));
- $("tr[data-torrent-id='" + val['hash'] + "'] > td.upspeed").html(bytesToSize(val['up'], true));
- });
- });
- }
- function diskInfo(){
- $.getJSON( "api/get_diskinfo", function ( data ) {
- percent = 100 - (data['free'] / data['total'] * 100);
- $(".disk-info > .text-info").html(bytesToSize(data['free'], false) + ' Free');
- $(".disk-bar > .inner-bar").css('width', percent + '%');
- });
- }
- function bytesToSize(bytes, speed) {
- var sizes = ['o', 'Ko', 'Mo', 'Go', 'To'];
- var speeds = ['o/s', 'Ko/s', 'Mo/s'];
- if (bytes == 0) return '-';
- var i = parseFloat(Math.floor(Math.log(bytes) / Math.log(1024)));
- if(speed) {
- return Math.round(bytes / Math.pow(1024, i) * 10) / 10 + ' ' + speeds[i];
- } else {
- return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i];
- }
- }
- function poppupAddTorrent(){
- window.open("/add", "Ajout d'un torrent", config='height=100, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no');
- }
|