jellyfin-web/dashboard-ui/components/tvproviders/xmltv.js

232 lines
8.1 KiB
JavaScript
Raw Normal View History

2016-10-14 09:22:04 -07:00
define(['jQuery', 'registrationServices', 'emby-checkbox', 'emby-input', 'listViewStyle', 'paper-icon-button-light'], function ($, registrationServices) {
2016-10-22 22:11:46 -07:00
'use strict';
2016-06-01 23:40:16 -07:00
return function (page, providerId, options) {
var self = this;
2016-06-03 12:32:10 -07:00
function getListingProvider(config, id) {
if (config && id) {
2016-06-06 14:12:44 -07:00
var result = config.ListingProviders.filter(function (i) {
2016-06-03 12:32:10 -07:00
return i.Id == id;
2016-06-06 14:12:44 -07:00
})[0];
2016-06-06 14:12:44 -07:00
if (result) {
return Promise.resolve(result);
}
return getListingProvider();
2016-06-03 12:32:10 -07:00
}
return ApiClient.getJSON(ApiClient.getUrl('LiveTv/ListingProviders/Default'));
}
2016-06-01 23:40:16 -07:00
function reload() {
Dashboard.showLoadingMsg();
ApiClient.getNamedConfiguration("livetv").then(function (config) {
2016-06-03 12:32:10 -07:00
getListingProvider(config, providerId).then(function (info) {
page.querySelector('.txtPath').value = info.Path || '';
2016-06-05 13:44:14 -07:00
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('|');
2016-11-15 10:55:26 -07:00
page.querySelector('.txtMoviePrefix').value = info.MoviePrefix || '';
2016-06-01 23:40:16 -07:00
2016-06-03 12:32:10 -07:00
page.querySelector('.chkAllTuners').checked = info.EnableAllTuners;
2016-06-01 23:40:16 -07:00
2016-06-03 12:32:10 -07:00
if (page.querySelector('.chkAllTuners').checked) {
page.querySelector('.selectTunersSection').classList.add('hide');
} else {
page.querySelector('.selectTunersSection').classList.remove('hide');
}
2016-06-01 23:40:16 -07:00
2016-06-03 12:32:10 -07:00
refreshTunerDevices(page, info, config.TunerHosts);
Dashboard.hideLoadingMsg();
});
2016-06-01 23:40:16 -07:00
});
}
2016-06-05 13:44:14 -07:00
function getCategories(txtInput) {
2016-06-03 12:32:10 -07:00
var value = txtInput.value;
return value ? value.split('|') : [];
}
2016-06-01 23:40:16 -07:00
function submitListingsForm() {
Dashboard.showLoadingMsg();
var id = providerId;
ApiClient.getNamedConfiguration("livetv").then(function (config) {
var info = config.ListingProviders.filter(function (i) {
return i.Id == id;
})[0] || {};
info.Type = 'xmltv';
2016-06-03 12:32:10 -07:00
2016-06-01 23:40:16 -07:00
info.Path = page.querySelector('.txtPath').value;
2016-06-03 12:32:10 -07:00
2016-11-15 20:05:53 -07:00
info.MoviePrefix = page.querySelector('.txtMoviePrefix') || null;
2016-11-15 10:55:26 -07:00
2016-06-05 13:44:14 -07:00
info.MovieCategories = getCategories(page.querySelector('.txtMovies'));
info.KidsCategories = getCategories(page.querySelector('.txtKids'));
info.NewsCategories = getCategories(page.querySelector('.txtNews'));
info.SportsCategories = getCategories(page.querySelector('.txtSports'));
2016-06-03 12:32:10 -07:00
2016-06-01 23:40:16 -07:00
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) {
Dashboard.hideLoadingMsg();
if (options.showConfirmation !== false) {
Dashboard.processServerConfigurationUpdateResult();
}
Events.trigger(self, 'submitted');
}, function () {
Dashboard.hideLoadingMsg();
Dashboard.alert({
message: Globalize.translate('ErrorAddingListingsToSchedulesDirect')
});
});
});
}
function getTunerName(providerId) {
providerId = providerId.toLowerCase();
switch (providerId) {
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];
2016-08-06 07:07:44 -07:00
html += '<div class="listItem">';
2016-06-01 23:40:16 -07:00
var enabledTuners = providerInfo.EnableAllTuners || [];
var isChecked = providerInfo.EnableAllTuners || enabledTuners.indexOf(device.Id) != -1;
var checkedAttribute = isChecked ? ' checked' : '';
2016-09-15 16:17:50 -07:00
html += '<label class="listItemCheckboxContainer"><input type="checkbox" is="emby-checkbox" class="chkTuner" data-id="' + device.Id + '" ' + checkedAttribute + '><span></span></label>';
2016-06-01 23:40:16 -07:00
2016-08-06 07:07:44 -07:00
html += '<div class="listItemBody two-line">';
html += '<div class="listItemBodyText">';
2016-06-01 23:40:16 -07:00
html += device.FriendlyName || getTunerName(device.Type);
html += '</div>';
2016-08-06 07:07:44 -07:00
html += '<div class="listItemBodyText secondary">';
2016-06-01 23:40:16 -07:00
html += device.Url;
html += '</div>';
2016-08-06 07:07:44 -07:00
html += '</div>';
2016-06-01 23:40:16 -07:00
2016-08-06 07:07:44 -07:00
html += '</div>';
2016-06-01 23:40:16 -07:00
}
page.querySelector('.tunerList').innerHTML = html;
}
self.submit = function () {
2016-07-05 09:55:37 -07:00
page.querySelector('.btnSubmitListings').click();
2016-06-01 23:40:16 -07:00
};
2016-06-03 13:01:16 -07:00
function onSelectPathClick(e) {
var page = $(e.target).parents('.xmltvForm')[0];
require(['directorybrowser'], function (directoryBrowser) {
var picker = new directoryBrowser();
picker.show({
2016-06-03 13:06:04 -07:00
includeFiles: true,
2016-06-03 13:01:16 -07:00
callback: function (path) {
if (path) {
var txtPath = page.querySelector('.txtPath');
txtPath.value = path;
txtPath.focus();
}
picker.close();
}
});
});
}
2016-06-01 23:40:16 -07:00
self.init = function () {
options = options || {};
if (options.showCancelButton !== false) {
page.querySelector('.btnCancel').classList.remove('hide');
} else {
page.querySelector('.btnCancel').classList.add('hide');
}
if (options.showSubmitButton !== false) {
page.querySelector('.btnSubmitListings').classList.remove('hide');
} else {
page.querySelector('.btnSubmitListings').classList.add('hide');
}
page.querySelector('.premiereHelp').innerHTML = Globalize.translate('XmlTvPremiere', 24);
2016-06-01 23:40:16 -07:00
$('form', page).on('submit', function () {
submitListingsForm();
return false;
});
2016-06-03 13:01:16 -07:00
page.querySelector('#btnSelectPath').addEventListener("click", onSelectPathClick);
page.querySelector('.lnkPremiere').addEventListener('click', function (e) {
registrationServices.showPremiereInfo();
e.preventDefault();
});
2016-06-01 23:40:16 -07:00
page.querySelector('.chkAllTuners').addEventListener('change', function (e) {
if (e.target.checked) {
page.querySelector('.selectTunersSection').classList.add('hide');
} else {
page.querySelector('.selectTunersSection').classList.remove('hide');
}
});
reload();
};
}
});