Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support changeUri api #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@
margin-left: -25px;
}
#ib-files ul,
#ib-uris ul,
#ib-options ul {
margin-top: 5px;
}
Expand Down Expand Up @@ -387,6 +388,33 @@
#ib-options li > * {
float: left;
}

#ib-uris {
margin-bottom: 50px;
}
.uri-list ul {
margin-left: 0;
list-style-type: none;
}
.uri-list li {
line-height: 16px;
padding-bottom: 6px;
vertical-align: top;
border-bottom: 1px solid #FFF;
}
.uri-list li > span {
display: block;
}
.uri-list li > .select-box {
float: left;
}
.uri-list li > .uri {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
margin-left: 20px;
margin-right: 20px;
}
#ib-peers .ip_port {
display: inline-block;
width: 250px;
Expand Down
32 changes: 31 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ <h2>Settings</h2>
<li class="active"><a href="#ib-status" data-toggle="tab">Status</a></li>
<li><a href="#ib-files" data-toggle="tab">Files</a></li>
<li><a id="ib-options-a" href="#ib-options" data-toggle="tab">Options</a></li>
<li><a id="ib-peers-a" class="hide" style="display:none;" href="#ib-peers" data-toggle="tab">Peers</a></li>
<li class="hide"><a id="ib-uris-a" href="#ib-uris" data-toggle="tab">Uris</a></li>
<li class="hide"><a id="ib-peers-a" href="#ib-peers" data-toggle="tab">Peers</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="ib-status"> </div>
Expand All @@ -328,6 +329,15 @@ <h2>Settings</h2>
</div>
</div>
<div class="tab-pane" id="ib-options"> </div>
<div class="tab-pane" id="ib-uris">
<div class="uri-list">
</div>
<div id="ib-uri-btn">
<input class="span8" type="text">
<button id="ib-uri-add" class="btn" type="button">Add</button>
<button id="ib-uri-save" class="btn btn-primary" type="button">Save</button>
</div>
</div>
<div class="tab-pane" id="ib-peers"> </div>
</div>
</div>
Expand Down Expand Up @@ -369,6 +379,26 @@ <h2>Settings</h2>
</form>
</script>

<script id="ib-uris-tpl" type="text/mustache-template">
<ul>
{{#.}}
<li data-uri="{{uri}}">
<span class="select-box icon-ok"></span>
<span class="uri"><a href="{{uri}}">{{uri}}</a></span>
</li>
{{/.}}
</ul>
</script>

<script id="ib-uri-new-tpl" type="text/mustache-template">
{{#.}}
<li data-uri="{{uri}}">
<span class="select-box icon-plus"></span>
<span class="uri"><a href="{{uri}}">{{uri}}</a></span>
</li>
{{/.}}
</script>

<script id="ib-peers-tpl" type="text/mustache-template">
{{#.}}
<li><span class="ip_port">{{ip}}:{{port}} - <span class="peerid">{{#_v.format_peerid}}{{peerId}}{{/_v.format_peerid}}</span></span> <b>{{#_v.bitfield_to_percent}}{{bitfield}}{{/_v.bitfield_to_percent}}%</b> <i class="icon-download"></i>{{#_v.format_size}}{{downloadSpeed}}{{/_v.format_size}}/s <i class="icon-upload"></i>{{#_v.format_size}}{{uploadSpeed}}{{/_v.format_size}}/s</li>
Expand Down
13 changes: 12 additions & 1 deletion js/aria2.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,14 @@ if (typeof ARIA2=="undefined"||!ARIA2) var ARIA2=(function(){
return results;
},

change_uri: function(gid, fileIndex, delUris, addUris) {
ARIA2.request("changeUri", [gid, fileIndex, delUris, addUris],
function(result) {
ARIA2.get_status(gid);
}
);
},

change_pos: function(gid, pos, how) {
ARIA2.request("changePosition", [gid, pos, how],
function(result) {
Expand Down Expand Up @@ -757,7 +765,10 @@ if (typeof ARIA2=="undefined"||!ARIA2) var ARIA2=(function(){
if ($("#task-gid-"+gid).attr("data-status") == "active")
$("#ib-file-save").hide();
if (result.bittorrent) {
$("#ib-peers-a").show();
$("#ib-peers-a").parent().show();
} else {
$("#ib-uris-a").parent().show();
$("#ib-uris .uri-list").empty().append(YAAW.tpl.ib_uris(result.files[0].uris));
}
}
);
Expand Down
31 changes: 31 additions & 0 deletions js/yaaw.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,37 @@ var YAAW = (function() {
ARIA2.get_options($(".info-box").attr("data-gid"));
});

$("#ib-uris .select-box:not(.icon-plus)").live("click", function() {
$(this).toggleClass("icon-ok icon-remove");
});
$("#ib-uris .select-box.icon-plus").live("click", function() {
$(this).parent().remove();
});

$("#ib-uri-add").live("click", function() {
var $this = $(this);
var uri = $this.prev().val();
if (!uri.startsWith('http')) {
return;
}

$this.parent().prev().children("ul").append(YAAW.tpl.ib_uri_new({uri: uri}));
});

$("#ib-uri-save").live("click", function() {
var delUris = [];
$("#ib-uris .select-box.icon-remove").each(function(i, n) {
delUris.push($(n).parent().data("uri"))
});

var addUris = [];
$("#ib-uris .select-box.icon-plus").each(function(i, n) {
addUris.push($(n).parent().data("uri"))
});

ARIA2.change_uri($(this).parents(".info-box").data("gid"), 1, delUris, addUris);
})

$("#ib-peers-a").live("click", function() {
ARIA2.get_peers($(".info-box").attr("data-gid"));
});
Expand Down