2020-05-04 12:44:12 +02:00
|
|
|
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) {
|
|
|
|
'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({
|
2020-05-04 12:44:12 +02:00
|
|
|
type: 'POST',
|
|
|
|
url: ApiClient.getUrl('LiveTv/ChannelMappings'),
|
2018-10-23 01:05:09 +03:00
|
|
|
data: {
|
|
|
|
providerId: providerId,
|
|
|
|
tunerChannelId: channelId,
|
|
|
|
providerChannelId: providerChannelId
|
|
|
|
},
|
2020-05-04 12:44:12 +02:00
|
|
|
dataType: 'json'
|
2019-10-09 18:52:14 +03:00
|
|
|
}).then(function (mapping) {
|
2020-05-04 12:44:12 +02:00
|
|
|
var listItem = dom.parentWithClass(button, 'listItem');
|
|
|
|
button.setAttribute('data-providerid', mapping.ProviderChannelId);
|
|
|
|
listItem.querySelector('.secondary').innerHTML = getMappingSecondaryName(mapping, currentMappingOptions.ProviderName);
|
2019-10-09 18:52:14 +03:00
|
|
|
loading.hide();
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onChannelsElementClick(e) {
|
2020-05-04 12:44:12 +02:00
|
|
|
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) {
|
2020-05-04 12:44:12 +02: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);
|
2020-05-04 12:44:12 +02:00
|
|
|
return apiClient.getJSON(apiClient.getUrl('LiveTv/ChannelMappingOptions', {
|
2018-10-23 01:05:09 +03:00
|
|
|
providerId: providerId
|
2019-10-09 18:52:14 +03:00
|
|
|
}));
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getMappingSecondaryName(mapping, providerName) {
|
2020-05-04 12:44:12 +02:00
|
|
|
return (mapping.ProviderChannelName || '') + ' - ' + providerName;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTunerChannelHtml(channel, providerName) {
|
2020-05-04 12:44:12 +02:00
|
|
|
var html = '';
|
2019-10-09 18:52:14 +03:00
|
|
|
html += '<div class="listItem">';
|
2020-04-26 02:37:28 +03:00
|
|
|
html += '<span class="material-icons listItemIcon dvr"></span>';
|
2019-10-09 18:52:14 +03:00
|
|
|
html += '<div class="listItemBody two-line">';
|
|
|
|
html += '<h3 class="listItemBodyText">';
|
|
|
|
html += channel.Name;
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</h3>';
|
2019-10-09 18:52:14 +03:00
|
|
|
html += '<div class="secondary listItemBodyText">';
|
|
|
|
|
|
|
|
if (channel.ProviderChannelName) {
|
|
|
|
html += getMappingSecondaryName(channel, providerName);
|
|
|
|
}
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</div>';
|
|
|
|
html += '</div>';
|
2020-04-26 02:37:28 +03:00
|
|
|
html += '<button class="btnMap autoSize" is="paper-icon-button-light" type="button" data-id="' + channel.Id + '" data-providerid="' + channel.ProviderChannelId + '"><span class="material-icons mode_edit"></span></button>';
|
2020-05-04 12:44:12 +02:00
|
|
|
return html += '</div>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getEditorHtml() {
|
2020-05-04 12:44:12 +02:00
|
|
|
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;">';
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '<h1>' + globalize.translate('HeaderChannels') + '</h1>';
|
2019-10-09 18:52:14 +03:00
|
|
|
html += '<div class="channels paperList">';
|
2020-05-04 12:44:12 +02:00
|
|
|
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;
|
2020-05-04 12:44:12 +02:00
|
|
|
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);
|
2020-05-04 12:44:12 +02:00
|
|
|
}).join('');
|
|
|
|
channelsElement.addEventListener('click', onChannelsElementClick);
|
2019-10-09 18:52:14 +03:00
|
|
|
});
|
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
|
|
|
};
|
2020-05-04 12:44:12 +02:00
|
|
|
dialogOptions.size = 'small';
|
2018-10-23 01:05:09 +03:00
|
|
|
var dlg = dialogHelper.createDialog(dialogOptions);
|
2020-05-04 12:44:12 +02:00
|
|
|
dlg.classList.add('formDialog');
|
|
|
|
dlg.classList.add('ui-body-a');
|
|
|
|
dlg.classList.add('background-theme-a');
|
|
|
|
var html = '';
|
|
|
|
var title = globalize.translate('MapChannels');
|
2019-10-09 18:52:14 +03:00
|
|
|
html += '<div class="formDialogHeader">';
|
2020-04-26 02:37:28 +03:00
|
|
|
html += '<button is="paper-icon-button-light" class="btnCancel autoSize" tabindex="-1"><span class="material-icons arrow_back"></span></button>';
|
2019-10-09 18:52:14 +03:00
|
|
|
html += '<h3 class="formDialogHeaderTitle">';
|
|
|
|
html += title;
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</h3>';
|
|
|
|
html += '</div>';
|
2019-10-09 18:52:14 +03:00
|
|
|
html += getEditorHtml();
|
|
|
|
dlg.innerHTML = html;
|
|
|
|
initEditor(dlg, options);
|
2020-05-04 12:44:12 +02:00
|
|
|
dlg.querySelector('.btnCancel').addEventListener('click', function () {
|
2019-10-09 18:52:14 +03:00
|
|
|
dialogHelper.close(dlg);
|
|
|
|
});
|
|
|
|
return new Promise(function (resolve, reject) {
|
2020-05-04 12:44:12 +02:00
|
|
|
dlg.addEventListener('close', resolve);
|
2019-10-09 18:52:14 +03:00
|
|
|
dialogHelper.open(dlg);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
2019-06-23 16:54:13 +01:00
|
|
|
});
|