define(['dialogHelper', 'dom', 'layoutManager', 'connectionManager', 'globalize', 'loading', 'browser', 'focusManager', 'scrollHelper', 'material-icons', 'formDialogStyle', 'emby-button', 'emby-itemscontainer', 'cardStyle'], function (dialogHelper, dom, layoutManager, connectionManager, globalize, loading, browser, focusManager, scrollHelper) { 'use strict'; var enableFocusTransform = !browser.slow && !browser.edge; function getEditorHtml() { var html = ''; html += '
'; html += '
'; html += '
'; html += '

' + globalize.translate('DetectingDevices') + '...

'; html += '

' + globalize.translate('MessagePleaseWait') + '

'; html += '
'; html += '

' + globalize.translate('HeaderNewDevices') + '

'; html += '
'; html += '
'; html += '
'; return html += '
'; } function getDeviceHtml(device) { var padderClass; var html = ''; var cssClass = 'card scalableCard'; var cardBoxCssClass = 'cardBox visualCardBox'; cssClass += ' backdropCard backdropCard-scalable'; padderClass = 'cardPadder-backdrop'; // TODO move card creation code to Card component if (layoutManager.tv) { cssClass += ' show-focus'; if (enableFocusTransform) { cssClass += ' show-animation'; } } html += ''; } function getTunerName(providerId) { switch (providerId = providerId.toLowerCase()) { case 'm3u': return 'M3U'; case 'hdhomerun': return 'HDHomerun'; case 'hauppauge': return 'Hauppauge'; case 'satip': return 'DVB'; default: return 'Unknown'; } } function renderDevices(view, devices) { var i; var length; var html = ''; for (i = 0, length = devices.length; i < length; i++) { html += getDeviceHtml(devices[i]); } if (devices.length) { view.querySelector('.devicesHeader').classList.remove('hide'); } else { html = '


' + globalize.translate('NoNewDevicesFound') + '

'; view.querySelector('.devicesHeader').classList.add('hide'); } var elem = view.querySelector('.results'); elem.innerHTML = html; if (layoutManager.tv) { focusManager.autoFocus(elem); } } function discoverDevices(view, apiClient) { loading.show(); view.querySelector('.loadingContent').classList.remove('hide'); return ApiClient.getJSON(ApiClient.getUrl('LiveTv/Tuners/Discvover', { NewDevicesOnly: true })).then(function (devices) { currentDevices = devices; renderDevices(view, devices); view.querySelector('.loadingContent').classList.add('hide'); loading.hide(); }); } function tunerPicker() { this.show = function (options) { var dialogOptions = { removeOnClose: true, scrollY: false }; if (layoutManager.tv) { dialogOptions.size = 'fullscreen'; } else { dialogOptions.size = 'small'; } var dlg = dialogHelper.createDialog(dialogOptions); dlg.classList.add('formDialog'); var html = ''; html += '
'; html += ''; html += '

'; html += globalize.translate('HeaderLiveTvTunerSetup'); html += '

'; html += '
'; html += getEditorHtml(); dlg.innerHTML = html; dlg.querySelector('.btnCancel').addEventListener('click', function () { dialogHelper.close(dlg); }); var deviceResult; dlg.querySelector('.results').addEventListener('click', function (e) { var tunerCard = dom.parentWithClass(e.target, 'card'); if (tunerCard) { var deviceId = tunerCard.getAttribute('data-id'); deviceResult = currentDevices.filter(function (d) { return d.DeviceId === deviceId; })[0]; dialogHelper.close(dlg); } }); if (layoutManager.tv) { scrollHelper.centerFocus.on(dlg.querySelector('.formDialogContent'), false); } var apiClient = connectionManager.getApiClient(options.serverId); discoverDevices(dlg, apiClient); if (layoutManager.tv) { scrollHelper.centerFocus.off(dlg.querySelector('.formDialogContent'), false); } return dialogHelper.open(dlg).then(function () { if (deviceResult) { return Promise.resolve(deviceResult); } return Promise.reject(); }); }; } var currentDevices = []; return tunerPicker; });