2019-11-11 12:28:27 +03:00
|
|
|
define(["jQuery", "globalize", "scripts/taskbutton", "dom", "libraryMenu", "layoutManager", "loading", "browser", "listViewStyle", "flexStyles", "emby-itemscontainer", "cardStyle", "material-icons", "emby-button"], function ($, globalize, taskButton, dom, libraryMenu, layoutManager, loading, browser) {
|
2018-10-23 01:05:09 +03:00
|
|
|
"use strict";
|
|
|
|
|
2019-11-11 12:28:27 +03:00
|
|
|
var enableFocusTransform = !browser.slow && !browser.edge;
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
function getDeviceHtml(device) {
|
2019-11-06 13:43:39 +03:00
|
|
|
var padderClass;
|
|
|
|
var html = "";
|
|
|
|
var cssClass = "card scalableCard";
|
|
|
|
var cardBoxCssClass = "cardBox visualCardBox";
|
|
|
|
cssClass += " backdropCard backdropCard-scalable";
|
|
|
|
padderClass = "cardPadder-backdrop";
|
|
|
|
|
2019-11-11 12:28:27 +03:00
|
|
|
// TODO move card creation code to Card component
|
|
|
|
|
2019-11-06 13:43:39 +03:00
|
|
|
if (layoutManager.tv) {
|
2019-11-11 12:28:27 +03:00
|
|
|
cssClass += " show-focus";
|
|
|
|
|
|
|
|
if (enableFocusTransform) {
|
|
|
|
cssClass += " show-animation";
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
html += '<div type="button" class="' + cssClass + '" data-id="' + device.Id + '">';
|
|
|
|
html += '<div class="' + cardBoxCssClass + '">';
|
|
|
|
html += '<div class="cardScalable visualCardBox-cardScalable">';
|
|
|
|
html += '<div class="' + padderClass + '"></div>';
|
|
|
|
html += '<div class="cardContent searchImage">';
|
2020-01-19 12:57:09 +01:00
|
|
|
html += '<div class="cardImageContainer coveredImage"><i class="cardImageIcon material-icons">dvr</i></div>';
|
2019-11-06 13:43:39 +03:00
|
|
|
html += "</div>";
|
|
|
|
html += "</div>";
|
|
|
|
html += '<div class="cardFooter visualCardBox-cardFooter">';
|
2020-01-19 12:57:09 +01:00
|
|
|
html += '<button is="paper-icon-button-light" class="itemAction btnCardOptions autoSize" data-action="menu"><i class="material-icons">more_horiz</i></button>';
|
2019-11-06 13:43:39 +03:00
|
|
|
html += '<div class="cardText">' + (device.FriendlyName || getTunerName(device.Type)) + "</div>";
|
|
|
|
html += '<div class="cardText cardText-secondary">';
|
|
|
|
html += device.Url || " ";
|
|
|
|
html += "</div>";
|
|
|
|
html += "</div>";
|
|
|
|
html += "</div>";
|
|
|
|
return html += "</div>";
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderDevices(page, devices) {
|
|
|
|
var html = devices.map(getDeviceHtml).join("");
|
2019-11-06 13:43:39 +03:00
|
|
|
page.querySelector(".devicesList").innerHTML = html;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteDevice(page, id) {
|
|
|
|
var message = globalize.translate("MessageConfirmDeleteTunerDevice");
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
require(["confirm"], function (confirm) {
|
|
|
|
confirm(message, globalize.translate("HeaderDeleteDevice")).then(function () {
|
|
|
|
loading.show();
|
|
|
|
ApiClient.ajax({
|
2018-10-23 01:05:09 +03:00
|
|
|
type: "DELETE",
|
|
|
|
url: ApiClient.getUrl("LiveTv/TunerHosts", {
|
|
|
|
Id: id
|
|
|
|
})
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(function () {
|
|
|
|
reload(page);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function reload(page) {
|
2019-11-06 13:43:39 +03:00
|
|
|
loading.show();
|
|
|
|
ApiClient.getNamedConfiguration("livetv").then(function (config) {
|
|
|
|
renderDevices(page, config.TunerHosts);
|
|
|
|
renderProviders(page, config.ListingProviders);
|
|
|
|
});
|
|
|
|
loading.hide();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function submitAddDeviceForm(page) {
|
2019-11-06 13:43:39 +03:00
|
|
|
page.querySelector(".dlgAddDevice").close();
|
|
|
|
loading.show();
|
|
|
|
ApiClient.ajax({
|
2018-10-23 01:05:09 +03:00
|
|
|
type: "POST",
|
|
|
|
url: ApiClient.getUrl("LiveTv/TunerHosts"),
|
|
|
|
data: JSON.stringify({
|
|
|
|
Type: $("#selectTunerDeviceType", page).val(),
|
|
|
|
Url: $("#txtDevicePath", page).val()
|
|
|
|
}),
|
|
|
|
contentType: "application/json"
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(function () {
|
|
|
|
reload(page);
|
|
|
|
}, function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
Dashboard.alert({
|
|
|
|
message: globalize.translate("ErrorAddingTunerDevice")
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderProviders(page, providers) {
|
|
|
|
var html = "";
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (providers.length) {
|
|
|
|
html += '<div class="paperList">';
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
for (var i = 0, length = providers.length; i < length; i++) {
|
|
|
|
var provider = providers[i];
|
2019-11-06 13:43:39 +03:00
|
|
|
html += '<div class="listItem">';
|
2020-01-19 12:57:09 +01:00
|
|
|
html += '<i class="listItemIcon material-icons">dvr</i>';
|
2019-11-06 13:43:39 +03:00
|
|
|
html += '<div class="listItemBody two-line">';
|
|
|
|
html += '<a is="emby-linkbutton" style="display:block;padding:0;margin:0;text-align:left;" class="clearLink" href="' + getProviderConfigurationUrl(provider.Type) + "&id=" + provider.Id + '">';
|
|
|
|
html += '<h3 class="listItemBodyText">';
|
|
|
|
html += getProviderName(provider.Type);
|
|
|
|
html += "</h3>";
|
|
|
|
html += '<div class="listItemBodyText secondary">';
|
|
|
|
html += provider.Path || provider.ListingsId || "";
|
|
|
|
html += "</div>";
|
|
|
|
html += "</a>";
|
|
|
|
html += "</div>";
|
2020-01-19 12:57:09 +01:00
|
|
|
html += '<button type="button" is="paper-icon-button-light" class="btnOptions" data-id="' + provider.Id + '"><i class="material-icons listItemAside">more_horiz</i></button>';
|
2019-11-06 13:43:39 +03:00
|
|
|
html += "</div>";
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
html += "</div>";
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var elem = $(".providerList", page).html(html);
|
2019-11-06 13:43:39 +03:00
|
|
|
$(".btnOptions", elem).on("click", function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
var id = this.getAttribute("data-id");
|
2019-11-06 13:43:39 +03:00
|
|
|
showProviderOptions(page, id, this);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showProviderOptions(page, providerId, button) {
|
|
|
|
var items = [];
|
|
|
|
items.push({
|
|
|
|
name: globalize.translate("ButtonDelete"),
|
|
|
|
id: "delete"
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
items.push({
|
2018-10-23 01:05:09 +03:00
|
|
|
name: globalize.translate("MapChannels"),
|
|
|
|
id: "map"
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
require(["actionsheet"], function (actionsheet) {
|
2018-10-23 01:05:09 +03:00
|
|
|
actionsheet.show({
|
|
|
|
items: items,
|
|
|
|
positionTo: button
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(function (id) {
|
2018-10-23 01:05:09 +03:00
|
|
|
switch (id) {
|
|
|
|
case "delete":
|
|
|
|
deleteProvider(page, providerId);
|
|
|
|
break;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
case "map":
|
2019-11-06 13:43:39 +03:00
|
|
|
mapChannels(page, providerId);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function mapChannels(page, providerId) {
|
2019-11-06 13:43:39 +03:00
|
|
|
require(["components/channelmapper/channelmapper"], function (channelmapper) {
|
2018-10-23 01:05:09 +03:00
|
|
|
new channelmapper({
|
|
|
|
serverId: ApiClient.serverInfo().Id,
|
|
|
|
providerId: providerId
|
2019-11-06 13:43:39 +03:00
|
|
|
}).show();
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteProvider(page, id) {
|
|
|
|
var message = globalize.translate("MessageConfirmDeleteGuideProvider");
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
require(["confirm"], function (confirm) {
|
|
|
|
confirm(message, globalize.translate("HeaderDeleteProvider")).then(function () {
|
|
|
|
loading.show();
|
|
|
|
ApiClient.ajax({
|
2018-10-23 01:05:09 +03:00
|
|
|
type: "DELETE",
|
|
|
|
url: ApiClient.getUrl("LiveTv/ListingProviders", {
|
|
|
|
Id: id
|
|
|
|
})
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(function () {
|
|
|
|
reload(page);
|
|
|
|
}, function () {
|
|
|
|
reload(page);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTunerName(providerId) {
|
|
|
|
switch (providerId = providerId.toLowerCase()) {
|
|
|
|
case "m3u":
|
|
|
|
return "M3U";
|
|
|
|
case "hdhomerun":
|
2020-01-20 10:14:25 +09:00
|
|
|
return "HDHomeRun";
|
2018-10-23 01:05:09 +03:00
|
|
|
case "hauppauge":
|
|
|
|
return "Hauppauge";
|
|
|
|
case "satip":
|
|
|
|
return "DVB";
|
|
|
|
default:
|
2019-11-06 13:43:39 +03:00
|
|
|
return "Unknown";
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getProviderName(providerId) {
|
|
|
|
switch (providerId = providerId.toLowerCase()) {
|
|
|
|
case "schedulesdirect":
|
|
|
|
return "Schedules Direct";
|
|
|
|
case "xmltv":
|
2020-01-20 10:14:25 +09:00
|
|
|
return "XMLTV";
|
2018-10-23 01:05:09 +03:00
|
|
|
default:
|
2019-11-06 13:43:39 +03:00
|
|
|
return "Unknown";
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getProviderConfigurationUrl(providerId) {
|
|
|
|
switch (providerId = providerId.toLowerCase()) {
|
|
|
|
case "xmltv":
|
|
|
|
return "livetvguideprovider.html?type=xmltv";
|
|
|
|
case "schedulesdirect":
|
|
|
|
return "livetvguideprovider.html?type=schedulesdirect";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addProvider(button) {
|
|
|
|
var menuItems = [];
|
|
|
|
menuItems.push({
|
|
|
|
name: "Schedules Direct",
|
|
|
|
id: "SchedulesDirect"
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
menuItems.push({
|
2020-01-20 10:14:25 +09:00
|
|
|
name: "XMLTV",
|
2018-10-23 01:05:09 +03:00
|
|
|
id: "xmltv"
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
require(["actionsheet"], function (actionsheet) {
|
2018-10-23 01:05:09 +03:00
|
|
|
actionsheet.show({
|
|
|
|
items: menuItems,
|
|
|
|
positionTo: button,
|
2019-11-06 13:43:39 +03:00
|
|
|
callback: function (id) {
|
|
|
|
Dashboard.navigate(getProviderConfigurationUrl(id));
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function addDevice(button) {
|
2019-11-06 13:43:39 +03:00
|
|
|
Dashboard.navigate("livetvtuner.html");
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showDeviceMenu(button, tunerDeviceId) {
|
|
|
|
var items = [];
|
|
|
|
items.push({
|
|
|
|
name: globalize.translate("ButtonDelete"),
|
|
|
|
id: "delete"
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
items.push({
|
2018-10-23 01:05:09 +03:00
|
|
|
name: globalize.translate("ButtonEdit"),
|
|
|
|
id: "edit"
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
require(["actionsheet"], function (actionsheet) {
|
2018-10-23 01:05:09 +03:00
|
|
|
actionsheet.show({
|
|
|
|
items: items,
|
|
|
|
positionTo: button
|
2019-11-06 13:43:39 +03:00
|
|
|
}).then(function (id) {
|
2018-10-23 01:05:09 +03:00
|
|
|
switch (id) {
|
|
|
|
case "delete":
|
|
|
|
deleteDevice(dom.parentWithClass(button, "page"), tunerDeviceId);
|
|
|
|
break;
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
case "edit":
|
2019-11-06 13:43:39 +03:00
|
|
|
Dashboard.navigate("livetvtuner.html?id=" + tunerDeviceId);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onDevicesListClick(e) {
|
|
|
|
var card = dom.parentWithClass(e.target, "card");
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (card) {
|
2019-11-06 13:43:39 +03:00
|
|
|
var id = card.getAttribute("data-id");
|
|
|
|
var btnCardOptions = dom.parentWithClass(e.target, "btnCardOptions");
|
|
|
|
|
|
|
|
if (btnCardOptions) {
|
|
|
|
showDeviceMenu(btnCardOptions, id);
|
|
|
|
} else {
|
|
|
|
Dashboard.navigate("livetvtuner.html?id=" + id);
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
$(document).on("pageinit", "#liveTvStatusPage", function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
var page = this;
|
2019-11-06 13:43:39 +03:00
|
|
|
$(".btnAddDevice", page).on("click", function () {
|
|
|
|
addDevice(this);
|
|
|
|
});
|
|
|
|
$(".formAddDevice", page).on("submit", function () {
|
|
|
|
submitAddDeviceForm(page);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$(".btnAddProvider", page).on("click", function () {
|
|
|
|
addProvider(this);
|
|
|
|
});
|
|
|
|
page.querySelector(".devicesList").addEventListener("click", onDevicesListClick);
|
|
|
|
}).on("pageshow", "#liveTvStatusPage", function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
var page = this;
|
2019-11-06 13:43:39 +03:00
|
|
|
reload(page);
|
|
|
|
taskButton({
|
2018-10-23 01:05:09 +03:00
|
|
|
mode: "on",
|
|
|
|
progressElem: page.querySelector(".refreshGuideProgress"),
|
|
|
|
taskKey: "RefreshGuide",
|
|
|
|
button: page.querySelector(".btnRefresh")
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
}).on("pagehide", "#liveTvStatusPage", function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
var page = this;
|
|
|
|
taskButton({
|
|
|
|
mode: "off",
|
|
|
|
progressElem: page.querySelector(".refreshGuideProgress"),
|
|
|
|
taskKey: "RefreshGuide",
|
|
|
|
button: page.querySelector(".btnRefresh")
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
2019-10-01 14:28:37 -07:00
|
|
|
});
|