Skip to content

Commit

Permalink
refactoring html to use bootstrap exclusively
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrogen18 committed Sep 2, 2013
1 parent b1a03e4 commit 2861d71
Show file tree
Hide file tree
Showing 13 changed files with 9,879 additions and 226 deletions.
1,109 changes: 1,109 additions & 0 deletions html/bootstrap/css/bootstrap-responsive.css

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions html/bootstrap/css/bootstrap-responsive.min.css

Large diffs are not rendered by default.

6,167 changes: 6,167 additions & 0 deletions html/bootstrap/css/bootstrap.css

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions html/bootstrap/css/bootstrap.min.css

Large diffs are not rendered by default.

Binary file added html/bootstrap/img/glyphicons-halflings-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added html/bootstrap/img/glyphicons-halflings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,280 changes: 2,280 additions & 0 deletions html/bootstrap/js/bootstrap.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions html/bootstrap/js/bootstrap.min.js

Large diffs are not rendered by default.

95 changes: 47 additions & 48 deletions html/index.html
Original file line number Diff line number Diff line change
@@ -1,55 +1,54 @@
<!DOCTYPE html>
<html>

<head>
<title>
Login
</title>
</head>
<head>
<title>Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen" />
<link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen" />
</head>

<body>

<script src="js/sha.js"></script>
<script src="js/jquery.js"></script>

<script src="js/fairywren.js"></script>
<script src="js/index.js"></script>


<link rel="stylesheet" type="text/css" href="torrents.css">

<div id="main" align="center">

<div id="message" style="color:red;">

</div>

<div id="loginform" class="contentBox" style="text-align:center; align:center;width:17.5em;min-width:16em;">
<div class="contentBoxHeader" style="align:center;">Login</div>
<form>
<table class="alignedform">
<tr >
<td >
<label for="username">Username:</label>
</td>
<td >
<input id="username" type="text" size="24"/>
</td>
</tr>
<tr >
<td >
<label for="password">Password:</label>
</td>
<td >
<input id="password" type="password" size="24"/>
</td>
</tr>

</table>
<input type="submit" value="Login" onclick="Fairywren.login(); return false;"/>
</form>
</div>

</div>
<script src="js/sha.js"></script>
<script src="js/jquery.js"></script>

<script src="js/fairywren.js"></script>
<script src="js/index.js"></script>

<div class="row">

<div class="span4 offset4">
<form class="form-horizontal">

<div class="control-group">
<label class="control-label" for="username">Username:</label>
<div class="controls">
<input id="username" type="text" size="24"/>
</div>
</div>

<div class="control-group">
<label for="password" class="control-label">Password:</label>
<div class="controls">
<input id="password" type="password" size="24"/>
</div>
</div>

<div class="controls">
<input type="submit" value="Login" onclick="Fairywren.login(); return false;"/>
</div>
</form>
</div>
</div>


<div class="row">
<div class="span4 offset4">

<span id="message" class="label label-important"></span>

</div>
</div>

</body>

Expand Down
81 changes: 81 additions & 0 deletions html/js/fairywren.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,87 @@ Fairywren.serverErrorHandler = function(jqXhr,textStatus,errorThrown,element)

}

Fairywren.makeErrorElement = function(msg)
{
var r = $("<div />");
r.addClass('alert');

r.append($("<button />").attr('type','button').addClass('close').attr('data-dismiss','alert').text('\u2A2F'));

r.append(msg);

r.alert();

return r;
}

Fairywren.handleServerFailure = function(errorHolder)
{
var f = function(jqXhr,textStatus,errorThrown)
{
var data = jqXhr.responseText;

if(textStatus === "error")
{
var statusCode = jqXhr.statusCode().status;
if(statusCode > 499)
{
errorHolder.prepend(Fairywren.makeErrorElement("Server error"));
}

else
{
data = jQuery.parseJSON(data);
if ( 'msg' in data )
{
if(data.msg === undefined || data.msg === null)
{
errorHolder.prepend(Fairywren.makeErrorElement(statusCode));
}
else
{
errorHolder.prepend(Fairywren.makeErrorElement(data.msg));
}
}
}
}
else if ( textStatus === "timeout" )
{
errorHolder.prepend(Fairywren.makeErrorElement('Request to server timed out'));
}
}

return f;
}


Fairywren.isError = function(data,errorHolder)
{
if ( ! ('error' in data))
{
return false;
}

if ( false === data.authenticated )
{
window.location = 'index.html';
return true;
}

if ( false === data.authorized )
{
if(errorHolder !== undefined && errorHolder !== null )
{
errorHolder.prepend(Fairywren.makeErrorElement("Not authorized"));
}
else
{
alert('You are not authorized to perform this function');
}
return true;
}
}

