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/channelmapper/channelmapper.js

137 lines
5.9 KiB
JavaScript
Raw Normal View History

define(["dom", "dialogHelper", "loading", "connectionManager", "globalize", "actionsheet", "emby-input", "paper-icon-button-light", "emby-button", "listViewStyle", "material-icons", "formDialogStyle"], function (dom, dialogHelper, loading, connectionManager, globalize, actionsheet) {
2018-10-23 01:05:09 +03:00
"use strict";
2019-10-09 18:52:14 +03:00
return function (options) {
2018-10-23 01:05:09 +03:00
function mapChannel(button, channelId, providerChannelId) {
loading.show();
var providerId = options.providerId;
connectionManager.getApiClient(options.serverId).ajax({
type: "POST",
url: ApiClient.getUrl("LiveTv/ChannelMappings"),
data: {
providerId: providerId,
tunerChannelId: channelId,
providerChannelId: providerChannelId
},
dataType: "json"
2019-10-09 18:52:14 +03:00
}).then(function (mapping) {
var listItem = dom.parentWithClass(button, "listItem");
2019-10-09 18:52:14 +03:00
button.setAttribute("data-providerid", mapping.ProviderChannelId);
listItem.querySelector(".secondary").innerHTML = getMappingSecondaryName(mapping, currentMappingOptions.ProviderName);
loading.hide();
});
2018-10-23 01:05:09 +03:00
}
function onChannelsElementClick(e) {
var btnMap = dom.parentWithClass(e.target, "btnMap");
2019-10-09 18:52:14 +03:00
2018-10-23 01:05:09 +03:00
if (btnMap) {
2019-06-23 16:56:04 +01:00
var channelId = btnMap.getAttribute("data-id");
var providerChannelId = btnMap.getAttribute("data-providerid");
2019-10-09 18:52:14 +03:00
var menuItems = currentMappingOptions.ProviderChannels.map(function (m) {
2019-06-23 16:54:13 +01:00
return {
name: m.Name,
id: m.Id,
selected: m.Id.toLowerCase() === providerChannelId.toLowerCase()
2019-10-09 18:52:14 +03:00
};
2019-06-23 16:54:13 +01:00
}).sort(function (a, b) {
return a.name.localeCompare(b.name);
});
2018-10-23 01:05:09 +03:00
actionsheet.show({
positionTo: btnMap,
items: menuItems
2019-10-09 18:52:14 +03:00
}).then(function (newChannelId) {
mapChannel(btnMap, channelId, newChannelId);
});
2018-10-23 01:05:09 +03:00
}
}
function getChannelMappingOptions(serverId, providerId) {
var apiClient = connectionManager.getApiClient(serverId);
return apiClient.getJSON(apiClient.getUrl("LiveTv/ChannelMappingOptions", {
providerId: providerId
2019-10-09 18:52:14 +03:00
}));
2018-10-23 01:05:09 +03:00
}
function getMappingSecondaryName(mapping, providerName) {
2019-10-09 18:52:14 +03:00
return (mapping.ProviderChannelName || "") + " - " + providerName;
2018-10-23 01:05:09 +03:00
}
function getTunerChannelHtml(channel, providerName) {
var html = "";
2019-10-09 18:52:14 +03:00
html += '<div class="listItem">';
2020-04-25 10:00:20 +03:00
html += '<i class="material-icons listItemIcon dvr"></i>';
2019-10-09 18:52:14 +03:00
html += '<div class="listItemBody two-line">';
html += '<h3 class="listItemBodyText">';
html += channel.Name;
html += "</h3>";
html += '<div class="secondary listItemBodyText">';
if (channel.ProviderChannelName) {
html += getMappingSecondaryName(channel, providerName);
}
html += "</div>";
html += "</div>";
2020-02-23 01:22:55 +03:00
html += '<button class="btnMap autoSize" is="paper-icon-button-light" type="button" data-id="' + channel.Id + '" data-providerid="' + channel.ProviderChannelId + '"><i class="material-icons mode_edit"></i></button>';
2019-10-09 18:52:14 +03:00
return html += "</div>";
2018-10-23 01:05:09 +03:00
}
function getEditorHtml() {
var html = "";
2019-10-09 18:52:14 +03:00
html += '<div class="formDialogContent">';
html += '<div class="dialogContentInner dialog-content-centered">';
html += '<form style="margin:auto;">';
html += "<h1>" + globalize.translate("HeaderChannels") + "</h1>";
html += '<div class="channels paperList">';
html += "</div>";
html += "</form>";
html += "</div>";
return html += "</div>";
2018-10-23 01:05:09 +03:00
}
function initEditor(dlg, options) {
2019-10-09 18:52:14 +03:00
getChannelMappingOptions(options.serverId, options.providerId).then(function (result) {
2018-10-23 01:05:09 +03:00
currentMappingOptions = result;
var channelsElement = dlg.querySelector(".channels");
2019-10-09 18:52:14 +03:00
channelsElement.innerHTML = result.TunerChannels.map(function (channel) {
return getTunerChannelHtml(channel, result.ProviderName);
}).join("");
channelsElement.addEventListener("click", onChannelsElementClick);
});
2018-10-23 01:05:09 +03:00
}
2019-10-09 18:52:14 +03:00
var currentMappingOptions;
var self = this;
self.show = function () {
2018-10-23 01:05:09 +03:00
var dialogOptions = {
2019-10-09 18:52:14 +03:00
removeOnClose: true
2018-10-23 01:05:09 +03:00
};
dialogOptions.size = "small";
var dlg = dialogHelper.createDialog(dialogOptions);
2019-10-09 18:52:14 +03:00
dlg.classList.add("formDialog");
dlg.classList.add("ui-body-a");
dlg.classList.add("background-theme-a");
var html = "";
var title = globalize.translate("MapChannels");
html += '<div class="formDialogHeader">';
html += '<button is="paper-icon-button-light" class="btnCancel autoSize" tabindex="-1"><i class="material-icons arrow_back"></i></button>';
2019-10-09 18:52:14 +03:00
html += '<h3 class="formDialogHeaderTitle">';
html += title;
html += "</h3>";
html += "</div>";
html += getEditorHtml();
dlg.innerHTML = html;
initEditor(dlg, options);
dlg.querySelector(".btnCancel").addEventListener("click", function () {
dialogHelper.close(dlg);
});
return new Promise(function (resolve, reject) {
dlg.addEventListener("close", resolve);
dialogHelper.open(dlg);
});
};
};
2019-06-23 16:54:13 +01:00
});