define(['dialogHelper', 'loading', 'connectionManager', 'globalize', 'paper-checkbox', 'emby-input', 'paper-icon-button-light', 'emby-select', 'emby-button', 'listViewStyle'], function (dialogHelper, loading, connectionManager, globalize) { var currentServerId; function getChannelMappingOptions(serverId, providerId) { return connectionManager.getApiClient(serverId).getJSON(ApiClient.getUrl('LiveTv/ChannelMappingOptions', { providerId: providerId })); } function getTunerChannelHtml(channel, providerName) { var html = ''; html += '
'; html += ''; html += '
'; html += '

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

'; if (channel.ProviderChannelNumber || channel.ProviderChannelName) { html += '
'; html += (channel.ProviderChannelNumber || '') + ' ' + (channel.ProviderChannelName || '') + ' - ' + providerName; html += '
'; } html += '
'; html += ''; html += '
'; return html; } function getEditorHtml() { var html = ''; html += '
'; html += '
'; html += '
'; html += '

' + globalize.translate('HeaderChannels') + '

'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; return html; } function initEditor(dlg, options) { getChannelMappingOptions(options.serverId, options.providerId).then(function (result) { dlg.querySelector('.channels').innerHTML = result.TunerChannels.map(function (channel) { return getTunerChannelHtml(channel, result.ProviderName); }).join(''); }); } return function () { var self = this; self.show = function (options) { currentServerId = options.serverId; var dialogOptions = { 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 = ''; var title = globalize.translate('MapChannels'); html += '
'; html += ''; html += '
'; html += title; html += '
'; html += '
'; html += getEditorHtml(); dlg.innerHTML = html; document.body.appendChild(dlg); 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); }); }; }; });