jellyfin-web/dashboard-ui/scripts/dlnaprofiles.js

116 lines
2.8 KiB
JavaScript
Raw Normal View History

2014-03-26 12:21:29 -07:00
(function ($, document, window) {
function loadProfiles(page) {
Dashboard.showLoadingMsg();
2014-07-01 22:16:59 -07:00
ApiClient.getJSON(ApiClient.getUrl("Dlna/ProfileInfos")).done(function (result) {
2014-03-26 12:21:29 -07:00
renderProfiles(page, result);
Dashboard.hideLoadingMsg();
});
}
function renderProfiles(page, profiles) {
renderUserProfiles(page, profiles);
renderSystemProfiles(page, profiles);
}
function renderUserProfiles(page, profiles) {
profiles = profiles.filter(function (p) {
return p.Type == 'User';
});
var html = '';
html += '<ul data-role="listview" data-inset="true" data-split-icon="delete">';
for (var i = 0, length = profiles.length; i < length; i++) {
var profile = profiles[i];
html += '<li>';
2014-10-06 16:58:46 -07:00
html += '<a href="dlnaprofile.html?id=' + profile.Id + '">';
2014-03-26 12:21:29 -07:00
html += profile.Name;
html += '</a>';
2014-05-30 14:06:57 -07:00
html += '<a href="#" data-icon="delete" class="btnDeleteProfile" data-profileid="' + profile.Id + '">' + Globalize.translate('Delete') + '</a>';
2014-03-26 12:21:29 -07:00
html += '</li>';
}
html += '</ul>';
var elem = $('.customProfiles', page).html(html).trigger('create');
$('.btnDeleteProfile', elem).on('click', function () {
var id = this.getAttribute('data-profileid');
deleteProfile(page, id);
});
}
function renderSystemProfiles(page, profiles) {
profiles = profiles.filter(function (p) {
return p.Type == 'System';
});
var html = '';
html += '<ul data-role="listview" data-inset="true">';
for (var i = 0, length = profiles.length; i < length; i++) {
var profile = profiles[i];
html += '<li>';
2014-10-06 16:58:46 -07:00
html += '<a href="dlnaprofile.html?id=' + profile.Id + '">';
2014-03-26 12:21:29 -07:00
html += profile.Name;
html += '</a>';
html += '</li>';
}
html += '</ul>';
$('.systemProfiles', page).html(html).trigger('create');
}
function deleteProfile(page, id) {
2014-05-30 14:06:57 -07:00
Dashboard.confirm(Globalize.translate('MessageConfirmProfileDeletion'), Globalize.translate('HeaderConfirmProfileDeletion'), function (result) {
2014-03-26 12:21:29 -07:00
if (result) {
Dashboard.showLoadingMsg();
2014-07-01 22:16:59 -07:00
ApiClient.ajax({
2014-03-26 12:21:29 -07:00
type: "DELETE",
url: ApiClient.getUrl("Dlna/Profiles/" + id)
}).done(function () {
Dashboard.hideLoadingMsg();
loadProfiles(page);
});
}
});
}
$(document).on('pageshow', "#dlnaProfilesPage", function () {
var page = this;
loadProfiles(page);
});
})(jQuery, document, window);