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

196 lines
7.6 KiB
JavaScript
Raw Normal View History

2020-08-14 08:46:34 +02:00
import 'jquery';
import loading from '../loading/loading';
import globalize from '../../scripts/globalize';
import '../../elements/emby-checkbox/emby-checkbox';
import '../../elements/emby-input/emby-input';
2021-01-26 16:25:38 -05:00
import '../listview/listview.scss';
2020-08-14 08:46:34 +02:00
import '../../elements/emby-button/paper-icon-button-light';
import Dashboard from '../../scripts/clientUtils';
import { Events } from 'jellyfin-apiclient';
export default function (page, providerId, options) {
function getListingProvider(config, id) {
if (config && id) {
2020-08-03 07:40:48 +01:00
const result = config.ListingProviders.filter(function (provider) {
return provider.Id === id;
})[0];
if (result) {
return Promise.resolve(result);
2019-01-10 21:34:44 +01:00
}
return getListingProvider();
2018-10-23 01:05:09 +03:00
}
return ApiClient.getJSON(ApiClient.getUrl('LiveTv/ListingProviders/Default'));
}
function reload() {
loading.show();
ApiClient.getNamedConfiguration('livetv').then(function (config) {
getListingProvider(config, providerId).then(function (info) {
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');
} else {
page.querySelector('.selectTunersSection').classList.remove('hide');
}
2019-01-10 21:34:44 +01:00
refreshTunerDevices(page, info, config.TunerHosts);
loading.hide();
2019-01-10 21:34:44 +01:00
});
});
}
2019-01-10 21:34:44 +01:00
function getCategories(txtInput) {
2020-08-03 07:40:48 +01:00
const value = txtInput.value;
2019-01-10 21:34:44 +01:00
if (value) {
return value.split('|');
2019-01-10 21:34:44 +01:00
}
2019-01-03 22:20:52 +00:00
return [];
}
function submitListingsForm() {
loading.show();
2020-08-03 07:40:48 +01:00
const id = providerId;
ApiClient.getNamedConfiguration('livetv').then(function (config) {
2020-08-03 07:40:48 +01:00
const info = config.ListingProviders.filter(function (provider) {
return provider.Id === id;
})[0] || {};
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) {
return tuner.checked;
}).map(function (tuner) {
return tuner.getAttribute('data-id');
});
ApiClient.ajax({
type: 'POST',
url: ApiClient.getUrl('LiveTv/ListingProviders', {
ValidateListings: true
}),
data: JSON.stringify(info),
contentType: 'application/json'
2021-01-26 22:20:12 -05:00
}).then(function () {
loading.hide();
if (options.showConfirmation !== false) {
Dashboard.processServerConfigurationUpdateResult();
}
2019-01-10 21:34:44 +01:00
Events.trigger(self, 'submitted');
}, function () {
loading.hide();
Dashboard.alert({
message: globalize.translate('ErrorAddingXmlTvFile')
2019-01-10 21:34:44 +01:00
});
});
});
}
function getTunerName(providerId) {
switch (providerId = providerId.toLowerCase()) {
case 'm3u':
return 'M3U Playlist';
case 'hdhomerun':
return 'HDHomerun';
case 'satip':
return 'DVB';
default:
return 'Unknown';
2019-01-10 21:34:44 +01:00
}
}
function refreshTunerDevices(page, providerInfo, devices) {
2020-08-03 07:40:48 +01:00
let html = '';
2020-08-03 07:40:48 +01:00
for (let i = 0, length = devices.length; i < length; i++) {
const device = devices[i];
html += '<div class="listItem">';
2020-08-03 07:40:48 +01:00
const enabledTuners = providerInfo.EnabledTuners || [];
const isChecked = providerInfo.EnableAllTuners || enabledTuners.indexOf(device.Id) !== -1;
const checkedAttribute = isChecked ? ' checked' : '';
html += '<label class="listItemCheckboxContainer"><input type="checkbox" is="emby-checkbox" class="chkTuner" data-id="' + device.Id + '" ' + checkedAttribute + '><span></span></label>';
html += '<div class="listItemBody two-line">';
html += '<div class="listItemBodyText">';
html += device.FriendlyName || getTunerName(device.Type);
html += '</div>';
html += '<div class="listItemBodyText secondary">';
html += device.Url;
html += '</div>';
html += '</div>';
html += '</div>';
2019-01-10 21:34:44 +01:00
}
page.querySelector('.tunerList').innerHTML = html;
}
function onSelectPathClick(e) {
2020-08-03 07:40:48 +01:00
const page = $(e.target).parents('.xmltvForm')[0];
import('../directorybrowser/directorybrowser').then(({default: directoryBrowser}) => {
2020-08-03 07:40:48 +01:00
const picker = new directoryBrowser();
picker.show({
includeFiles: true,
callback: function (path) {
if (path) {
2020-08-03 07:40:48 +01:00
const txtPath = page.querySelector('.txtPath');
txtPath.value = path;
txtPath.focus();
2019-01-10 21:34:44 +01:00
}
picker.close();
}
2019-01-10 21:34:44 +01:00
});
});
}
2019-01-10 21:34:44 +01:00
2020-08-03 07:40:48 +01:00
const self = this;
2019-01-10 21:34:44 +01:00
self.submit = function () {
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
2020-08-03 07:40:48 +01:00
const hideCancelButton = options.showCancelButton === false;
page.querySelector('.btnCancel').classList.toggle('hide', hideCancelButton);
2020-08-03 07:40:48 +01:00
const hideSubmitButton = options.showSubmitButton === false;
page.querySelector('.btnSubmitListings').classList.toggle('hide', hideSubmitButton);
$('form', page).on('submit', function () {
submitListingsForm();
return false;
});
page.querySelector('#btnSelectPath').addEventListener('click', onSelectPathClick);
page.querySelector('.chkAllTuners').addEventListener('change', function (evt) {
if (evt.target.checked) {
page.querySelector('.selectTunersSection').classList.add('hide');
} else {
page.querySelector('.selectTunersSection').classList.remove('hide');
}
});
reload();
2019-01-03 22:20:52 +00:00
};
2020-08-03 07:40:48 +01:00
}