2014-03-10 01:18:05 -04:00
|
|
|
$(document).ready(function(){
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
$.fn.showHideProviders = function() {
|
|
|
|
$('.providerDiv').each(function(){
|
2014-03-10 01:18:05 -04:00
|
|
|
var providerName = $(this).attr('id');
|
|
|
|
var selectedProvider = $('#editAProvider :selected').val();
|
|
|
|
|
2014-10-28 20:50:38 -04:00
|
|
|
if (selectedProvider + 'Div' == providerName) {
|
2014-03-10 01:18:05 -04:00
|
|
|
$(this).show();
|
2014-10-28 20:50:38 -04:00
|
|
|
} else {
|
2014-03-10 01:18:05 -04:00
|
|
|
$(this).hide();
|
2014-10-28 20:50:38 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
});
|
2014-03-20 14:03:22 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-09-11 04:47:59 -04:00
|
|
|
/**
|
|
|
|
* Gets categories for the provided newznab provider.
|
|
|
|
* @param {String} isDefault
|
|
|
|
* @param {Array} selectedProvider
|
|
|
|
* @return no return data. Function updateNewznabCaps() is run at callback
|
|
|
|
*/
|
|
|
|
$.fn.getCategories = function (isDefault, selectedProvider) {
|
|
|
|
|
|
|
|
var name = selectedProvider[0];
|
|
|
|
var url = selectedProvider[1];
|
|
|
|
var key = selectedProvider[2];
|
|
|
|
|
2014-09-01 11:57:52 -04:00
|
|
|
if (!name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!url)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!key)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var params = {url: url, name: name, key: key};
|
|
|
|
var returnData;
|
|
|
|
|
|
|
|
$.getJSON(sbRoot + '/config/providers/getNewznabCategories', params,
|
|
|
|
function(data){
|
2014-12-24 10:48:36 -05:00
|
|
|
$(this).updateNewznabCaps( data, selectedProvider );
|
2014-09-01 11:57:52 -04:00
|
|
|
console.debug(data.tv_categories);
|
|
|
|
});
|
2014-12-24 10:48:36 -05:00
|
|
|
};
|
2014-09-01 11:57:52 -04:00
|
|
|
|
|
|
|
$.fn.addProvider = function (id, name, url, key, cat, isDefault, showProvider) {
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
url = $.trim(url);
|
|
|
|
if (!url)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!/^https?:\/\//i.test(url))
|
|
|
|
url = "http://" + url;
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
if (url.match('/$') == null)
|
|
|
|
url = url + '/';
|
|
|
|
|
2014-09-01 11:57:52 -04:00
|
|
|
var newData = [isDefault, [name, url, key, cat]];
|
2014-03-10 01:18:05 -04:00
|
|
|
newznabProviders[id] = newData;
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
if (!isDefault){
|
2014-03-10 01:18:05 -04:00
|
|
|
$('#editANewznabProvider').addOption(id, name);
|
|
|
|
$(this).populateNewznabSection();
|
|
|
|
}
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
if ($('#provider_order_list > #'+id).length == 0 && showProvider != false) {
|
2014-11-08 21:49:38 -05:00
|
|
|
var toAdd = '<li class="ui-state-default" id="' + id + '"> <input type="checkbox" id="enable_' + id + '" class="provider_enabler" CHECKED> <a href="' + anonURL + url + '" class="imgLink" target="_new"><img src="' + sbRoot
|
|
|
|
+ '/images/providers/newznab.png" alt="' + name + '" width="16" height="16"></a> ' + name + '</li>'
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
$('#provider_order_list').append(toAdd);
|
|
|
|
$('#provider_order_list').sortable("refresh");
|
|
|
|
}
|
|
|
|
|
|
|
|
$(this).makeNewznabProviderString();
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-05-25 03:28:13 -04:00
|
|
|
$.fn.addTorrentRssProvider = function (id, name, url, cookies) {
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-05-25 03:28:13 -04:00
|
|
|
var newData = [name, url, cookies];
|
2014-03-10 01:18:05 -04:00
|
|
|
torrentRssProviders[id] = newData;
|
|
|
|
|
|
|
|
$('#editATorrentRssProvider').addOption(id, name);
|
|
|
|
$(this).populateTorrentRssSection();
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
if ($('#provider_order_list > #'+id).length == 0) {
|
2014-11-08 21:49:38 -05:00
|
|
|
var toAdd = '<li class="ui-state-default" id="' + id + '"> <input type="checkbox" id="enable_' + id + '" class="provider_enabler" CHECKED> <a href="' + anonURL + url + '" class="imgLink" target="_new"><img src="' + sbRoot
|
|
|
|
+ '/images/providers/torrentrss.png" alt="' + name + '" width="16" height="16"></a> ' + name + '</li>'
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
$('#provider_order_list').append(toAdd);
|
|
|
|
$('#provider_order_list').sortable("refresh");
|
|
|
|
}
|
|
|
|
|
|
|
|
$(this).makeTorrentRssProviderString();
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-09-01 11:57:52 -04:00
|
|
|
$.fn.updateProvider = function (id, url, key, cat) {
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
newznabProviders[id][1][1] = url;
|
|
|
|
newznabProviders[id][1][2] = key;
|
2014-09-01 11:57:52 -04:00
|
|
|
newznabProviders[id][1][3] = cat;
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
$(this).populateNewznabSection();
|
|
|
|
|
|
|
|
$(this).makeNewznabProviderString();
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
$.fn.deleteProvider = function (id) {
|
|
|
|
|
|
|
|
$('#editANewznabProvider').removeOption(id);
|
|
|
|
delete newznabProviders[id];
|
|
|
|
$(this).populateNewznabSection();
|
2014-03-20 14:03:22 -04:00
|
|
|
$('li').remove('#'+id);
|
2014-03-10 01:18:05 -04:00
|
|
|
$(this).makeNewznabProviderString();
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-05-25 03:28:13 -04:00
|
|
|
$.fn.updateTorrentRssProvider = function (id, url, cookies) {
|
2014-03-10 01:18:05 -04:00
|
|
|
torrentRssProviders[id][1] = url;
|
2014-05-25 03:28:13 -04:00
|
|
|
torrentRssProviders[id][2] = cookies;
|
2014-03-10 01:18:05 -04:00
|
|
|
$(this).populateTorrentRssSection();
|
|
|
|
$(this).makeTorrentRssProviderString();
|
2014-03-20 14:03:22 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
$.fn.deleteTorrentRssProvider = function (id) {
|
|
|
|
$('#editATorrentRssProvider').removeOption(id);
|
|
|
|
delete torrentRssProviders[id];
|
|
|
|
$(this).populateTorrentRssSection();
|
2014-03-20 14:03:22 -04:00
|
|
|
$('li').remove('#'+id);
|
2014-03-10 01:18:05 -04:00
|
|
|
$(this).makeTorrentRssProviderString();
|
2014-03-20 14:03:22 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
$.fn.populateNewznabSection = function() {
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
var selectedProvider = $('#editANewznabProvider :selected').val();
|
|
|
|
|
|
|
|
if (selectedProvider == 'addNewznab') {
|
2014-03-20 14:03:22 -04:00
|
|
|
var data = ['','',''];
|
2014-03-10 01:18:05 -04:00
|
|
|
var isDefault = 0;
|
|
|
|
$('#newznab_add_div').show();
|
|
|
|
$('#newznab_update_div').hide();
|
2014-09-01 11:57:52 -04:00
|
|
|
$('#newznab_cat').attr('disabled','disabled');
|
|
|
|
$('#newznab_cap').attr('disabled','disabled');
|
|
|
|
|
|
|
|
$("#newznab_cat option").each(function() {
|
|
|
|
$(this).remove();
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#newznab_cap option").each(function() {
|
|
|
|
$(this).remove();
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
} else {
|
|
|
|
var data = newznabProviders[selectedProvider][1];
|
|
|
|
var isDefault = newznabProviders[selectedProvider][0];
|
|
|
|
$('#newznab_add_div').hide();
|
|
|
|
$('#newznab_update_div').show();
|
2014-09-01 11:57:52 -04:00
|
|
|
$('#newznab_cat').removeAttr("disabled");
|
|
|
|
$('#newznab_cap').removeAttr("disabled");
|
2014-03-10 01:18:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$('#newznab_name').val(data[0]);
|
|
|
|
$('#newznab_url').val(data[1]);
|
|
|
|
$('#newznab_key').val(data[2]);
|
2014-09-01 11:57:52 -04:00
|
|
|
|
|
|
|
//Check if not already array
|
|
|
|
if (typeof data[3] === 'string') {
|
|
|
|
rrcat = data[3].split(",")
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rrcat = data[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the category select box (on the right)
|
|
|
|
var newCatOptions = [];
|
|
|
|
if (rrcat) {
|
|
|
|
rrcat.forEach(function (cat) {
|
|
|
|
newCatOptions.push({text : cat, value : cat});
|
|
|
|
});
|
|
|
|
$("#newznab_cat").replaceOptions(newCatOptions);
|
|
|
|
};
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
if (selectedProvider == 'addNewznab') {
|
|
|
|
$('#newznab_name').removeAttr("disabled");
|
|
|
|
$('#newznab_url').removeAttr("disabled");
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$('#newznab_name').attr("disabled", "disabled");
|
|
|
|
|
|
|
|
if (isDefault) {
|
|
|
|
$('#newznab_url').attr("disabled", "disabled");
|
|
|
|
$('#newznab_delete').attr("disabled", "disabled");
|
|
|
|
} else {
|
|
|
|
$('#newznab_url').removeAttr("disabled");
|
|
|
|
$('#newznab_delete').removeAttr("disabled");
|
2014-09-01 11:57:52 -04:00
|
|
|
|
|
|
|
//Get Categories Capabilities
|
|
|
|
if (data[0] && data[1] && data[2] && !ifExists($.fn.newznabProvidersCapabilities, data[0])) {
|
2014-09-11 04:47:59 -04:00
|
|
|
$(this).getCategories(isDefault, data);
|
2014-09-01 11:57:52 -04:00
|
|
|
}
|
2014-09-11 04:47:59 -04:00
|
|
|
else {
|
2015-02-02 14:52:59 -05:00
|
|
|
$(this).updateNewznabCaps( null, data );
|
2014-09-11 04:47:59 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
}
|
|
|
|
}
|
2014-03-20 14:03:22 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-09-01 11:57:52 -04:00
|
|
|
ifExists = function(loopThroughArray, searchFor) {
|
|
|
|
var found = false;
|
|
|
|
|
|
|
|
loopThroughArray.forEach(function(rootObject) {
|
|
|
|
if (rootObject.name == searchFor) {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
console.log(rootObject.name + " while searching for: "+ searchFor);
|
|
|
|
});
|
|
|
|
return found;
|
|
|
|
};
|
|
|
|
|
2014-09-11 04:47:59 -04:00
|
|
|
/**
|
|
|
|
* Updates the Global array $.fn.newznabProvidersCapabilities with a combination of newznab prov name
|
|
|
|
* and category capabilities. Return
|
|
|
|
* @param {Array} newzNabCaps, is the returned object with newzNabprod Name and Capabilities.
|
|
|
|
* @param {Array} selectedProvider
|
|
|
|
* @return no return data. The multiselect input $("#newznab_cap") is updated, as a result.
|
|
|
|
*/
|
2014-12-24 10:48:36 -05:00
|
|
|
$.fn.updateNewznabCaps = function( newzNabCaps, selectedProvider ) {
|
2014-09-11 04:47:59 -04:00
|
|
|
|
|
|
|
if (newzNabCaps && !ifExists($.fn.newznabProvidersCapabilities, selectedProvider[0])) {
|
|
|
|
$.fn.newznabProvidersCapabilities.push({'name' : selectedProvider[0], 'categories' : newzNabCaps.tv_categories});
|
|
|
|
}
|
|
|
|
|
|
|
|
//Loop through the array and if currently selected newznab provider name matches one in the array, use it to
|
|
|
|
//update the capabilities select box (on the left).
|
|
|
|
if (selectedProvider[0]) {
|
|
|
|
$.fn.newznabProvidersCapabilities.forEach(function(newzNabCap) {
|
|
|
|
|
|
|
|
if (newzNabCap.name && newzNabCap.name == selectedProvider[0] && newzNabCap.categories instanceof Array) {
|
|
|
|
var newCapOptions = [];
|
|
|
|
newzNabCap.categories.forEach(function(category_set) {
|
|
|
|
if (category_set.id && category_set.name) {
|
|
|
|
newCapOptions.push({value : category_set.id, text : category_set.name + "(" + category_set.id + ")"});
|
2014-12-24 10:48:36 -05:00
|
|
|
}
|
2014-09-11 04:47:59 -04:00
|
|
|
});
|
|
|
|
$("#newznab_cap").replaceOptions(newCapOptions);
|
|
|
|
}
|
|
|
|
});
|
2014-12-24 10:48:36 -05:00
|
|
|
}
|
|
|
|
};
|
2014-09-11 04:47:59 -04:00
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
$.fn.makeNewznabProviderString = function() {
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
var provStrings = new Array();
|
|
|
|
|
|
|
|
for (var id in newznabProviders) {
|
|
|
|
provStrings.push(newznabProviders[id][1].join('|'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#newznab_string').val(provStrings.join('!!!'))
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
$.fn.populateTorrentRssSection = function() {
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
var selectedProvider = $('#editATorrentRssProvider :selected').val();
|
|
|
|
|
|
|
|
if (selectedProvider == 'addTorrentRss') {
|
2014-05-25 03:28:13 -04:00
|
|
|
var data = ['','',''];
|
2014-03-10 01:18:05 -04:00
|
|
|
$('#torrentrss_add_div').show();
|
|
|
|
$('#torrentrss_update_div').hide();
|
|
|
|
} else {
|
|
|
|
var data = torrentRssProviders[selectedProvider];
|
|
|
|
$('#torrentrss_add_div').hide();
|
|
|
|
$('#torrentrss_update_div').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#torrentrss_name').val(data[0]);
|
|
|
|
$('#torrentrss_url').val(data[1]);
|
2014-05-25 03:28:13 -04:00
|
|
|
$('#torrentrss_cookies').val(data[2]);
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
if (selectedProvider == 'addTorrentRss') {
|
|
|
|
$('#torrentrss_name').removeAttr("disabled");
|
|
|
|
$('#torrentrss_url').removeAttr("disabled");
|
2014-05-25 03:28:13 -04:00
|
|
|
$('#torrentrss_cookies').removeAttr("disabled");
|
2014-03-10 01:18:05 -04:00
|
|
|
} else {
|
|
|
|
$('#torrentrss_name').attr("disabled", "disabled");
|
|
|
|
$('#torrentrss_url').removeAttr("disabled");
|
2014-05-25 03:28:13 -04:00
|
|
|
$('#torrentrss_cookies').removeAttr("disabled");
|
2014-03-10 01:18:05 -04:00
|
|
|
$('#torrentrss_delete').removeAttr("disabled");
|
|
|
|
}
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
$.fn.makeTorrentRssProviderString = function() {
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
var provStrings = new Array();
|
|
|
|
for (var id in torrentRssProviders) {
|
|
|
|
provStrings.push(torrentRssProviders[id].join('|'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#torrentrss_string').val(provStrings.join('!!!'))
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
$.fn.refreshProviderList = function() {
|
2014-03-10 01:18:05 -04:00
|
|
|
var idArr = $("#provider_order_list").sortable('toArray');
|
|
|
|
var finalArr = new Array();
|
2014-03-20 14:03:22 -04:00
|
|
|
$.each(idArr, function(key, val) {
|
|
|
|
var checked = + $('#enable_'+val).prop('checked') ? '1' : '0';
|
2014-03-10 01:18:05 -04:00
|
|
|
finalArr.push(val + ':' + checked);
|
|
|
|
});
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
$("#provider_order").val(finalArr.join(' '));
|
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
var newznabProviders = new Array();
|
|
|
|
var torrentRssProviders = new Array();
|
|
|
|
|
|
|
|
$(this).on('change', '.newznab_key', function(){
|
|
|
|
|
|
|
|
var provider_id = $(this).attr('id');
|
|
|
|
provider_id = provider_id.substring(0, provider_id.length-'_hash'.length);
|
|
|
|
|
|
|
|
var url = $('#'+provider_id+'_url').val();
|
2014-09-01 11:57:52 -04:00
|
|
|
var cat = $('#'+provider_id+'_cat').val();
|
2014-03-10 01:18:05 -04:00
|
|
|
var key = $(this).val();
|
|
|
|
|
2014-09-01 11:57:52 -04:00
|
|
|
$(this).updateProvider(provider_id, url, key, cat);
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#newznab_key,#newznab_url').change(function(){
|
|
|
|
|
|
|
|
var selectedProvider = $('#editANewznabProvider :selected').val();
|
|
|
|
|
|
|
|
if (selectedProvider == "addNewznab")
|
|
|
|
return;
|
|
|
|
|
|
|
|
var url = $('#newznab_url').val();
|
|
|
|
var key = $('#newznab_key').val();
|
|
|
|
|
2014-09-01 11:57:52 -04:00
|
|
|
var cat = $('#newznab_cat option').map(function(i, opt) {
|
|
|
|
return $(opt).text();
|
|
|
|
}).toArray().join(',');
|
|
|
|
|
|
|
|
$(this).updateProvider(selectedProvider, url, key, cat);
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2014-05-25 03:28:13 -04:00
|
|
|
$('#torrentrss_url,#torrentrss_cookies').change(function(){
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
var selectedProvider = $('#editATorrentRssProvider :selected').val();
|
|
|
|
|
|
|
|
if (selectedProvider == "addTorrentRss")
|
|
|
|
return;
|
|
|
|
|
|
|
|
var url = $('#torrentrss_url').val();
|
2014-05-25 03:28:13 -04:00
|
|
|
var cookies = $('#torrentrss_cookies').val();
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-05-25 03:28:13 -04:00
|
|
|
$(this).updateTorrentRssProvider(selectedProvider, url, cookies);
|
2014-03-10 01:18:05 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$('#editAProvider').change(function(){
|
|
|
|
$(this).showHideProviders();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#editANewznabProvider').change(function(){
|
|
|
|
$(this).populateNewznabSection();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#editATorrentRssProvider').change(function(){
|
|
|
|
$(this).populateTorrentRssSection();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(this).on('click', '.provider_enabler', function(){
|
|
|
|
$(this).refreshProviderList();
|
|
|
|
});
|
|
|
|
|
2014-12-24 10:48:36 -05:00
|
|
|
$('#newznab_cat_update').click(function(){
|
2014-09-01 11:57:52 -04:00
|
|
|
console.debug('Clicked Button');
|
|
|
|
|
2014-12-24 10:48:36 -05:00
|
|
|
// Maybe check if there is anything selected?
|
2014-09-01 11:57:52 -04:00
|
|
|
$("#newznab_cat option").each(function() {
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
|
|
|
|
var newOptions = [];
|
|
|
|
|
|
|
|
// When the update botton is clicked, loop through the capabilities list
|
|
|
|
// and copy the selected category id's to the category list on the right.
|
2014-12-24 10:48:36 -05:00
|
|
|
$("#newznab_cap option:selected").each(function(){
|
|
|
|
var selected_cat = $(this).val();
|
|
|
|
console.debug(selected_cat);
|
|
|
|
newOptions.push({text: selected_cat, value: selected_cat})
|
2014-09-01 11:57:52 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
$("#newznab_cat").replaceOptions(newOptions);
|
|
|
|
|
2014-12-24 10:48:36 -05:00
|
|
|
var selectedProvider = $("#editANewznabProvider :selected").val();
|
2014-09-01 11:57:52 -04:00
|
|
|
if (selectedProvider == "addNewznab")
|
|
|
|
return;
|
|
|
|
|
|
|
|
var url = $('#newznab_url').val();
|
|
|
|
var key = $('#newznab_key').val();
|
|
|
|
|
|
|
|
var cat = $('#newznab_cat option').map(function(i, opt) {
|
|
|
|
return $(opt).text();
|
|
|
|
}).toArray().join(',');
|
|
|
|
|
|
|
|
$("#newznab_cat option:not([value])").remove();
|
|
|
|
|
|
|
|
$(this).updateProvider(selectedProvider, url, key, cat);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
$('#newznab_add').click(function(){
|
|
|
|
|
|
|
|
var selectedProvider = $('#editANewznabProvider :selected').val();
|
|
|
|
|
|
|
|
var name = $.trim($('#newznab_name').val());
|
|
|
|
var url = $.trim($('#newznab_url').val());
|
|
|
|
var key = $.trim($('#newznab_key').val());
|
2014-09-01 11:57:52 -04:00
|
|
|
//var cat = $.trim($('#newznab_cat').val());
|
|
|
|
|
|
|
|
var cat = $.trim($('#newznab_cat option').map(function(i, opt) {
|
|
|
|
return $(opt).text();}).toArray().join(','));
|
|
|
|
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
if (!name)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!url)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!key)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var params = {name: name};
|
|
|
|
|
|
|
|
// send to the form with ajax, get a return value
|
|
|
|
$.getJSON(sbRoot + '/config/providers/canAddNewznabProvider', params,
|
|
|
|
function(data){
|
|
|
|
if (data.error != undefined) {
|
|
|
|
alert(data.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-01 11:57:52 -04:00
|
|
|
$(this).addProvider(data.success, name, url, key, cat, 0);
|
2014-03-10 01:18:05 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.newznab_delete').click(function(){
|
|
|
|
|
|
|
|
var selectedProvider = $('#editANewznabProvider :selected').val();
|
|
|
|
|
|
|
|
$(this).deleteProvider(selectedProvider);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#torrentrss_add').click(function(){
|
|
|
|
var selectedProvider = $('#editATorrentRssProvider :selected').val();
|
|
|
|
|
|
|
|
var name = $('#torrentrss_name').val();
|
|
|
|
var url = $('#torrentrss_url').val();
|
2014-05-25 03:28:13 -04:00
|
|
|
var cookies = $('#torrentrss_cookies').val();
|
|
|
|
var params = { name: name, url: url, cookies: cookies}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
// send to the form with ajax, get a return value
|
|
|
|
$.getJSON(sbRoot + '/config/providers/canAddTorrentRssProvider', params,
|
|
|
|
function(data){
|
|
|
|
if (data.error != undefined) {
|
|
|
|
alert(data.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-25 03:28:13 -04:00
|
|
|
$(this).addTorrentRssProvider(data.success, name, url, cookies);
|
2014-03-10 01:18:05 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.torrentrss_delete').on('click', function(){
|
|
|
|
var selectedProvider = $('#editATorrentRssProvider :selected').val();
|
|
|
|
$(this).deleteTorrentRssProvider(selectedProvider);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$(this).on('change', "[class='providerDiv_tip'] input", function(){
|
|
|
|
$('div .providerDiv ' + "[name=" + $(this).attr('name') + "]").replaceWith($(this).clone());
|
|
|
|
$('div .providerDiv ' + "[newznab_name=" + $(this).attr('id') + "]").replaceWith($(this).clone());
|
|
|
|
});
|
|
|
|
|
|
|
|
$(this).on('change', "[class='providerDiv_tip'] select", function(){
|
|
|
|
|
|
|
|
$(this).find('option').each( function() {
|
|
|
|
if ($(this).is(':selected')) {
|
|
|
|
$(this).prop('defaultSelected', true)
|
|
|
|
} else {
|
|
|
|
$(this).prop('defaultSelected', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('div .providerDiv ' + "[name=" + $(this).attr('name') + "]").empty().replaceWith($(this).clone())});
|
|
|
|
|
|
|
|
$(this).on('change', '.enabler', function(){
|
|
|
|
if ($(this).is(':checked')) {
|
|
|
|
$('.content_'+$(this).attr('id')).each( function() {
|
|
|
|
$(this).show()
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
$('.content_'+$(this).attr('id')).each( function() {
|
|
|
|
$(this).hide()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".enabler").each(function(){
|
|
|
|
if (!$(this).is(':checked')) {
|
|
|
|
$('.content_'+$(this).attr('id')).hide();
|
|
|
|
} else {
|
|
|
|
$('.content_'+$(this).attr('id')).show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
$.fn.makeTorrentOptionString = function(provider_id) {
|
2014-03-10 01:18:05 -04:00
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
var seed_ratio = $('.providerDiv_tip #'+provider_id+'_seed_ratio').prop('value');
|
|
|
|
var seed_time = $('.providerDiv_tip #'+provider_id+'_seed_time').prop('value');
|
|
|
|
var process_met = $('.providerDiv_tip #'+provider_id+'_process_method').prop('value');
|
|
|
|
var option_string = $('.providerDiv_tip #'+provider_id+'_option_string');
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
option_string.val([seed_ratio, seed_time, process_met].join('|'))
|
|
|
|
|
2014-03-20 14:03:22 -04:00
|
|
|
}
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
$(this).on('change', '.seed_option', function(){
|
|
|
|
|
|
|
|
var provider_id = $(this).attr('id').split('_')[0];
|
|
|
|
|
|
|
|
$(this).makeTorrentOptionString(provider_id);
|
|
|
|
|
|
|
|
});
|
2014-09-01 11:57:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
$.fn.replaceOptions = function(options) {
|
|
|
|
var self, $option;
|
|
|
|
|
|
|
|
this.empty();
|
|
|
|
self = this;
|
|
|
|
|
|
|
|
$.each(options, function(index, option) {
|
|
|
|
$option = $("<option></option>")
|
|
|
|
.attr("value", option.value)
|
|
|
|
.text(option.text);
|
|
|
|
self.append($option);
|
|
|
|
});
|
|
|
|
};
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
// initialization stuff
|
|
|
|
|
2014-09-01 11:57:52 -04:00
|
|
|
|
|
|
|
$.fn.newznabProvidersCapabilities = [];
|
2014-03-10 01:18:05 -04:00
|
|
|
|
|
|
|
$(this).showHideProviders();
|
|
|
|
|
|
|
|
$("#provider_order_list").sortable({
|
|
|
|
placeholder: 'ui-state-highlight',
|
|
|
|
update: function (event, ui) {
|
|
|
|
$(this).refreshProviderList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#provider_order_list").disableSelection();
|
|
|
|
|
2015-02-02 14:52:59 -05:00
|
|
|
});
|