mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Merge pull request #1736 from Camc314/migrate-to-ES6-54
Migration of xmltv and schedulesdirect to ES6 modules
This commit is contained in:
commit
b6befd29a8
3 changed files with 455 additions and 446 deletions
|
@ -167,6 +167,8 @@
|
||||||
"src/components/syncPlay/playbackPermissionManager.js",
|
"src/components/syncPlay/playbackPermissionManager.js",
|
||||||
"src/components/syncPlay/syncPlayManager.js",
|
"src/components/syncPlay/syncPlayManager.js",
|
||||||
"src/components/syncPlay/timeSyncManager.js",
|
"src/components/syncPlay/timeSyncManager.js",
|
||||||
|
"src/components/tvproviders/schedulesdirect.js",
|
||||||
|
"src/components/tvproviders/xmltv.js",
|
||||||
"src/components/toast/toast.js",
|
"src/components/toast/toast.js",
|
||||||
"src/components/upnextdialog/upnextdialog.js",
|
"src/components/upnextdialog/upnextdialog.js",
|
||||||
"src/components/viewContainer.js",
|
"src/components/viewContainer.js",
|
||||||
|
|
|
@ -1,299 +1,304 @@
|
||||||
define(['jQuery', 'loading', 'globalize', 'emby-checkbox', 'listViewStyle', 'emby-input', 'emby-select', 'emby-button', 'flexStyles'], function ($, loading, globalize) {
|
import $ from 'jQuery';
|
||||||
'use strict';
|
import loading from 'loading';
|
||||||
|
import globalize from 'globalize';
|
||||||
|
import 'emby-checkbox';
|
||||||
|
import 'emby-input';
|
||||||
|
import 'listViewStyle';
|
||||||
|
import 'paper-icon-button-light';
|
||||||
|
import 'emby-select';
|
||||||
|
import 'emby-button';
|
||||||
|
import 'flexStyles';
|
||||||
|
|
||||||
loading = loading.default || loading;
|
export default function (page, providerId, options) {
|
||||||
|
function reload() {
|
||||||
|
loading.show();
|
||||||
|
ApiClient.getNamedConfiguration('livetv').then(function (config) {
|
||||||
|
const info = config.ListingProviders.filter(function (i) {
|
||||||
|
return i.Id === providerId;
|
||||||
|
})[0] || {};
|
||||||
|
listingsId = info.ListingsId;
|
||||||
|
$('#selectListing', page).val(info.ListingsId || '');
|
||||||
|
page.querySelector('.txtUser').value = info.Username || '';
|
||||||
|
page.querySelector('.txtPass').value = '';
|
||||||
|
page.querySelector('.txtZipCode').value = info.ZipCode || '';
|
||||||
|
|
||||||
return function (page, providerId, options) {
|
if (info.Username && info.Password) {
|
||||||
function reload() {
|
page.querySelector('.listingsSection').classList.remove('hide');
|
||||||
loading.show();
|
} else {
|
||||||
ApiClient.getNamedConfiguration('livetv').then(function (config) {
|
page.querySelector('.listingsSection').classList.add('hide');
|
||||||
var info = config.ListingProviders.filter(function (i) {
|
|
||||||
return i.Id === providerId;
|
|
||||||
})[0] || {};
|
|
||||||
listingsId = info.ListingsId;
|
|
||||||
$('#selectListing', page).val(info.ListingsId || '');
|
|
||||||
page.querySelector('.txtUser').value = info.Username || '';
|
|
||||||
page.querySelector('.txtPass').value = '';
|
|
||||||
page.querySelector('.txtZipCode').value = info.ZipCode || '';
|
|
||||||
|
|
||||||
if (info.Username && info.Password) {
|
|
||||||
page.querySelector('.listingsSection').classList.remove('hide');
|
|
||||||
} else {
|
|
||||||
page.querySelector('.listingsSection').classList.add('hide');
|
|
||||||
}
|
|
||||||
|
|
||||||
page.querySelector('.chkAllTuners').checked = info.EnableAllTuners;
|
|
||||||
|
|
||||||
if (info.EnableAllTuners) {
|
|
||||||
page.querySelector('.selectTunersSection').classList.add('hide');
|
|
||||||
} else {
|
|
||||||
page.querySelector('.selectTunersSection').classList.remove('hide');
|
|
||||||
}
|
|
||||||
|
|
||||||
setCountry(info);
|
|
||||||
refreshTunerDevices(page, info, config.TunerHosts);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function setCountry(info) {
|
|
||||||
ApiClient.getJSON(ApiClient.getUrl('LiveTv/ListingProviders/SchedulesDirect/Countries')).then(function (result) {
|
|
||||||
var i;
|
|
||||||
var length;
|
|
||||||
var countryList = [];
|
|
||||||
|
|
||||||
for (var region in result) {
|
|
||||||
var countries = result[region];
|
|
||||||
|
|
||||||
if (countries.length && region !== 'ZZZ') {
|
|
||||||
for (i = 0, length = countries.length; i < length; i++) {
|
|
||||||
countryList.push({
|
|
||||||
name: countries[i].fullName,
|
|
||||||
value: countries[i].shortName
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
countryList.sort(function (a, b) {
|
|
||||||
if (a.name > b.name) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a.name < b.name) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
$('#selectCountry', page).html(countryList.map(function (c) {
|
|
||||||
return '<option value="' + c.value + '">' + c.name + '</option>';
|
|
||||||
}).join('')).val(info.Country || '');
|
|
||||||
$(page.querySelector('.txtZipCode')).trigger('change');
|
|
||||||
}, function () { // ApiClient.getJSON() error handler
|
|
||||||
Dashboard.alert({
|
|
||||||
message: globalize.translate('ErrorGettingTvLineups')
|
|
||||||
});
|
|
||||||
});
|
|
||||||
loading.hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
function sha256(str) {
|
|
||||||
if (!self.TextEncoder) {
|
|
||||||
return Promise.resolve('');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var buffer = new TextEncoder('utf-8').encode(str);
|
page.querySelector('.chkAllTuners').checked = info.EnableAllTuners;
|
||||||
return crypto.subtle.digest('SHA-256', buffer).then(function (hash) {
|
|
||||||
return hex(hash);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function hex(buffer) {
|
if (info.EnableAllTuners) {
|
||||||
var hexCodes = [];
|
page.querySelector('.selectTunersSection').classList.add('hide');
|
||||||
var view = new DataView(buffer);
|
} else {
|
||||||
|
page.querySelector('.selectTunersSection').classList.remove('hide');
|
||||||
for (var i = 0; i < view.byteLength; i += 4) {
|
|
||||||
var value = view.getUint32(i);
|
|
||||||
var stringValue = value.toString(16);
|
|
||||||
var paddedValue = ('00000000' + stringValue).slice(-'00000000'.length);
|
|
||||||
hexCodes.push(paddedValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hexCodes.join('');
|
setCountry(info);
|
||||||
}
|
refreshTunerDevices(page, info, config.TunerHosts);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function submitLoginForm() {
|
function setCountry(info) {
|
||||||
loading.show();
|
ApiClient.getJSON(ApiClient.getUrl('LiveTv/ListingProviders/SchedulesDirect/Countries')).then(function (result) {
|
||||||
sha256(page.querySelector('.txtPass').value).then(function (passwordHash) {
|
let i;
|
||||||
var info = {
|
let length;
|
||||||
Type: 'SchedulesDirect',
|
const countryList = [];
|
||||||
Username: page.querySelector('.txtUser').value,
|
|
||||||
EnableAllTuners: true,
|
|
||||||
Password: passwordHash,
|
|
||||||
Pw: page.querySelector('.txtPass').value
|
|
||||||
};
|
|
||||||
var id = providerId;
|
|
||||||
|
|
||||||
if (id) {
|
for (const region in result) {
|
||||||
info.Id = id;
|
const countries = result[region];
|
||||||
|
|
||||||
|
if (countries.length && region !== 'ZZZ') {
|
||||||
|
for (i = 0, length = countries.length; i < length; i++) {
|
||||||
|
countryList.push({
|
||||||
|
name: countries[i].fullName,
|
||||||
|
value: countries[i].shortName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
countryList.sort(function (a, b) {
|
||||||
|
if (a.name > b.name) {
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiClient.ajax({
|
if (a.name < b.name) {
|
||||||
type: 'POST',
|
return -1;
|
||||||
url: ApiClient.getUrl('LiveTv/ListingProviders', {
|
}
|
||||||
ValidateLogin: true
|
|
||||||
}),
|
return 0;
|
||||||
data: JSON.stringify(info),
|
|
||||||
contentType: 'application/json',
|
|
||||||
dataType: 'json'
|
|
||||||
}).then(function (result) {
|
|
||||||
Dashboard.processServerConfigurationUpdateResult();
|
|
||||||
providerId = result.Id;
|
|
||||||
reload();
|
|
||||||
}, function () {
|
|
||||||
Dashboard.alert({ // ApiClient.ajax() error handler
|
|
||||||
message: globalize.translate('ErrorSavingTvProvider')
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
$('#selectCountry', page).html(countryList.map(function (c) {
|
||||||
|
return '<option value="' + c.value + '">' + c.name + '</option>';
|
||||||
|
}).join('')).val(info.Country || '');
|
||||||
|
$(page.querySelector('.txtZipCode')).trigger('change');
|
||||||
|
}, function () { // ApiClient.getJSON() error handler
|
||||||
|
Dashboard.alert({
|
||||||
|
message: globalize.translate('ErrorGettingTvLineups')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
loading.hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
function sha256(str) {
|
||||||
|
if (!self.TextEncoder) {
|
||||||
|
return Promise.resolve('');
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitListingsForm() {
|
const buffer = new TextEncoder('utf-8').encode(str);
|
||||||
var selectedListingsId = $('#selectListing', page).val();
|
return crypto.subtle.digest('SHA-256', buffer).then(function (hash) {
|
||||||
|
return hex(hash);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!selectedListingsId) {
|
function hex(buffer) {
|
||||||
return void Dashboard.alert({
|
const hexCodes = [];
|
||||||
message: globalize.translate('ErrorPleaseSelectLineup')
|
const view = new DataView(buffer);
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
loading.show();
|
for (let i = 0; i < view.byteLength; i += 4) {
|
||||||
var id = providerId;
|
const value = view.getUint32(i);
|
||||||
ApiClient.getNamedConfiguration('livetv').then(function (config) {
|
const stringValue = value.toString(16);
|
||||||
var info = config.ListingProviders.filter(function (i) {
|
const paddedValue = ('00000000' + stringValue).slice(-'00000000'.length);
|
||||||
return i.Id === id;
|
hexCodes.push(paddedValue);
|
||||||
})[0];
|
|
||||||
info.ZipCode = page.querySelector('.txtZipCode').value;
|
|
||||||
info.Country = $('#selectCountry', page).val();
|
|
||||||
info.ListingsId = selectedListingsId;
|
|
||||||
info.EnableAllTuners = page.querySelector('.chkAllTuners').checked;
|
|
||||||
info.EnabledTuners = info.EnableAllTuners ? [] : $('.chkTuner', page).get().filter(function (i) {
|
|
||||||
return i.checked;
|
|
||||||
}).map(function (i) {
|
|
||||||
return i.getAttribute('data-id');
|
|
||||||
});
|
|
||||||
ApiClient.ajax({
|
|
||||||
type: 'POST',
|
|
||||||
url: ApiClient.getUrl('LiveTv/ListingProviders', {
|
|
||||||
ValidateListings: true
|
|
||||||
}),
|
|
||||||
data: JSON.stringify(info),
|
|
||||||
contentType: 'application/json'
|
|
||||||
}).then(function (result) {
|
|
||||||
loading.hide();
|
|
||||||
|
|
||||||
if (options.showConfirmation) {
|
|
||||||
Dashboard.processServerConfigurationUpdateResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
Events.trigger(self, 'submitted');
|
|
||||||
}, function () {
|
|
||||||
loading.hide();
|
|
||||||
Dashboard.alert({
|
|
||||||
message: globalize.translate('ErrorAddingListingsToSchedulesDirect')
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshListings(value) {
|
return hexCodes.join('');
|
||||||
if (!value) {
|
}
|
||||||
return void $('#selectListing', page).html('');
|
|
||||||
|
function submitLoginForm() {
|
||||||
|
loading.show();
|
||||||
|
sha256(page.querySelector('.txtPass').value).then(function (passwordHash) {
|
||||||
|
const info = {
|
||||||
|
Type: 'SchedulesDirect',
|
||||||
|
Username: page.querySelector('.txtUser').value,
|
||||||
|
EnableAllTuners: true,
|
||||||
|
Password: passwordHash,
|
||||||
|
Pw: page.querySelector('.txtPass').value
|
||||||
|
};
|
||||||
|
const id = providerId;
|
||||||
|
|
||||||
|
if (id) {
|
||||||
|
info.Id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
loading.show();
|
|
||||||
ApiClient.ajax({
|
ApiClient.ajax({
|
||||||
type: 'GET',
|
type: 'POST',
|
||||||
url: ApiClient.getUrl('LiveTv/ListingProviders/Lineups', {
|
url: ApiClient.getUrl('LiveTv/ListingProviders', {
|
||||||
Id: providerId,
|
ValidateLogin: true
|
||||||
Location: value,
|
|
||||||
Country: $('#selectCountry', page).val()
|
|
||||||
}),
|
}),
|
||||||
|
data: JSON.stringify(info),
|
||||||
|
contentType: 'application/json',
|
||||||
dataType: 'json'
|
dataType: 'json'
|
||||||
}).then(function (result) {
|
}).then(function (result) {
|
||||||
$('#selectListing', page).html(result.map(function (o) {
|
Dashboard.processServerConfigurationUpdateResult();
|
||||||
return '<option value="' + o.Id + '">' + o.Name + '</option>';
|
providerId = result.Id;
|
||||||
}));
|
reload();
|
||||||
|
}, function () {
|
||||||
if (listingsId) {
|
Dashboard.alert({ // ApiClient.ajax() error handler
|
||||||
$('#selectListing', page).val(listingsId);
|
message: globalize.translate('ErrorSavingTvProvider')
|
||||||
}
|
|
||||||
|
|
||||||
loading.hide();
|
|
||||||
}, function (result) {
|
|
||||||
Dashboard.alert({
|
|
||||||
message: globalize.translate('ErrorGettingTvLineups')
|
|
||||||
});
|
});
|
||||||
refreshListings('');
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitListingsForm() {
|
||||||
|
const selectedListingsId = $('#selectListing', page).val();
|
||||||
|
|
||||||
|
if (!selectedListingsId) {
|
||||||
|
return void Dashboard.alert({
|
||||||
|
message: globalize.translate('ErrorPleaseSelectLineup')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.show();
|
||||||
|
const id = providerId;
|
||||||
|
ApiClient.getNamedConfiguration('livetv').then(function (config) {
|
||||||
|
const info = config.ListingProviders.filter(function (i) {
|
||||||
|
return i.Id === id;
|
||||||
|
})[0];
|
||||||
|
info.ZipCode = page.querySelector('.txtZipCode').value;
|
||||||
|
info.Country = $('#selectCountry', page).val();
|
||||||
|
info.ListingsId = selectedListingsId;
|
||||||
|
info.EnableAllTuners = page.querySelector('.chkAllTuners').checked;
|
||||||
|
info.EnabledTuners = info.EnableAllTuners ? [] : $('.chkTuner', page).get().filter(function (i) {
|
||||||
|
return i.checked;
|
||||||
|
}).map(function (i) {
|
||||||
|
return i.getAttribute('data-id');
|
||||||
|
});
|
||||||
|
ApiClient.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: ApiClient.getUrl('LiveTv/ListingProviders', {
|
||||||
|
ValidateListings: true
|
||||||
|
}),
|
||||||
|
data: JSON.stringify(info),
|
||||||
|
contentType: 'application/json'
|
||||||
|
}).then(function (result) {
|
||||||
loading.hide();
|
loading.hide();
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTunerName(providerId) {
|
if (options.showConfirmation) {
|
||||||
switch (providerId = providerId.toLowerCase()) {
|
Dashboard.processServerConfigurationUpdateResult();
|
||||||
case 'm3u':
|
|
||||||
return 'M3U Playlist';
|
|
||||||
case 'hdhomerun':
|
|
||||||
return 'HDHomerun';
|
|
||||||
case 'satip':
|
|
||||||
return 'DVB';
|
|
||||||
default:
|
|
||||||
return 'Unknown';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function refreshTunerDevices(page, providerInfo, devices) {
|
|
||||||
var html = '';
|
|
||||||
|
|
||||||
for (var i = 0, length = devices.length; i < length; i++) {
|
|
||||||
var device = devices[i];
|
|
||||||
html += '<div class="listItem">';
|
|
||||||
var enabledTuners = providerInfo.EnabledTuners || [];
|
|
||||||
var isChecked = providerInfo.EnableAllTuners || enabledTuners.indexOf(device.Id) !== -1;
|
|
||||||
var checkedAttribute = isChecked ? ' checked' : '';
|
|
||||||
html += '<label class="checkboxContainer listItemCheckboxContainer"><input type="checkbox" is="emby-checkbox" data-id="' + device.Id + '" class="chkTuner" ' + 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>';
|
|
||||||
}
|
|
||||||
|
|
||||||
page.querySelector('.tunerList').innerHTML = html;
|
|
||||||
}
|
|
||||||
|
|
||||||
var listingsId;
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
self.submit = function () {
|
|
||||||
page.querySelector('.btnSubmitListingsContainer').click();
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
|
||||||
page.querySelector('.btnCancel').classList.toggle('hide', hideCancelButton);
|
|
||||||
|
|
||||||
var hideSubmitButton = options.showSubmitButton === false;
|
|
||||||
page.querySelector('.btnSubmitListings').classList.toggle('hide', hideSubmitButton);
|
|
||||||
|
|
||||||
$('.formLogin', page).on('submit', function () {
|
|
||||||
submitLoginForm();
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
$('.formListings', page).on('submit', function () {
|
|
||||||
submitListingsForm();
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
$('.txtZipCode', page).on('change', function () {
|
|
||||||
refreshListings(this.value);
|
|
||||||
});
|
|
||||||
page.querySelector('.chkAllTuners').addEventListener('change', function (e) {
|
|
||||||
if (e.target.checked) {
|
|
||||||
page.querySelector('.selectTunersSection').classList.add('hide');
|
|
||||||
} else {
|
|
||||||
page.querySelector('.selectTunersSection').classList.remove('hide');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Events.trigger(self, 'submitted');
|
||||||
|
}, function () {
|
||||||
|
loading.hide();
|
||||||
|
Dashboard.alert({
|
||||||
|
message: globalize.translate('ErrorAddingListingsToSchedulesDirect')
|
||||||
|
});
|
||||||
});
|
});
|
||||||
$('.createAccountHelp', page).html(globalize.translate('MessageCreateAccountAt', '<a is="emby-linkbutton" class="button-link" href="http://www.schedulesdirect.org" target="_blank">http://www.schedulesdirect.org</a>'));
|
});
|
||||||
reload();
|
}
|
||||||
};
|
|
||||||
|
function refreshListings(value) {
|
||||||
|
if (!value) {
|
||||||
|
return void $('#selectListing', page).html('');
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.show();
|
||||||
|
ApiClient.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: ApiClient.getUrl('LiveTv/ListingProviders/Lineups', {
|
||||||
|
Id: providerId,
|
||||||
|
Location: value,
|
||||||
|
Country: $('#selectCountry', page).val()
|
||||||
|
}),
|
||||||
|
dataType: 'json'
|
||||||
|
}).then(function (result) {
|
||||||
|
$('#selectListing', page).html(result.map(function (o) {
|
||||||
|
return '<option value="' + o.Id + '">' + o.Name + '</option>';
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (listingsId) {
|
||||||
|
$('#selectListing', page).val(listingsId);
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.hide();
|
||||||
|
}, function (result) {
|
||||||
|
Dashboard.alert({
|
||||||
|
message: globalize.translate('ErrorGettingTvLineups')
|
||||||
|
});
|
||||||
|
refreshListings('');
|
||||||
|
loading.hide();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTunerName(providerId) {
|
||||||
|
switch (providerId = providerId.toLowerCase()) {
|
||||||
|
case 'm3u':
|
||||||
|
return 'M3U Playlist';
|
||||||
|
case 'hdhomerun':
|
||||||
|
return 'HDHomerun';
|
||||||
|
case 'satip':
|
||||||
|
return 'DVB';
|
||||||
|
default:
|
||||||
|
return 'Unknown';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshTunerDevices(page, providerInfo, devices) {
|
||||||
|
let html = '';
|
||||||
|
|
||||||
|
for (let i = 0, length = devices.length; i < length; i++) {
|
||||||
|
const device = devices[i];
|
||||||
|
html += '<div class="listItem">';
|
||||||
|
const enabledTuners = providerInfo.EnabledTuners || [];
|
||||||
|
const isChecked = providerInfo.EnableAllTuners || enabledTuners.indexOf(device.Id) !== -1;
|
||||||
|
const checkedAttribute = isChecked ? ' checked' : '';
|
||||||
|
html += '<label class="checkboxContainer listItemCheckboxContainer"><input type="checkbox" is="emby-checkbox" data-id="' + device.Id + '" class="chkTuner" ' + 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>';
|
||||||
|
}
|
||||||
|
|
||||||
|
page.querySelector('.tunerList').innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
let listingsId;
|
||||||
|
const self = this;
|
||||||
|
|
||||||
|
self.submit = function () {
|
||||||
|
page.querySelector('.btnSubmitListingsContainer').click();
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
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
|
||||||
|
const hideCancelButton = options.showCancelButton === false;
|
||||||
|
page.querySelector('.btnCancel').classList.toggle('hide', hideCancelButton);
|
||||||
|
|
||||||
|
const hideSubmitButton = options.showSubmitButton === false;
|
||||||
|
page.querySelector('.btnSubmitListings').classList.toggle('hide', hideSubmitButton);
|
||||||
|
|
||||||
|
$('.formLogin', page).on('submit', function () {
|
||||||
|
submitLoginForm();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
$('.formListings', page).on('submit', function () {
|
||||||
|
submitListingsForm();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
$('.txtZipCode', page).on('change', function () {
|
||||||
|
refreshListings(this.value);
|
||||||
|
});
|
||||||
|
page.querySelector('.chkAllTuners').addEventListener('change', function (e) {
|
||||||
|
if (e.target.checked) {
|
||||||
|
page.querySelector('.selectTunersSection').classList.add('hide');
|
||||||
|
} else {
|
||||||
|
page.querySelector('.selectTunersSection').classList.remove('hide');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('.createAccountHelp', page).html(globalize.translate('MessageCreateAccountAt', '<a is="emby-linkbutton" class="button-link" href="http://www.schedulesdirect.org" target="_blank">http://www.schedulesdirect.org</a>'));
|
||||||
|
reload();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,191 +1,193 @@
|
||||||
define(['jQuery', 'loading', 'globalize', 'emby-checkbox', 'emby-input', 'listViewStyle', 'paper-icon-button-light'], function ($, loading, globalize) {
|
import $ from 'jQuery';
|
||||||
'use strict';
|
import loading from 'loading';
|
||||||
|
import globalize from 'globalize';
|
||||||
|
import 'emby-checkbox';
|
||||||
|
import 'emby-input';
|
||||||
|
import 'listViewStyle';
|
||||||
|
import 'paper-icon-button-light';
|
||||||
|
|
||||||
loading = loading.default || loading;
|
export default function (page, providerId, options) {
|
||||||
|
function getListingProvider(config, id) {
|
||||||
|
if (config && id) {
|
||||||
|
const result = config.ListingProviders.filter(function (provider) {
|
||||||
|
return provider.Id === id;
|
||||||
|
})[0];
|
||||||
|
|
||||||
return function (page, providerId, options) {
|
if (result) {
|
||||||
function getListingProvider(config, id) {
|
return Promise.resolve(result);
|
||||||
if (config && id) {
|
|
||||||
var result = config.ListingProviders.filter(function (provider) {
|
|
||||||
return provider.Id === id;
|
|
||||||
})[0];
|
|
||||||
|
|
||||||
if (result) {
|
|
||||||
return Promise.resolve(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return getListingProvider();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ApiClient.getJSON(ApiClient.getUrl('LiveTv/ListingProviders/Default'));
|
return getListingProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
function reload() {
|
return ApiClient.getJSON(ApiClient.getUrl('LiveTv/ListingProviders/Default'));
|
||||||
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) {
|
function reload() {
|
||||||
page.querySelector('.selectTunersSection').classList.add('hide');
|
loading.show();
|
||||||
} else {
|
ApiClient.getNamedConfiguration('livetv').then(function (config) {
|
||||||
page.querySelector('.selectTunersSection').classList.remove('hide');
|
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;
|
||||||
|
|
||||||
refreshTunerDevices(page, info, config.TunerHosts);
|
if (page.querySelector('.chkAllTuners').checked) {
|
||||||
loading.hide();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCategories(txtInput) {
|
|
||||||
var value = txtInput.value;
|
|
||||||
|
|
||||||
if (value) {
|
|
||||||
return value.split('|');
|
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
function submitListingsForm() {
|
|
||||||
loading.show();
|
|
||||||
var id = providerId;
|
|
||||||
ApiClient.getNamedConfiguration('livetv').then(function (config) {
|
|
||||||
var 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'
|
|
||||||
}).then(function (result) {
|
|
||||||
loading.hide();
|
|
||||||
|
|
||||||
if (options.showConfirmation !== false) {
|
|
||||||
Dashboard.processServerConfigurationUpdateResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
Events.trigger(self, 'submitted');
|
|
||||||
}, function () {
|
|
||||||
loading.hide();
|
|
||||||
Dashboard.alert({
|
|
||||||
message: globalize.translate('ErrorAddingXmlTvFile')
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTunerName(providerId) {
|
|
||||||
switch (providerId = providerId.toLowerCase()) {
|
|
||||||
case 'm3u':
|
|
||||||
return 'M3U Playlist';
|
|
||||||
case 'hdhomerun':
|
|
||||||
return 'HDHomerun';
|
|
||||||
case 'satip':
|
|
||||||
return 'DVB';
|
|
||||||
default:
|
|
||||||
return 'Unknown';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function refreshTunerDevices(page, providerInfo, devices) {
|
|
||||||
var html = '';
|
|
||||||
|
|
||||||
for (var i = 0, length = devices.length; i < length; i++) {
|
|
||||||
var device = devices[i];
|
|
||||||
html += '<div class="listItem">';
|
|
||||||
var enabledTuners = providerInfo.EnabledTuners || [];
|
|
||||||
var isChecked = providerInfo.EnableAllTuners || enabledTuners.indexOf(device.Id) !== -1;
|
|
||||||
var 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>';
|
|
||||||
}
|
|
||||||
|
|
||||||
page.querySelector('.tunerList').innerHTML = html;
|
|
||||||
}
|
|
||||||
|
|
||||||
function onSelectPathClick(e) {
|
|
||||||
var page = $(e.target).parents('.xmltvForm')[0];
|
|
||||||
|
|
||||||
require(['directorybrowser'], function (directoryBrowser) {
|
|
||||||
var picker = new directoryBrowser.default();
|
|
||||||
picker.show({
|
|
||||||
includeFiles: true,
|
|
||||||
callback: function (path) {
|
|
||||||
if (path) {
|
|
||||||
var txtPath = page.querySelector('.txtPath');
|
|
||||||
txtPath.value = path;
|
|
||||||
txtPath.focus();
|
|
||||||
}
|
|
||||||
picker.close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
self.submit = function () {
|
|
||||||
page.querySelector('.btnSubmitListings').click();
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
|
||||||
page.querySelector('.btnCancel').classList.toggle('hide', hideCancelButton);
|
|
||||||
|
|
||||||
var 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');
|
page.querySelector('.selectTunersSection').classList.add('hide');
|
||||||
} else {
|
} else {
|
||||||
page.querySelector('.selectTunersSection').classList.remove('hide');
|
page.querySelector('.selectTunersSection').classList.remove('hide');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshTunerDevices(page, info, config.TunerHosts);
|
||||||
|
loading.hide();
|
||||||
});
|
});
|
||||||
reload();
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
|
function getCategories(txtInput) {
|
||||||
|
const value = txtInput.value;
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
return value.split('|');
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitListingsForm() {
|
||||||
|
loading.show();
|
||||||
|
const id = providerId;
|
||||||
|
ApiClient.getNamedConfiguration('livetv').then(function (config) {
|
||||||
|
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'
|
||||||
|
}).then(function (result) {
|
||||||
|
loading.hide();
|
||||||
|
|
||||||
|
if (options.showConfirmation !== false) {
|
||||||
|
Dashboard.processServerConfigurationUpdateResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
Events.trigger(self, 'submitted');
|
||||||
|
}, function () {
|
||||||
|
loading.hide();
|
||||||
|
Dashboard.alert({
|
||||||
|
message: globalize.translate('ErrorAddingXmlTvFile')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTunerName(providerId) {
|
||||||
|
switch (providerId = providerId.toLowerCase()) {
|
||||||
|
case 'm3u':
|
||||||
|
return 'M3U Playlist';
|
||||||
|
case 'hdhomerun':
|
||||||
|
return 'HDHomerun';
|
||||||
|
case 'satip':
|
||||||
|
return 'DVB';
|
||||||
|
default:
|
||||||
|
return 'Unknown';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshTunerDevices(page, providerInfo, devices) {
|
||||||
|
let html = '';
|
||||||
|
|
||||||
|
for (let i = 0, length = devices.length; i < length; i++) {
|
||||||
|
const device = devices[i];
|
||||||
|
html += '<div class="listItem">';
|
||||||
|
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>';
|
||||||
|
}
|
||||||
|
|
||||||
|
page.querySelector('.tunerList').innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSelectPathClick(e) {
|
||||||
|
const page = $(e.target).parents('.xmltvForm')[0];
|
||||||
|
|
||||||
|
import('directorybrowser').then(({default: directoryBrowser}) => {
|
||||||
|
const picker = new directoryBrowser();
|
||||||
|
picker.show({
|
||||||
|
includeFiles: true,
|
||||||
|
callback: function (path) {
|
||||||
|
if (path) {
|
||||||
|
const txtPath = page.querySelector('.txtPath');
|
||||||
|
txtPath.value = path;
|
||||||
|
txtPath.focus();
|
||||||
|
}
|
||||||
|
picker.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const self = this;
|
||||||
|
|
||||||
|
self.submit = function () {
|
||||||
|
page.querySelector('.btnSubmitListings').click();
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
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
|
||||||
|
const hideCancelButton = options.showCancelButton === false;
|
||||||
|
page.querySelector('.btnCancel').classList.toggle('hide', hideCancelButton);
|
||||||
|
|
||||||
|
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();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue