1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/components/tvproviders/xmltv.js

190 lines
8 KiB
JavaScript
Raw Normal View History

2020-05-04 12:44:12 +02:00
define(['jQuery', 'loading', 'globalize', 'emby-checkbox', 'emby-input', 'listViewStyle', 'paper-icon-button-light'], function ($, loading, globalize) {
'use strict';
2018-10-23 01:05:09 +03:00
2019-01-10 21:34:44 +01:00
return function (page, providerId, options) {
function getListingProvider(config, id) {
if (config && id) {
var result = config.ListingProviders.filter(function (provider) {
return provider.Id === id;
})[0];
2018-10-23 01:05:09 +03:00
2019-01-10 21:34:44 +01:00
if (result) {
return Promise.resolve(result);
}
return getListingProvider();
}
2020-05-04 12:44:12 +02:00
return ApiClient.getJSON(ApiClient.getUrl('LiveTv/ListingProviders/Default'));
2018-10-23 01:05:09 +03:00
}
2019-01-10 21:34:44 +01:00
function reload() {
loading.show();
2020-05-04 12:44:12 +02:00
ApiClient.getNamedConfiguration('livetv').then(function (config) {
2019-01-10 21:34:44 +01:00
getListingProvider(config, providerId).then(function (info) {
2020-05-04 12:44:12 +02:00
page.querySelector('.txtPath').value = info.Path || '';
page.querySelector('.txtKids').value = (info.KidsCategories || []).join('|');
page.querySelector('.txtNews').value = (info.NewsCategories || []).join('|');
page.querySelector('.txtSports').value = (info.SportsCategories || []).join('|');
page.querySelector('.txtMovies').value = (info.MovieCategories || []).join('|');
page.querySelector('.txtMoviePrefix').value = info.MoviePrefix || '';
page.querySelector('.txtUserAgent').value = info.UserAgent || '';
page.querySelector('.chkAllTuners').checked = info.EnableAllTuners;
if (page.querySelector('.chkAllTuners').checked) {
page.querySelector('.selectTunersSection').classList.add('hide');
2019-01-10 21:34:44 +01:00
} else {
2020-05-04 12:44:12 +02:00
page.querySelector('.selectTunersSection').classList.remove('hide');
2019-01-10 21:34:44 +01:00
}
refreshTunerDevices(page, info, config.TunerHosts);
loading.hide();
});
});
}
function getCategories(txtInput) {
var value = txtInput.value;
if (value) {
2020-05-04 12:44:12 +02:00
return value.split('|');
2018-10-23 01:05:09 +03:00
}
2019-01-10 21:34:44 +01:00
return [];
}
2019-01-03 22:20:52 +00:00
2019-01-10 21:34:44 +01:00
function submitListingsForm() {
loading.show();
var id = providerId;
2020-05-04 12:44:12 +02:00
ApiClient.getNamedConfiguration('livetv').then(function (config) {
2019-01-10 21:34:44 +01:00
var info = config.ListingProviders.filter(function (provider) {
return provider.Id === id;
})[0] || {};
2020-05-04 12:44:12 +02:00
info.Type = 'xmltv';
info.Path = page.querySelector('.txtPath').value;
info.MoviePrefix = page.querySelector('.txtMoviePrefix').value || null;
info.UserAgent = page.querySelector('.txtUserAgent').value || null;
info.MovieCategories = getCategories(page.querySelector('.txtMovies'));
info.KidsCategories = getCategories(page.querySelector('.txtKids'));
info.NewsCategories = getCategories(page.querySelector('.txtNews'));
info.SportsCategories = getCategories(page.querySelector('.txtSports'));
info.EnableAllTuners = page.querySelector('.chkAllTuners').checked;
info.EnabledTuners = info.EnableAllTuners ? [] : $('.chkTuner', page).get().filter(function (tuner) {
2019-01-10 21:34:44 +01:00
return tuner.checked;
}).map(function (tuner) {
2020-05-04 12:44:12 +02:00
return tuner.getAttribute('data-id');
2019-01-10 21:34:44 +01:00
});
ApiClient.ajax({
2020-05-04 12:44:12 +02:00
type: 'POST',
url: ApiClient.getUrl('LiveTv/ListingProviders', {
2019-01-10 21:34:44 +01:00
ValidateListings: true
}),
data: JSON.stringify(info),
2020-05-04 12:44:12 +02:00
contentType: 'application/json'
2019-01-10 21:34:44 +01:00
}).then(function (result) {
loading.hide();
if (false !== options.showConfirmation) {
Dashboard.processServerConfigurationUpdateResult();
}
2020-05-04 12:44:12 +02:00
Events.trigger(self, 'submitted');
2019-01-10 21:34:44 +01:00
}, function () {
loading.hide();
Dashboard.alert({
2020-05-04 12:44:12 +02:00
message: globalize.translate('ErrorAddingXmlTvFile')
2019-01-10 21:34:44 +01:00
});
});
});
}
2019-01-03 22:20:52 +00:00
2019-01-10 21:34:44 +01:00
function getTunerName(providerId) {
switch (providerId = providerId.toLowerCase()) {
2020-05-04 12:44:12 +02:00
case 'm3u':
return 'M3U Playlist';
case 'hdhomerun':
return 'HDHomerun';
case 'satip':
return 'DVB';
2019-01-10 21:34:44 +01:00
default:
2020-05-04 12:44:12 +02:00
return 'Unknown';
2019-01-10 21:34:44 +01:00
}
}
2019-01-03 22:20:52 +00:00
2019-01-10 21:34:44 +01:00
function refreshTunerDevices(page, providerInfo, devices) {
2020-05-04 12:44:12 +02:00
var html = '';
2019-01-10 21:34:44 +01:00
for (var i = 0, length = devices.length; i < length; i++) {
2019-01-10 21:34:44 +01:00
var device = devices[i];
html += '<div class="listItem">';
var enabledTuners = providerInfo.EnabledTuners || [];
var isChecked = providerInfo.EnableAllTuners || -1 !== enabledTuners.indexOf(device.Id);
2020-05-04 12:44:12 +02:00
var checkedAttribute = isChecked ? ' checked' : '';
html += '<label class="listItemCheckboxContainer"><input type="checkbox" is="emby-checkbox" class="chkTuner" data-id="' + device.Id + '" ' + checkedAttribute + '><span></span></label>';
2019-01-10 21:34:44 +01:00
html += '<div class="listItemBody two-line">';
html += '<div class="listItemBodyText">';
html += device.FriendlyName || getTunerName(device.Type);
2020-05-04 12:44:12 +02:00
html += '</div>';
2019-01-10 21:34:44 +01:00
html += '<div class="listItemBodyText secondary">';
html += device.Url;
2020-05-04 12:44:12 +02:00
html += '</div>';
html += '</div>';
html += '</div>';
2019-01-10 21:34:44 +01:00
}
2020-05-04 12:44:12 +02:00
page.querySelector('.tunerList').innerHTML = html;
2019-01-10 21:34:44 +01:00
}
2019-10-09 19:15:06 +03:00
function onSelectPathClick(e) {
2020-05-04 12:44:12 +02:00
var page = $(e.target).parents('.xmltvForm')[0];
2019-01-10 21:34:44 +01:00
2020-05-04 12:44:12 +02:00
require(['directorybrowser'], function (directoryBrowser) {
2019-01-10 21:34:44 +01:00
var picker = new directoryBrowser();
picker.show({
includeFiles: true,
callback: function (path) {
if (path) {
2020-05-04 12:44:12 +02:00
var txtPath = page.querySelector('.txtPath');
2019-01-10 21:34:44 +01:00
txtPath.value = path;
txtPath.focus();
}
picker.close();
}
});
});
2019-01-03 22:20:52 +00:00
}
2019-01-10 21:34:44 +01:00
var self = this;
self.submit = function () {
2020-05-04 12:44:12 +02:00
page.querySelector('.btnSubmitListings').click();
2019-01-10 21:34:44 +01:00
};
self.init = function () {
options = options || {};
// Only hide the buttons if explicitly set to false; default to showing if undefined or null
// FIXME: rename this option to clarify logic
var hideCancelButton = options.showCancelButton === false;
2020-05-04 12:44:12 +02:00
page.querySelector('.btnCancel').classList.toggle('hide', hideCancelButton);
2019-01-10 21:34:44 +01:00
var hideSubmitButton = options.showSubmitButton === false;
2020-05-04 12:44:12 +02:00
page.querySelector('.btnSubmitListings').classList.toggle('hide', hideSubmitButton);
2019-01-10 21:34:44 +01:00
2020-05-04 12:44:12 +02:00
$('form', page).on('submit', function () {
2019-01-10 21:34:44 +01:00
submitListingsForm();
return false;
});
2020-05-04 12:44:12 +02:00
page.querySelector('#btnSelectPath').addEventListener('click', onSelectPathClick);
page.querySelector('.chkAllTuners').addEventListener('change', function (evt) {
2019-01-10 21:34:44 +01:00
if (evt.target.checked) {
2020-05-04 12:44:12 +02:00
page.querySelector('.selectTunersSection').classList.add('hide');
2019-01-10 21:34:44 +01:00
} else {
2020-05-04 12:44:12 +02:00
page.querySelector('.selectTunersSection').classList.remove('hide');
2019-01-10 21:34:44 +01:00
}
});
reload();
};
2019-01-03 22:20:52 +00:00
};
2019-01-03 21:47:58 +00:00
});