Fairywren.errorHandler = function(data)
{
if ( ! 'error' in data )
Expand Down
139 changes: 139 additions & 0 deletions html/js/torrentPaginator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@

function TorrentPaginator(divEle){
this.divEle = divEle;
this.bar = $("<div />");

this.pageIndicator = $("<span />");
this.pageIndicator.addClass('badge');
this.pageIndicator.text('999/999');

var newer = $("<li />").addClass('previous').append(
$("<a />").attr('href','#').text('\u2190Newer'));

var refresh = $("<li />").append(
$("<a />").attr('href','#').css('font-size','2em').append('\u0020\u21bb\u0020').append("<br />").append(this.pageIndicator ));

var older = $("<li />").addClass('next').append(
$("<a />").attr('href','#').text('Older\u2192'));

this.bar.append($("<ul />").addClass('pager').append(newer).append(refresh).append(older));

this.divEle.append(this.bar);

this.table = $("<table />");
this.table.addClass("table table-hover table-bordered");

this.table.append(
$("<thead />").append(
$("<tr />").append(
$("<th />").text('Title')).append(
$("<th />").text('Size')).append(
$("<th />").text('Upload Time')).append(
$("<th />").text('Uploader'))));

this.tableBody = $("<tbody />");

this.table.append(this.tableBody);

this.divEle.append(this.table);

this.pageSize = 20;

this.currentPage = 0;

this.pages = null;

}

TorrentPaginator.prototype.show = function()
{
var newBody = $("<tbody />");

var pageset = this.pages[this.currentPage];

for(i in pageset)
{
var title = pageset[i].title;
var uploadTime = Fairywren.trimIsoFormatDate(pageset[i].creationDate);
var uploader = pageset[i].creator.name;
var downloadUrl = pageset[i].metainfo.href;
var lengthInBytes = pageset[i].lengthInBytes;
var seeds = pageset[i].seeds;
var leeches = pageset[i].leeches;

var adjustedLength = Fairywren.bytesToPrettyPrint(lengthInBytes);

var titleSpan = $("<span />");
titleSpan.attr('class','torrentLink');
var infoHref = pageset[i].info.href;
titleSpan.click(infoHref,function(event){
Fairywren.torrentTab.display(event.data);
});
titleSpan.attr('style','white-space:nowrap;');
titleSpan.text(title);

var row = $("<tr />");
var titleData = $("<td />");
titleData.append(titleSpan);

titleData.append('<span style="float:right;">&nbsp;<span >'+ '&uarr;' + seeds + '&nbsp;&darr;' + leeches + '</span><a class="downloadLink" href="' + downloadUrl + '">Download</a>\
</span>');

row.append(titleData);

row.append('<td>' + adjustedLength + '</td>\
<td>' + uploadTime + "</td>\
<td>" + uploader + "</td>");

newBody.append(row);
}

this.table.find('tbody').remove();
this.table.append(newBody);

this.pageIndicator.text( (this.currentPage + 1) + '/' + this.pages.length);
}

TorrentPaginator.prototype.flipPage = function(movement)
{

}

TorrentPaginator.prototype.loadTorrentsForPage = function(clearCache)
{
if( ! (clearCache === undefined || clearCache === null) && clearCache)
{
this.pages = null;
}
var page = this.currentPage;

var self = this;
if(this.pages === null || this.pages[page] === null)
{
jQuery.get("api/torrents",{'resultSize':this.pageSize,'subset':page}).

done(function(data)
{
if( ! Fairywren.isError(data) )
{
var numPages = data.numSubsets;
if(self.pages === null || self.pages.length != numPages)
{
self.pages = [];
for(var i= 0; i < numPages ; ++i)
{
self.pages.push(null);
}
}

self.pages[page] = data.torrents;
self.show();
}
}).
fail(Fairywren.handleServerFailure(this.divEle));
}
else
{
this.show();
}
}
13 changes: 7 additions & 6 deletions html/js/torrents.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Fairywren.torrents = {}

$(document).ready(function(){
jQuery.ajaxSettings.traditional = true;
var p = new TorrentPaginator($("#newestTorrents"));
p.loadTorrentsForPage();


return;

Fairywren.search.init();
Fairywren.torrents.init();
Expand Down Expand Up @@ -210,18 +215,14 @@ Fairywren.clearAndRenderTorrents = function(torrentTable,pageset)
<td>' + uploadTime + "</td>\
<td>" + uploader + "</td>");

torrentTable.find("tr:last").after(row);


torrentTable.find("tbody").after(row);
}


}

Fairywren.showTorrents = function()
{

var torrentTable = $("#torrents").find("#torrentTable");
var torrentTable = $("#torrentTable");

var page = Fairywren.torrents.page;
$("#pageNumbers").text((page +1 )+ ' / ' + Fairywren.torrents.numPages);
Expand Down
Loading

0 comments on commit 2861d71

Please sign in to comment.