2016-03-18 14:12:44 -07:00
|
|
|
|
define(['jQuery','paper-checkbox', 'paper-input', 'paper-item-body', 'paper-icon-item'], function ($) {
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
|
|
|
|
return function (page, providerId, options) {
|
|
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
|
|
var listingsId;
|
|
|
|
|
|
|
|
|
|
function reload() {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getNamedConfiguration("livetv").then(function (config) {
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
|
|
|
|
var info = config.ListingProviders.filter(function (i) {
|
|
|
|
|
return i.Id == providerId;
|
|
|
|
|
})[0] || {};
|
|
|
|
|
|
|
|
|
|
listingsId = info.ListingsId;
|
2015-09-03 10:01:51 -07:00
|
|
|
|
$('#selectListing', page).val(info.ListingsId || '');
|
2015-08-21 19:59:10 -07:00
|
|
|
|
page.querySelector('.txtUser').value = info.Username || '';
|
2015-10-10 17:39:30 -07:00
|
|
|
|
page.querySelector('.txtPass').value = '';
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
|
|
|
|
page.querySelector('.txtZipCode').value = info.ZipCode || '';
|
|
|
|
|
|
2015-10-10 17:39:30 -07:00
|
|
|
|
if (info.Username && info.Password) {
|
|
|
|
|
page.querySelector('.listingsSection').classList.remove('hide');
|
|
|
|
|
} else {
|
|
|
|
|
page.querySelector('.listingsSection').classList.add('hide');
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 11:46:52 -07:00
|
|
|
|
page.querySelector('.chkAllTuners').checked = info.EnableAllTuners;
|
|
|
|
|
|
|
|
|
|
if (page.querySelector('.chkAllTuners').checked) {
|
|
|
|
|
page.querySelector('.selectTunersSection').classList.add('hide');
|
|
|
|
|
} else {
|
|
|
|
|
page.querySelector('.selectTunersSection').classList.remove('hide');
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-21 19:59:10 -07:00
|
|
|
|
setCountry(info);
|
2016-03-14 11:46:52 -07:00
|
|
|
|
refreshTunerDevices(page, info, config.TunerHosts);
|
2015-08-21 19:59:10 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setCountry(info) {
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl('LiveTv/ListingProviders/SchedulesDirect/Countries')).then(function (result) {
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
|
|
|
|
var countryList = [];
|
|
|
|
|
var i, length;
|
|
|
|
|
|
|
|
|
|
for (var region in result) {
|
|
|
|
|
var countries = result[region];
|
|
|
|
|
|
|
|
|
|
if (countries.length && region !== 'ZZZ') {
|
|
|
|
|
for (i = 0, length = countries.length; i < length; i++) {
|
|
|
|
|
countryList.push({
|
|
|
|
|
name: countries[i].fullName,
|
|
|
|
|
value: countries[i].shortName
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
countryList.sort(function (a, b) {
|
|
|
|
|
if (a.name > b.name) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (a.name < b.name) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
// a must be equal to b
|
|
|
|
|
return 0;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#selectCountry', page).html(countryList.map(function (c) {
|
|
|
|
|
|
|
|
|
|
return '<option value="' + c.value + '">' + c.name + '</option>';
|
|
|
|
|
|
2015-09-03 10:01:51 -07:00
|
|
|
|
}).join('')).val(info.Country || '');
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
|
|
|
|
$(page.querySelector('.txtZipCode')).trigger('change');
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}, function () {
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: Globalize.translate('ErrorGettingTvLineups')
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function submitLoginForm() {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2015-09-09 10:49:44 -07:00
|
|
|
|
require(["cryptojs-sha1"], function () {
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
2015-09-09 10:49:44 -07:00
|
|
|
|
var info = {
|
|
|
|
|
Type: 'SchedulesDirect',
|
|
|
|
|
Username: page.querySelector('.txtUser').value,
|
2016-03-14 11:46:52 -07:00
|
|
|
|
EnableAllTuners: true,
|
2015-09-09 10:49:44 -07:00
|
|
|
|
Password: CryptoJS.SHA1(page.querySelector('.txtPass').value).toString()
|
|
|
|
|
};
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
2015-09-09 10:49:44 -07:00
|
|
|
|
var id = providerId;
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
2015-09-09 10:49:44 -07:00
|
|
|
|
if (id) {
|
|
|
|
|
info.Id = id;
|
|
|
|
|
}
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
2015-09-09 10:49:44 -07:00
|
|
|
|
ApiClient.ajax({
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: ApiClient.getUrl('LiveTv/ListingProviders', {
|
|
|
|
|
ValidateLogin: true
|
|
|
|
|
}),
|
|
|
|
|
data: JSON.stringify(info),
|
2015-12-14 08:43:03 -07:00
|
|
|
|
contentType: "application/json",
|
|
|
|
|
dataType: 'json'
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}).then(function (result) {
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
2015-09-09 10:49:44 -07:00
|
|
|
|
Dashboard.processServerConfigurationUpdateResult();
|
|
|
|
|
providerId = result.Id;
|
|
|
|
|
reload();
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}, function () {
|
2015-09-09 10:49:44 -07:00
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: Globalize.translate('ErrorSavingTvProvider')
|
|
|
|
|
});
|
2015-08-21 19:59:10 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function submitListingsForm() {
|
|
|
|
|
|
|
|
|
|
var selectedListingsId = $('#selectListing', page).val();
|
|
|
|
|
|
|
|
|
|
if (!selectedListingsId) {
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: Globalize.translate('ErrorPleaseSelectLineup')
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var id = providerId;
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getNamedConfiguration("livetv").then(function (config) {
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
|
|
|
|
var info = config.ListingProviders.filter(function (i) {
|
|
|
|
|
return i.Id == id;
|
|
|
|
|
})[0];
|
|
|
|
|
|
|
|
|
|
info.ZipCode = page.querySelector('.txtZipCode').value;
|
|
|
|
|
info.Country = $('#selectCountry', page).val();
|
|
|
|
|
info.ListingsId = selectedListingsId;
|
2016-03-14 11:46:52 -07:00
|
|
|
|
info.EnableAllTuners = page.querySelector('.chkAllTuners').checked;
|
|
|
|
|
info.EnabledTuners = info.EnableAllTuners ? [] : $('.chkTuner', page).get().filter(function (i) {
|
|
|
|
|
return i.checked;
|
|
|
|
|
}).map(function (i) {
|
|
|
|
|
return i.getAttribute('data-id');
|
|
|
|
|
});
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
|
|
|
|
ApiClient.ajax({
|
|
|
|
|
type: "POST",
|
|
|
|
|
url: ApiClient.getUrl('LiveTv/ListingProviders', {
|
|
|
|
|
ValidateListings: true
|
|
|
|
|
}),
|
|
|
|
|
data: JSON.stringify(info),
|
|
|
|
|
contentType: "application/json"
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}).then(function (result) {
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
2015-08-22 09:55:23 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
if (options.showConfirmation !== false) {
|
|
|
|
|
Dashboard.processServerConfigurationUpdateResult();
|
|
|
|
|
}
|
2015-12-23 10:46:01 -07:00
|
|
|
|
Events.trigger(self, 'submitted');
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}, function () {
|
2015-08-22 09:55:23 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
2015-08-21 19:59:10 -07:00
|
|
|
|
Dashboard.alert({
|
2015-10-17 18:18:29 -07:00
|
|
|
|
message: Globalize.translate('ErrorAddingListingsToSchedulesDirect')
|
2015-08-21 19:59:10 -07:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function refreshListings(value) {
|
|
|
|
|
|
|
|
|
|
if (!value) {
|
2015-09-03 10:01:51 -07:00
|
|
|
|
$('#selectListing', page).html('');
|
2015-08-21 19:59:10 -07:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 10:30:39 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
|
|
|
|
ApiClient.ajax({
|
|
|
|
|
type: "GET",
|
|
|
|
|
url: ApiClient.getUrl('LiveTv/ListingProviders/Lineups', {
|
|
|
|
|
Id: providerId,
|
|
|
|
|
Location: value,
|
|
|
|
|
Country: $('#selectCountry', page).val()
|
|
|
|
|
}),
|
|
|
|
|
dataType: 'json'
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}).then(function (result) {
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
|
|
|
|
$('#selectListing', page).html(result.map(function (o) {
|
|
|
|
|
|
|
|
|
|
return '<option value="' + o.Id + '">' + o.Name + '</option>';
|
|
|
|
|
|
2015-09-03 10:01:51 -07:00
|
|
|
|
}));
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
|
|
|
|
if (listingsId) {
|
2015-09-03 10:01:51 -07:00
|
|
|
|
$('#selectListing', page).val(listingsId);
|
2015-08-21 19:59:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 10:30:39 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}, function (result) {
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: Globalize.translate('ErrorGettingTvLineups')
|
|
|
|
|
});
|
|
|
|
|
refreshListings('');
|
2016-07-22 10:30:39 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
2015-08-21 19:59:10 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 11:46:52 -07:00
|
|
|
|
function getTunerName(providerId) {
|
|
|
|
|
|
|
|
|
|
providerId = providerId.toLowerCase();
|
|
|
|
|
|
|
|
|
|
switch (providerId) {
|
|
|
|
|
|
|
|
|
|
case 'm3u':
|
|
|
|
|
return 'M3U Playlist';
|
|
|
|
|
case 'hdhomerun':
|
|
|
|
|
return 'HDHomerun';
|
|
|
|
|
case 'satip':
|
|
|
|
|
return 'DVB';
|
|
|
|
|
default:
|
|
|
|
|
return 'Unknown';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function refreshTunerDevices(page, providerInfo, devices) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
for (var i = 0, length = devices.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
var device = devices[i];
|
|
|
|
|
|
|
|
|
|
html += '<paper-icon-item>';
|
|
|
|
|
|
2016-06-01 23:40:16 -07:00
|
|
|
|
var enabledTuners = providerInfo.EnableAllTuners || [];
|
|
|
|
|
var isChecked = providerInfo.EnableAllTuners || enabledTuners.indexOf(device.Id) != -1;
|
2016-03-14 11:46:52 -07:00
|
|
|
|
var checkedAttribute = isChecked ? ' checked' : '';
|
|
|
|
|
html += '<paper-checkbox data-id="' + device.Id + '" class="chkTuner" item-icon ' + checkedAttribute + '></paper-checkbox>';
|
|
|
|
|
|
|
|
|
|
html += '<paper-item-body two-line>';
|
|
|
|
|
html += '<div>';
|
|
|
|
|
html += device.FriendlyName || getTunerName(device.Type);
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
html += '<div secondary>';
|
|
|
|
|
html += device.Url;
|
|
|
|
|
html += '</div>';
|
|
|
|
|
html += '</paper-item-body>';
|
|
|
|
|
|
|
|
|
|
html += '</paper-icon-item>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
page.querySelector('.tunerList').innerHTML = html;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-21 19:59:10 -07:00
|
|
|
|
self.submit = function () {
|
|
|
|
|
page.querySelector('.btnSubmitListingsContainer').click();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.init = function () {
|
|
|
|
|
|
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
|
|
if (options.showCancelButton !== false) {
|
|
|
|
|
page.querySelector('.btnCancel').classList.remove('hide');
|
|
|
|
|
} else {
|
|
|
|
|
page.querySelector('.btnCancel').classList.add('hide');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.showSubmitButton !== false) {
|
|
|
|
|
page.querySelector('.btnSubmitListings').classList.remove('hide');
|
|
|
|
|
} else {
|
|
|
|
|
page.querySelector('.btnSubmitListings').classList.add('hide');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('.formLogin', page).on('submit', function () {
|
|
|
|
|
submitLoginForm();
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.formListings', page).on('submit', function () {
|
|
|
|
|
submitListingsForm();
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.txtZipCode', page).on('change', function () {
|
|
|
|
|
refreshListings(this.value);
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-14 11:46:52 -07:00
|
|
|
|
page.querySelector('.chkAllTuners').addEventListener('change', function (e) {
|
|
|
|
|
if (e.target.checked) {
|
|
|
|
|
page.querySelector('.selectTunersSection').classList.add('hide');
|
|
|
|
|
} else {
|
|
|
|
|
page.querySelector('.selectTunersSection').classList.remove('hide');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2015-08-21 19:59:10 -07:00
|
|
|
|
$('.createAccountHelp', page).html(Globalize.translate('MessageCreateAccountAt', '<a href="http://www.schedulesdirect.org" target="_blank">http://www.schedulesdirect.org</a>'));
|
|
|
|
|
|
|
|
|
|
reload();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
});
|