2020-08-14 08:46:34 +02:00
|
|
|
import 'jquery';
|
|
|
|
import globalize from '../../../scripts/globalize';
|
|
|
|
import loading from '../../../components/loading/loading';
|
|
|
|
import libraryMenu from '../../../scripts/libraryMenu';
|
2021-01-26 16:25:38 -05:00
|
|
|
import '../../../components/listview/listview.scss';
|
2020-08-14 08:46:34 +02:00
|
|
|
import '../../../elements/emby-button/emby-button';
|
2020-10-18 15:18:15 +01:00
|
|
|
import confirm from '../../../components/confirm/confirm';
|
2020-07-11 16:54:20 +01:00
|
|
|
|
|
|
|
/* eslint-disable indent */
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function loadProfiles(page) {
|
2019-11-06 13:43:39 +03:00
|
|
|
loading.show();
|
2020-05-04 12:44:12 +02:00
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Dlna/ProfileInfos')).then(function (result) {
|
2019-11-06 13:43:39 +03:00
|
|
|
renderUserProfiles(page, result);
|
|
|
|
renderSystemProfiles(page, result);
|
|
|
|
loading.hide();
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderUserProfiles(page, profiles) {
|
2020-05-04 12:44:12 +02:00
|
|
|
renderProfiles(page, page.querySelector('.customProfiles'), profiles.filter(function (p) {
|
2020-07-30 16:07:13 +02:00
|
|
|
return p.Type == 'User';
|
2019-11-06 13:43:39 +03:00
|
|
|
}));
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderSystemProfiles(page, profiles) {
|
2020-05-04 12:44:12 +02:00
|
|
|
renderProfiles(page, page.querySelector('.systemProfiles'), profiles.filter(function (p) {
|
2020-07-30 16:07:13 +02:00
|
|
|
return p.Type == 'System';
|
2019-11-06 13:43:39 +03:00
|
|
|
}));
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderProfiles(page, element, profiles) {
|
2020-07-11 16:54:20 +01:00
|
|
|
let html = '';
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
if (profiles.length) {
|
|
|
|
html += '<div class="paperList">';
|
|
|
|
}
|
|
|
|
|
2020-07-11 16:54:20 +01:00
|
|
|
for (let i = 0, length = profiles.length; i < length; i++) {
|
2020-07-19 17:38:42 +02:00
|
|
|
const profile = profiles[i];
|
2019-11-06 13:43:39 +03:00
|
|
|
html += '<div class="listItem listItem-border">';
|
2022-02-24 20:15:24 +03:00
|
|
|
html += '<span class="listItemIcon material-icons live_tv" aria-hidden="true"></span>';
|
2019-11-06 13:43:39 +03:00
|
|
|
html += '<div class="listItemBody two-line">';
|
2020-12-09 12:23:14 -05:00
|
|
|
html += "<a is='emby-linkbutton' style='padding:0;margin:0;' data-ripple='false' class='clearLink' href='#!/dlnaprofile.html?id=" + profile.Id + "'>";
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '<div>' + profile.Name + '</div>';
|
|
|
|
html += '</a>';
|
|
|
|
html += '</div>';
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-30 16:07:13 +02:00
|
|
|
if (profile.Type == 'User') {
|
2022-02-24 20:15:24 +03:00
|
|
|
html += '<button type="button" is="paper-icon-button-light" class="btnDeleteProfile" data-profileid="' + profile.Id + '" title="' + globalize.translate('Delete') + '"><span class="material-icons delete" aria-hidden="true"></span></button>';
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</div>';
|
2019-11-06 13:43:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (profiles.length) {
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</div>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
element.innerHTML = html;
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.btnDeleteProfile', element).on('click', function () {
|
2020-07-11 16:54:20 +01:00
|
|
|
const id = this.getAttribute('data-profileid');
|
2019-11-06 13:43:39 +03:00
|
|
|
deleteProfile(page, id);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteProfile(page, id) {
|
2020-10-18 15:18:15 +01:00
|
|
|
confirm(globalize.translate('MessageConfirmProfileDeletion'), globalize.translate('HeaderConfirmProfileDeletion')).then(function () {
|
|
|
|
loading.show();
|
|
|
|
ApiClient.ajax({
|
|
|
|
type: 'DELETE',
|
|
|
|
url: ApiClient.getUrl('Dlna/Profiles/' + id)
|
|
|
|
}).then(function () {
|
|
|
|
loading.hide();
|
|
|
|
loadProfiles(page);
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getTabs() {
|
|
|
|
return [{
|
2020-12-03 16:13:27 -05:00
|
|
|
href: '#!/dlnasettings.html',
|
2020-08-24 08:20:29 +09:00
|
|
|
name: globalize.translate('Settings')
|
2018-10-23 01:05:09 +03:00
|
|
|
}, {
|
2020-12-03 16:13:27 -05:00
|
|
|
href: '#!/dlnaprofiles.html',
|
2020-05-04 12:44:12 +02:00
|
|
|
name: globalize.translate('TabProfiles')
|
2019-11-06 13:43:39 +03:00
|
|
|
}];
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-04-03 00:12:02 +01:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
$(document).on('pageshow', '#dlnaProfilesPage', function () {
|
|
|
|
libraryMenu.setTabs('dlna', 1, getTabs);
|
2019-11-06 13:43:39 +03:00
|
|
|
loadProfiles(this);
|
|
|
|
});
|
2020-07-11 16:54:20 +01:00
|
|
|
|
|
|
|
/* eslint-enable indent */
|