added dynamic global settings functionality

This commit is contained in:
Hamza Zia 2012-06-07 01:43:51 +08:00
parent 8501ccde77
commit d006bdeab1
3 changed files with 42 additions and 18 deletions

View File

@ -133,7 +133,7 @@
{{^has_value}} {{^has_value}}
<select id="input_settings_{{name}}"> <select id="input_settings_{{name}}">
<option value=" ">Default</option> <option value="no_val">Default</option>
{{/has_value}} {{/has_value}}
{{/option}} {{/option}}
@ -314,7 +314,7 @@
</form> </form>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button id="save_global_settings" class="btn btn-success" onclick="alert('not implemented yet');">Save</button> <button id="save_global_settings" class="btn btn-success">Save</button>
</div> </div>
</div> </div>
<!-- global settings template end }}}--> <!-- global settings template end }}}-->

View File

@ -137,12 +137,6 @@ var input_file_settings = [
}, },
{ {
name: "check-integrity", name: "check-integrity",
desc: "sample",
option:true,
options: ["true", "false"]
},
{
name: "sample",
desc: "Check file integrity by validating piece hashes or a hash of entire file. This option has effect only in BitTorrent, Metalink downloads with checksums or HTTP(S)/FTP downloads with --checksum option. If piece hashes are provided, this option can detect damaged portions of a file and re-download them. If a hash of entire file is provided, hash check is only done when file has been already download. This is determined by file length. If hash check fails, file is re-downloaded from scratch. If both piece hashes and a hash of entire file are provided, only piece hashes are used. Default: false", desc: "Check file integrity by validating piece hashes or a hash of entire file. This option has effect only in BitTorrent, Metalink downloads with checksums or HTTP(S)/FTP downloads with --checksum option. If piece hashes are provided, this option can detect damaged portions of a file and re-download them. If a hash of entire file is provided, hash check is only done when file has been already download. This is determined by file length. If hash check fails, file is re-downloaded from scratch. If both piece hashes and a hash of entire file are provided, only piece hashes are used. Default: false",
option:true, option:true,
options: ["true", "false"] options: ["true", "false"]
@ -200,6 +194,7 @@ var input_file_settings = [
{ {
name: "file-allocation", name: "file-allocation",
desc: "Specify file allocation method. none doesn't pre-allocate file space. prealloc pre-allocates file space before download begins. This may take some time depending on the size of the file. If you are using newer file systems such as ext4 (with extents support), btrfs, xfs or NTFS(MinGW build only), falloc is your best choice. It allocates large(few GiB) files almost instantly. Don't use falloc with legacy file systems such as ext3 and FAT32 because it takes almost same time as prealloc and it blocks aria2 entirely until allocation finishes. falloc may not be available if your system doesn't have posix_fallocate(3) function. Possible Values: none, prealloc, falloc Default: prealloc", desc: "Specify file allocation method. none doesn't pre-allocate file space. prealloc pre-allocates file space before download begins. This may take some time depending on the size of the file. If you are using newer file systems such as ext4 (with extents support), btrfs, xfs or NTFS(MinGW build only), falloc is your best choice. It allocates large(few GiB) files almost instantly. Don't use falloc with legacy file systems such as ext3 and FAT32 because it takes almost same time as prealloc and it blocks aria2 entirely until allocation finishes. falloc may not be available if your system doesn't have posix_fallocate(3) function. Possible Values: none, prealloc, falloc Default: prealloc",
option: true,
options: ["none", "prealloc", "falloc"] options: ["none", "prealloc", "falloc"]
}, },
{ {

View File

@ -121,7 +121,7 @@ $(function() {
html += '<a href="#"><i class="icon-trash"></i></a></li>'; html += '<a href="#"><i class="icon-trash"></i></a></li>';
$(html).appendTo('.download_urls'); $(html).appendTo('.download_urls');
$('#newDownload_url').val(""); $('#newDownload_url').val("");
$('.download_urls a').click(function() { $('.download_urls a').unbind('click').click(function() {
$(this).parents('li').remove(); $(this).parents('li').remove();
}); });
}); });
@ -137,15 +137,15 @@ function check_global(name) {
} }
function get_global_settings(cb) { function get_global_settings(cb) {
var sets = []; var sets = [];
var tmp_set; var tmp_set = [];
for(var i = 0; i < input_file_settings.length; i++) { for(var i = 0; i < input_file_settings.length; i++) {
tmp_set = input_file_settings[i]; tmp_set = $.extend(true, {}, input_file_settings[i]);
if(check_global(tmp_set)) { if(check_global(tmp_set)) {
sets.push(tmp_set); sets.push(tmp_set);
} }
} }
for(var i = 0; i < global_settings.length; i++) { for(var i = 0; i < global_settings.length; i++) {
tmp_set = global_settings[i]; tmp_set = $.extend(true, {}, global_settings[i]);
if(check_global(tmp_set)) { if(check_global(tmp_set)) {
sets.push(tmp_set); sets.push(tmp_set);
} }
@ -154,8 +154,7 @@ function get_global_settings(cb) {
func: 'getGlobalOption', func: 'getGlobalOption',
success: function(data) { success: function(data) {
var res = data.result; var res = data.result;
console.log(res); for(var i in res) {
for(var i in data.result) {
for(var j = 0; j < sets.length; j++) { for(var j = 0; j < sets.length; j++) {
if(sets[j].name === i) { if(sets[j].name === i) {
sets[j].value = res[i].trim(); sets[j].value = res[i].trim();
@ -163,10 +162,11 @@ function get_global_settings(cb) {
if(sets[j].option) { if(sets[j].option) {
for(var k = 0; k < sets[j].options.length; k++) { for(var k = 0; k < sets[j].options.length; k++) {
var tmp = { var tmp = {
val: sets[j].options[k].toString(), val: sets[j].options[k],
disp: sets[j].options[k].toString() disp: sets[j].options[k]
}; };
if(sets[j].options[k].toString() === sets[j].value) {
if(sets[j].options[k] === sets[j].value) {
tmp.val = sets[j].value + '" selected="true'; tmp.val = sets[j].value + '" selected="true';
} }
sets[j].options[k] = tmp; sets[j].options[k] = tmp;
@ -185,7 +185,7 @@ function get_global_settings(cb) {
function custom_global_settings() { function custom_global_settings() {
var gen = function(name) { var gen = function(name) {
return { name: name, values: [] }; return { name: name, values: [] };
} };
var general_settings = gen("General Settings"); var general_settings = gen("General Settings");
var torrent_settings = gen("Bit-Torrent Settings"); var torrent_settings = gen("Bit-Torrent Settings");
var ftp_settings = gen("FTP Settings"); var ftp_settings = gen("FTP Settings");
@ -224,6 +224,35 @@ function custom_global_settings() {
}); });
$('#dynamic_global_settings').html(item); $('#dynamic_global_settings').html(item);
modals.global_settings_modal.modal('show'); modals.global_settings_modal.modal('show');
$("#save_global_settings").one('click',function() {
var settings = {};
for(var i = 0; i < sets.length; i++) {
var elem = $("#input_settings_" + sets[i].name);
if(sets[i].value) {
if(elem.val() !== sets[i].value) {
settings[sets[i].name] = elem.val();
}
}
else if(elem.val() !== "no_val" && elem.val() !== "") {
settings[sets[i].name] = elem.val();
}
}
console.log(settings);
if(!$.isEmptyObject(settings)) {
aria_syscall({
func: 'changeGlobalOption',
params: [settings],
success: function(data) {
console.log(data);
clear_dialogs();
}
});
clear_dialogs();
}
else {
clear_dialogs();
}
});
}); });
} }