1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/controllers/dashboard/dlna/profiles.js

90 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-05-04 12:44:12 +02:00
define(['jQuery', 'globalize', 'loading', 'libraryMenu', 'listViewStyle', 'emby-button'], function ($, globalize, loading, libraryMenu) {
'use strict';
2018-10-23 01:05:09 +03:00
function loadProfiles(page) {
loading.show();
2020-05-04 12:44:12 +02:00
ApiClient.getJSON(ApiClient.getUrl('Dlna/ProfileInfos')).then(function (result) {
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) {
return 'User' == p.Type;
}));
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) {
return 'System' == p.Type;
}));
2018-10-23 01:05:09 +03:00
}
function renderProfiles(page, element, profiles) {
2020-05-04 12:44:12 +02:00
var html = '';
if (profiles.length) {
html += '<div class="paperList">';
}
2018-10-23 01:05:09 +03:00
for (var i = 0, length = profiles.length; i < length; i++) {
var profile = profiles[i];
html += '<div class="listItem listItem-border">';
2020-04-26 02:37:28 +03:00
html += '<span class="listItemIcon material-icons live_tv"></span>';
html += '<div class="listItemBody two-line">';
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>';
2020-05-04 12:44:12 +02:00
if ('User' == profile.Type) {
html += '<button type="button" is="paper-icon-button-light" class="btnDeleteProfile" data-profileid="' + profile.Id + '" title="' + globalize.translate('ButtonDelete') + '"><span class="material-icons delete"></span></button>';
}
2020-05-04 12:44:12 +02:00
html += '</div>';
}
if (profiles.length) {
2020-05-04 12:44:12 +02:00
html += '</div>';
2018-10-23 01:05:09 +03:00
}
element.innerHTML = html;
2020-05-04 12:44:12 +02:00
$('.btnDeleteProfile', element).on('click', function () {
var id = this.getAttribute('data-profileid');
deleteProfile(page, id);
});
2018-10-23 01:05:09 +03:00
}
function deleteProfile(page, id) {
2020-05-04 12:44:12 +02:00
require(['confirm'], function (confirm) {
confirm(globalize.translate('MessageConfirmProfileDeletion'), globalize.translate('HeaderConfirmProfileDeletion')).then(function () {
loading.show();
ApiClient.ajax({
2020-05-04 12:44:12 +02:00
type: 'DELETE',
url: ApiClient.getUrl('Dlna/Profiles/' + id)
}).then(function () {
loading.hide();
loadProfiles(page);
});
});
});
2018-10-23 01:05:09 +03:00
}
function getTabs() {
return [{
2020-05-04 12:44:12 +02:00
href: 'dlnasettings.html',
name: globalize.translate('TabSettings')
2018-10-23 01:05:09 +03:00
}, {
2020-05-04 12:44:12 +02:00
href: 'dlnaprofiles.html',
name: globalize.translate('TabProfiles')
}];
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);
loadProfiles(this);
});
});