1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/components/channelmapper/channelmapper.js

171 lines
5.1 KiB
JavaScript
Raw Normal View History

2016-06-10 02:54:03 -04:00
define(['dialogHelper', 'loading', 'connectionManager', 'globalize', 'actionsheet', 'paper-checkbox', 'emby-input', 'paper-icon-button-light', 'emby-select', 'emby-button', 'listViewStyle', 'material-icons'],
function (dialogHelper, loading, connectionManager, globalize, actionsheet) {
2016-06-08 17:04:52 -04:00
2016-06-10 02:54:03 -04:00
return function (options) {
2016-06-08 17:04:52 -04:00
2016-06-10 02:54:03 -04:00
var self = this;
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
var currentMappingOptions;
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
function parentWithClass(elem, className) {
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
while (!elem.classList || !elem.classList.contains(className)) {
elem = elem.parentNode;
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
if (!elem) {
return null;
}
}
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
return elem;
}
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
function mapChannel(tunerChannelNumber, providerChannelNumber) {
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
alert('coming soon.');
2016-06-09 12:13:25 -04:00
}
2016-06-10 02:54:03 -04:00
function onChannelsElementClick(e) {
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
var btnMap = parentWithClass(e.target, 'btnMap');
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
if (!btnMap) {
return;
}
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
var channelNumber = btnMap.getAttribute('data-number');
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
var menuItems = currentMappingOptions.ProviderChannels.map(function (m) {
2016-06-08 17:04:52 -04:00
2016-06-10 02:54:03 -04:00
return {
name: m.Name,
id: m.Id,
selected: m.Id == channelNumber
};
});
2016-06-08 17:04:52 -04:00
2016-06-10 02:54:03 -04:00
actionsheet.show({
positionTo: btnMap,
items: menuItems
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
}).then(function (newChannelNumber) {
mapChannel(channelNumber, newChannelNumber);
});
}
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
function getChannelMappingOptions(serverId, providerId) {
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
return connectionManager.getApiClient(serverId).getJSON(ApiClient.getUrl('LiveTv/ChannelMappingOptions', {
providerId: providerId
}));
}
2016-06-08 17:04:52 -04:00
2016-06-10 02:54:03 -04:00
function getTunerChannelHtml(channel, providerName) {
2016-06-08 17:04:52 -04:00
2016-06-10 02:54:03 -04:00
var html = '';
2016-06-09 12:13:25 -04:00
2016-06-10 02:54:03 -04:00
html += '<div class="listItem">';
2016-06-08 17:04:52 -04:00
2016-06-10 02:54:03 -04:00
html += '<button is="emby-button" type="button" class="fab listItemIcon mini" style="background:#52B54B;"><iron-icon icon="dvr"></iron-icon></button>';
2016-06-08 17:04:52 -04:00
2016-06-10 02:54:03 -04:00
html += '<div class="listItemBody">';
html += '<h3>';
html += channel.Name;
html += '</h3>';
2016-06-08 17:04:52 -04:00
2016-06-10 02:54:03 -04:00
if (channel.ProviderChannelNumber || channel.ProviderChannelName) {
html += '<div class="secondary">';
html += (channel.ProviderChannelNumber || '') + ' ' + (channel.ProviderChannelName || '') + ' - ' + providerName;
html += '</div>';
}
2016-06-08 17:04:52 -04:00
2016-06-10 02:54:03 -04:00
html += '</div>';
html += '<button class="btnMap" is="paper-icon-button-light" type="button" data-number="' + channel.Number + '"><iron-icon icon="mode-edit"></iron-icon></button>';
html += '</div>';
return html;
}
function getEditorHtml() {
var html = '';
html += '<div class="dialogContent">';
html += '<div class="dialogContentInner centeredContent">';
html += '<form style="margin:auto;">';
html += '<h1>' + globalize.translate('HeaderChannels') + '</h1>';
html += '<div class="channels paperList">';
html += '</div>';
html += '</form>';
html += '</div>';
html += '</div>';
return html;
}
function initEditor(dlg, options) {
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);
});
}
2016-06-08 17:04:52 -04:00
2016-06-10 02:54:03 -04:00
self.show = function () {
2016-06-08 17:04:52 -04:00
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 += '<div class="dialogHeader" style="margin:0 0 2em;">';
2016-06-10 02:54:03 -04:00
html += '<button is="paper-icon-button-light" class="btnCancel autoSize" tabindex="-1"><i class="md-icon">arrow_back</i></button>';
2016-06-08 17:04:52 -04:00
html += '<div class="dialogHeaderTitle">';
html += title;
html += '</div>';
html += '</div>';
html += getEditorHtml();
dlg.innerHTML = html;
document.body.appendChild(dlg);
2016-06-09 12:13:25 -04:00
initEditor(dlg, options);
2016-06-08 17:04:52 -04:00
dlg.querySelector('.btnCancel').addEventListener('click', function () {
dialogHelper.close(dlg);
});
return new Promise(function (resolve, reject) {
dlg.addEventListener('close', resolve);
dialogHelper.open(dlg);
});
};
};
});