refined add new download

This commit is contained in:
hamza zia 2012-08-27 14:12:52 +08:00
parent b0881e8262
commit 4d606f6d14
2 changed files with 22 additions and 20 deletions

View File

@ -73,6 +73,7 @@
} }
</style> </style>
<!--{{{ active downloads template --> <!--{{{ active downloads template -->
<script type="text/mustache" id="download_active_template"> <script type="text/mustache" id="download_active_template">
<div class="row download_item download_active_item" data-gid="{{gid}}" data-settingsName={{sett_name}}> <div class="row download_item download_active_item" data-gid="{{gid}}" data-settingsName={{sett_name}}>
@ -314,6 +315,7 @@
</div> </div>
</script> </script>
<!-- }}} --> <!-- }}} -->
<!--{{{ download settings template start --> <!--{{{ download settings template start -->
<script type="text/mustache" id="download_settings_template"> <script type="text/mustache" id="download_settings_template">
@ -664,7 +666,6 @@
<input type="text" class="input-xlarge" id="newDownload_url" placeholder="http://example.com"/> <input type="text" class="input-xlarge" id="newDownload_url" placeholder="http://example.com"/>
<button class="btn" id="multiple_uris"><i class="icon-plus-sign"></i></button> <button class="btn" id="multiple_uris"><i class="icon-plus-sign"></i></button>
<span class="help-block">URI can be HTTP(S)/FTP/BitTorrent Magnet URI</span> <span class="help-block">URI can be HTTP(S)/FTP/BitTorrent Magnet URI</span>
<ol class="download_urls"></ol>
</div> </div>
</div> </div>
</fieldset> </fieldset>

View File

@ -1,3 +1,4 @@
/* ex: set tabstop=4 */
var graphSize = 15; var graphSize = 15;
var graphData = []; var graphData = [];
var globalGraphData = null; var globalGraphData = null;
@ -256,20 +257,20 @@ $(function() {
} }
}); });
$('#multiple_uris').click(function() { $('#multiple_uris').click(function() {
var url = $('#newDownload_url').val(); if ($('#multiple_uris i').hasClass('icon-plus-sign')) {
var html = '<li>'; var txt = $('#newDownload_url').val();
html += '<span class="uris">'; $('#newDownload_url').replaceWith('<textarea style="width: 270px" id="newDownload_url" rows="5"></textarea>');
html += url; if (txt.trim().length)
html += '</span>'; $('#newDownload_url').val(txt + '\n');
html += ' '; $('#multiple_uris i').removeClass('icon-plus-sign').addClass('icon-minus-sign');
html += '<a href="#"><i class="icon-trash"></i></a></li>'; }
$(html).appendTo('.download_urls'); else {
$('#newDownload_url').val(""); $('#newDownload_url').replaceWith('<input type="text" class="input-xlarge" id="newDownload_url" placeholder="http://example.com"/>');
$('.download_urls a').unbind('click').click(function() { $('#multiple_uris i').removeClass('icon-minus-sign').addClass('icon-plus-sign');
$(this).parents('li').remove(); }
});
}); });
$('#addNewDownload').click(newDownload); $('#addNewDownload').click(newDownload);
setInterval(update_ui, 1000); setInterval(update_ui, 1000);
}); });
function check_global(name) { function check_global(name) {
@ -415,14 +416,14 @@ function addDownload(uris) {
} }
function newDownload() { function newDownload() {
var li = $('.download_urls li'); var urls = $('#newDownload_url').val().split('\n')
var urls = []; .map(function(e) {
for(var i = 0; i < li.length; i++) { return e.trim();
urls.push($(li[i]).text().trim()); })
.filter(function(e) {
return e.length;
});
}
var inp_url = $('#newDownload_url').val().trim();
if(inp_url.length > 0) urls.push(inp_url);
addDownload([urls]); addDownload([urls]);
} }