diff --git a/src/components/channelmapper/channelmapper.js b/src/components/channelmapper/channelmapper.js index 2abf7e2c9e..d1fdcb1985 100644 --- a/src/components/channelmapper/channelmapper.js +++ b/src/components/channelmapper/channelmapper.js @@ -1,10 +1,15 @@ -define(["dialogHelper", "loading", "connectionManager", "globalize", "actionsheet", "emby-input", "paper-icon-button-light", "emby-button", "listViewStyle", "material-icons", "formDialogStyle"], function(dialogHelper, loading, connectionManager, globalize, actionsheet) { +define(["dialogHelper", "loading", "connectionManager", "globalize", "actionsheet", "emby-input", "paper-icon-button-light", "emby-button", "listViewStyle", "material-icons", "formDialogStyle"], function (dialogHelper, loading, connectionManager, globalize, actionsheet) { "use strict"; - return function(options) { + + return function (options) { function parentWithClass(elem, className) { - for (; !elem.classList || !elem.classList.contains(className);) - if (!(elem = elem.parentNode)) return null; - return elem + for (; !elem.classList || !elem.classList.contains(className);) { + if (!(elem = elem.parentNode)) { + return null; + } + } + + return elem; } function mapChannel(button, channelId, providerChannelId) { @@ -19,33 +24,35 @@ define(["dialogHelper", "loading", "connectionManager", "globalize", "actionshee providerChannelId: providerChannelId }, dataType: "json" - }).then(function(mapping) { + }).then(function (mapping) { var listItem = parentWithClass(button, "listItem"); - button.setAttribute("data-providerid", mapping.ProviderChannelId), listItem.querySelector(".secondary").innerHTML = getMappingSecondaryName(mapping, currentMappingOptions.ProviderName), loading.hide() - }) + button.setAttribute("data-providerid", mapping.ProviderChannelId); + listItem.querySelector(".secondary").innerHTML = getMappingSecondaryName(mapping, currentMappingOptions.ProviderName); + loading.hide(); + }); } function onChannelsElementClick(e) { var btnMap = parentWithClass(e.target, "btnMap"); + if (btnMap) { var channelId = btnMap.getAttribute("data-id"); var providerChannelId = btnMap.getAttribute("data-providerid"); - var menuItems = currentMappingOptions.ProviderChannels.map(function(m) { + var menuItems = currentMappingOptions.ProviderChannels.map(function (m) { return { name: m.Name, id: m.Id, selected: m.Id.toLowerCase() === providerChannelId.toLowerCase() - } + }; }).sort(function (a, b) { return a.name.localeCompare(b.name); }); - actionsheet.show({ positionTo: btnMap, items: menuItems - }).then(function(newChannelId) { - mapChannel(btnMap, channelId, newChannelId) - }) + }).then(function (newChannelId) { + mapChannel(btnMap, channelId, newChannelId); + }); } } @@ -53,47 +60,87 @@ define(["dialogHelper", "loading", "connectionManager", "globalize", "actionshee var apiClient = connectionManager.getApiClient(serverId); return apiClient.getJSON(apiClient.getUrl("LiveTv/ChannelMappingOptions", { providerId: providerId - })) + })); } function getMappingSecondaryName(mapping, providerName) { - return (mapping.ProviderChannelName || "") + " - " + providerName + return (mapping.ProviderChannelName || "") + " - " + providerName; } function getTunerChannelHtml(channel, providerName) { var html = ""; - return html += '
', html += 'dvr', html += '
', html += '

', html += channel.Name, html += "

", html += '
', channel.ProviderChannelName && (html += getMappingSecondaryName(channel, providerName)), html += "
", html += "
", html += '', html += "
" + html += '
'; + html += 'dvr'; + html += '
'; + html += '

'; + html += channel.Name; + html += "

"; + html += '
'; + + if (channel.ProviderChannelName) { + html += getMappingSecondaryName(channel, providerName); + } + + html += "
"; + html += "
"; + html += ''; + return html += "
"; } function getEditorHtml() { var html = ""; - return html += '
', html += '
', html += '
', html += "

" + globalize.translate("HeaderChannels") + "

", html += '
', html += "
", html += "
", html += "
", html += "
" + html += '
'; + html += '
'; + html += '
'; + html += "

" + globalize.translate("HeaderChannels") + "

"; + html += '
'; + html += "
"; + html += "
"; + html += "
"; + return html += "
"; } function initEditor(dlg, options) { - getChannelMappingOptions(options.serverId, options.providerId).then(function(result) { + getChannelMappingOptions(options.serverId, options.providerId).then(function (result) { currentMappingOptions = result; var channelsElement = dlg.querySelector(".channels"); - channelsElement.innerHTML = result.TunerChannels.map(function(channel) { - return getTunerChannelHtml(channel, result.ProviderName) - }).join(""), channelsElement.addEventListener("click", onChannelsElementClick) - }) + channelsElement.innerHTML = result.TunerChannels.map(function (channel) { + return getTunerChannelHtml(channel, result.ProviderName); + }).join(""); + channelsElement.addEventListener("click", onChannelsElementClick); + }); } - var currentMappingOptions, self = this; - self.show = function() { + + var currentMappingOptions; + var self = this; + + self.show = function () { var dialogOptions = { - removeOnClose: !0 + removeOnClose: true }; dialogOptions.size = "small"; var dlg = dialogHelper.createDialog(dialogOptions); - dlg.classList.add("formDialog"), dlg.classList.add("ui-body-a"), dlg.classList.add("background-theme-a"); - var html = "", - title = globalize.translate("MapChannels"); - return html += '
', html += '', html += '

', html += title, html += "

", html += "
", html += getEditorHtml(), dlg.innerHTML = html, initEditor(dlg, options), dlg.querySelector(".btnCancel").addEventListener("click", function() { - dialogHelper.close(dlg) - }), new Promise(function(resolve, reject) { - dlg.addEventListener("close", resolve), dialogHelper.open(dlg) - }) - } - } + dlg.classList.add("formDialog"); + dlg.classList.add("ui-body-a"); + dlg.classList.add("background-theme-a"); + var html = ""; + var title = globalize.translate("MapChannels"); + html += '
'; + html += ''; + html += '

'; + html += title; + html += "

"; + html += "
"; + 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); + }); + }; + }; });