jellyfin-web/dashboard-ui/scripts/livetvtunerprovider-satip.js

135 lines
4.3 KiB
JavaScript
Raw Normal View History

2016-03-16 14:30:49 -07:00
define(['jQuery'], function ($) {
2016-03-13 00:34:17 -07:00
function reload(page, providerId) {
page.querySelector('.txtDevicePath').value = '';
if (providerId) {
ApiClient.getNamedConfiguration("livetv").then(function (config) {
var info = config.TunerHosts.filter(function (i) {
return i.Id == providerId;
})[0];
page.querySelector('.txtDevicePath').value = info.Url || '';
2016-03-17 10:11:23 -07:00
page.querySelector('.txtM3uUrl').value = info.M3UUrl || '';
2016-03-13 20:32:03 -07:00
page.querySelector('.chkEnabled').checked = info.IsEnabled;
2016-03-13 00:34:17 -07:00
});
}
}
2016-03-13 20:32:03 -07:00
function fillInfoFromPage(page, info) {
info.Url = page.querySelector('.txtDevicePath').value;
2016-03-17 10:11:23 -07:00
info.M3UUrl = page.querySelector('.txtM3uUrl').value;
2016-03-13 20:32:03 -07:00
info.IsEnabled = page.querySelector('.chkEnabled').checked;
2016-03-31 12:41:52 -07:00
info.DiseqC = page.querySelector('.selectDiseqC').value;
info.SourceA = page.querySelector('.selectSourceA').value;
info.SourceB = page.querySelector('.selectSourceB').value;
info.SourceC = page.querySelector('.selectSourceC').value;
info.SourceD = page.querySelector('.selectSourceD').value;
2016-03-13 20:32:03 -07:00
}
2016-03-13 00:34:17 -07:00
function submitTunerInfo(page, info) {
ApiClient.ajax({
type: "POST",
url: ApiClient.getUrl('LiveTv/TunerHosts'),
data: JSON.stringify(info),
contentType: "application/json"
}).then(function () {
Dashboard.processServerConfigurationUpdateResult();
Dashboard.navigate('livetvstatus.html');
}, function () {
Dashboard.hideLoadingMsg();
Dashboard.alert({
message: Globalize.translate('ErrorSavingTvProvider')
});
});
}
2016-03-17 11:19:39 -07:00
function populateMappings(view) {
2016-03-13 20:32:03 -07:00
2016-03-17 11:19:39 -07:00
ApiClient.getJSON(ApiClient.getUrl('LiveTv/TunerHosts/Satip/IniMappings')).then(function (mappings) {
2016-03-13 20:32:03 -07:00
2016-03-17 11:19:39 -07:00
var optionsHtml = mappings.map(function (m) {
return '<option value="' + m.Value + '">' + m.Name + '</option>';
}).join('');
2016-03-13 20:32:03 -07:00
2016-03-17 11:19:39 -07:00
optionsHtml = '<option value="">' + Globalize.translate('OptionNone') + '</option>' + optionsHtml;
2016-03-13 20:32:03 -07:00
2016-03-17 11:19:39 -07:00
view.querySelector('.selectSourceA').innerHTML = optionsHtml;
view.querySelector('.selectSourceB').innerHTML = optionsHtml;
view.querySelector('.selectSourceC').innerHTML = optionsHtml;
view.querySelector('.selectSourceD').innerHTML = optionsHtml;
});
2016-03-13 20:32:03 -07:00
}
2016-03-17 11:19:39 -07:00
return function (view, params) {
2016-03-18 12:43:17 -07:00
function submitForm() {
Dashboard.showLoadingMsg();
var id = params.id;
if (id) {
ApiClient.getNamedConfiguration("livetv").then(function (config) {
var info = config.TunerHosts.filter(function (i) {
return i.Id == id;
})[0];
fillInfoFromPage(view, info);
submitTunerInfo(view, info);
});
} else {
var info = {
Type: 'satip'
};
fillInfoFromPage(view, info);
submitTunerInfo(view, info);
}
}
2016-03-17 11:19:39 -07:00
function onSelectDiseqCChange(e) {
var select = e.target;
var value = select.value;
2016-03-13 00:34:17 -07:00
2016-03-17 11:19:39 -07:00
if (value) {
view.querySelector('.fldSourceB').classList.remove('hide');
} else {
view.querySelector('.fldSourceB').classList.add('hide');
}
2016-03-13 00:34:17 -07:00
2016-03-17 11:19:39 -07:00
if (value == 'diseqc1') {
view.querySelector('.fldSourceC').classList.remove('hide');
view.querySelector('.fldSourceD').classList.remove('hide');
} else {
view.querySelector('.fldSourceC').classList.add('hide');
view.querySelector('.fldSourceD').classList.add('hide');
}
}
view.querySelector('form').addEventListener('submit', function (e) {
2016-03-18 12:43:17 -07:00
submitForm();
2016-03-17 11:19:39 -07:00
e.preventDefault();
2016-03-13 00:34:17 -07:00
return false;
});
2016-03-17 11:19:39 -07:00
view.querySelector('.selectDiseqC').addEventListener('change', onSelectDiseqCChange);
2016-03-13 20:32:03 -07:00
2016-03-17 11:19:39 -07:00
populateMappings(view);
2016-03-13 00:34:17 -07:00
2016-03-17 11:19:39 -07:00
view.addEventListener('viewshow', function (e) {
var providerId = params.id;
reload(view, providerId);
});
}
2016-03-16 14:30:49 -07:00
});