2016-03-18 21:26:17 -07:00
|
|
|
|
define(['jQuery'], function ($) {
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
|
|
|
|
function loadProfiles(page) {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl("Dlna/ProfileInfos")).then(function (result) {
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
renderUserProfiles(page, result);
|
|
|
|
|
renderSystemProfiles(page, result);
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderUserProfiles(page, profiles) {
|
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
renderProfiles(page, page.querySelector('.customProfiles'), profiles.filter(function (p) {
|
2014-03-26 12:21:29 -07:00
|
|
|
|
return p.Type == 'User';
|
2016-02-07 22:59:33 -07:00
|
|
|
|
}));
|
|
|
|
|
}
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
function renderSystemProfiles(page, profiles) {
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
renderProfiles(page, page.querySelector('.systemProfiles'), profiles.filter(function (p) {
|
|
|
|
|
return p.Type == 'System';
|
|
|
|
|
}));
|
|
|
|
|
}
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
function renderProfiles(page, element, profiles) {
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
require(['paper-fab', 'paper-item-body', 'paper-icon-item'], function () {
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
var html = '';
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
if (profiles.length) {
|
|
|
|
|
html += '<div class="paperList">';
|
|
|
|
|
}
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
for (var i = 0, length = profiles.length; i < length; i++) {
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
var profile = profiles[i];
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
html += '<paper-icon-item>';
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
html += "<a item-icon class='clearLink' href='dlnaprofile.html?id=" + profile.Id + "'>";
|
|
|
|
|
html += '<paper-fab mini icon="dvr" class="blue"></paper-fab>';
|
|
|
|
|
html += "</a>";
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
html += '<paper-item-body two-line>';
|
|
|
|
|
html += "<a class='clearLink' href='dlnaprofile.html?id=" + profile.Id + "'>";
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
html += "<div>" + profile.Name + "</div>";
|
|
|
|
|
//html += "<div secondary>" + task.Description + "</div>";
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
html += "</a>";
|
|
|
|
|
html += '</paper-item-body>';
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
if (profile.Type == 'User') {
|
2016-05-07 23:31:08 -07:00
|
|
|
|
html += '<button type="button" is="paper-icon-button-light" class="btnDeleteProfile" data-profileid="' + profile.Id + '" title="' + Globalize.translate('ButtonDelete') + '"><iron-icon icon="delete"></iron-icon></button>';
|
2016-02-07 22:59:33 -07:00
|
|
|
|
}
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
html += '</paper-icon-item>';
|
|
|
|
|
}
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
if (profiles.length) {
|
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
element.innerHTML = html;
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
$('.btnDeleteProfile', element).on('click', function () {
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-07 22:59:33 -07:00
|
|
|
|
var id = this.getAttribute('data-profileid');
|
|
|
|
|
deleteProfile(page, id);
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-03-26 12:21:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteProfile(page, id) {
|
|
|
|
|
|
2016-02-22 11:49:19 -07:00
|
|
|
|
require(['confirm'], function (confirm) {
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-02-22 11:49:19 -07:00
|
|
|
|
confirm(Globalize.translate('MessageConfirmProfileDeletion'), Globalize.translate('HeaderConfirmProfileDeletion')).then(function () {
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}).then(function () {
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
|
|
|
|
loadProfiles(page);
|
|
|
|
|
});
|
2016-02-22 11:49:19 -07:00
|
|
|
|
});
|
2014-03-26 12:21:29 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-12 23:02:07 -07:00
|
|
|
|
function getTabs() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
href: 'dlnasettings.html',
|
|
|
|
|
name: Globalize.translate('TabSettings')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
href: 'dlnaprofiles.html',
|
|
|
|
|
name: Globalize.translate('TabProfiles')
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-24 10:08:10 -07:00
|
|
|
|
$(document).on('pageshow', "#dlnaProfilesPage", function () {
|
2014-03-26 12:21:29 -07:00
|
|
|
|
|
2016-04-12 23:02:07 -07:00
|
|
|
|
LibraryMenu.setTabs('dlna', 1, getTabs);
|
2014-03-26 12:21:29 -07:00
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
loadProfiles(page);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-18 21:26:17 -07:00
|
|
|
|
});
|