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

162 lines
4.5 KiB
JavaScript
Raw Normal View History

2014-10-29 15:01:02 -07:00
(function ($, window, document) {
2014-12-22 20:58:14 -07:00
function loadMediaFolders(page, mediaFolders) {
2014-10-29 19:06:05 -07:00
var html = '';
html += '<fieldset data-role="controlgroup">';
2015-01-19 22:19:13 -07:00
html += '<legend>' + Globalize.translate('HeaderLibraries') + '</legend>';
2014-10-29 19:06:05 -07:00
for (var i = 0, length = mediaFolders.length; i < length; i++) {
var folder = mediaFolders[i];
var id = 'mediaFolder' + i;
2014-12-22 20:58:14 -07:00
var checkedAttribute = ' checked="checked"';
2014-10-29 19:06:05 -07:00
2015-01-19 22:19:13 -07:00
html += '<input class="chkFolder" data-id="' + folder.Id + '" type="checkbox" id="' + id + '"' + checkedAttribute + ' />';
2014-10-29 19:06:05 -07:00
html += '<label for="' + id + '">' + folder.Name + '</label>';
}
html += '</fieldset>';
2015-01-19 22:19:13 -07:00
$('.folderAccess', page).html(html).trigger('create');
$('#chkEnableAllFolders', page).checked(true).checkboxradio('refresh').trigger('change');
2014-10-29 19:06:05 -07:00
}
2014-12-22 20:58:14 -07:00
function loadChannels(page, channels) {
2014-10-29 19:06:05 -07:00
var html = '';
html += '<fieldset data-role="controlgroup">';
html += '<legend>' + Globalize.translate('HeaderChannels') + '</legend>';
for (var i = 0, length = channels.length; i < length; i++) {
var folder = channels[i];
var id = 'channels' + i;
2014-12-22 20:58:14 -07:00
var checkedAttribute = ' checked="checked"';
2014-10-29 19:06:05 -07:00
2015-01-13 21:20:30 -07:00
html += '<input class="chkChannel" data-id="' + folder.Id + '" type="checkbox" id="' + id + '"' + checkedAttribute + ' />';
2014-10-29 19:06:05 -07:00
html += '<label for="' + id + '">' + folder.Name + '</label>';
}
html += '</fieldset>';
$('.channelAccess', page).show().html(html).trigger('create');
if (channels.length) {
$('.channelAccessContainer', page).show();
} else {
$('.channelAccessContainer', page).hide();
}
2015-01-19 13:53:02 -07:00
$('#chkEnableAllChannels', page).checked(true).checkboxradio('refresh').trigger('change');
2014-10-29 19:06:05 -07:00
}
2014-12-22 20:58:14 -07:00
function loadUser(page) {
2014-10-29 15:01:02 -07:00
2014-12-22 20:58:14 -07:00
$('#txtUserName', page).val('');
2014-10-29 19:06:05 -07:00
Dashboard.showLoadingMsg();
var promise4 = ApiClient.getJSON(ApiClient.getUrl("Library/MediaFolders", { IsHidden: false }));
var promise5 = ApiClient.getJSON(ApiClient.getUrl("Channels"));
$.when(promise4, promise5).done(function (response4, response5) {
2014-12-22 20:58:14 -07:00
loadMediaFolders(page, response4[0].Items);
loadChannels(page, response5[0].Items);
2014-10-29 19:06:05 -07:00
Dashboard.hideLoadingMsg();
});
2014-10-29 15:01:02 -07:00
}
2014-10-29 19:06:05 -07:00
function saveUser(page) {
var name = $('#txtUserName', page).val();
ApiClient.createUser(name).done(function (user) {
2015-01-19 22:19:13 -07:00
user.Policy.EnableAllFolders = $('#chkEnableAllFolders', page).checked();
user.Policy.EnabledFolders = user.Policy.EnableAllFolders ?
[] :
$('.chkFolder:checked', page).map(function () {
2014-10-29 15:01:02 -07:00
2015-01-19 22:19:13 -07:00
return this.getAttribute('data-id');
2014-10-29 15:01:02 -07:00
2015-01-19 22:19:13 -07:00
}).get();
2014-10-29 19:06:05 -07:00
2015-01-19 13:53:02 -07:00
user.Policy.EnableAllChannels = $('#chkEnableAllChannels', page).checked();
user.Policy.EnabledChannels = user.Policy.EnableAllChannels ?
[] :
$('.chkChannel:checked', page).map(function () {
2014-10-29 19:06:05 -07:00
2015-01-19 13:53:02 -07:00
return this.getAttribute('data-id');
2014-10-29 19:06:05 -07:00
2015-01-19 13:53:02 -07:00
}).get();
2015-01-13 21:20:30 -07:00
2014-12-19 23:06:27 -07:00
ApiClient.updateUserPolicy(user.Id, user.Policy).done(function () {
2014-10-29 19:06:05 -07:00
Dashboard.navigate("useredit.html?userId=" + user.Id);
});
2014-10-29 15:01:02 -07:00
});
}
2015-05-17 18:27:48 -07:00
function onSubmit() {
var page = $(this).parents('.page');
2014-10-29 15:01:02 -07:00
2015-05-17 18:27:48 -07:00
Dashboard.showLoadingMsg();
2014-10-29 15:01:02 -07:00
2015-05-17 18:27:48 -07:00
saveUser(page);
2014-10-29 15:01:02 -07:00
2015-05-17 18:27:48 -07:00
// Disable default form submission
return false;
2014-10-29 15:01:02 -07:00
}
function loadData(page) {
2014-12-22 20:58:14 -07:00
loadUser(page);
2014-10-29 15:01:02 -07:00
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#newUserPage", function () {
2015-01-19 13:53:02 -07:00
var page = this;
$('#chkEnableAllChannels', page).on('change', function () {
if (this.checked) {
$('.channelAccessListContainer', page).hide();
} else {
$('.channelAccessListContainer', page).show();
}
});
2015-01-19 22:19:13 -07:00
$('#chkEnableAllFolders', page).on('change', function () {
if (this.checked) {
$('.folderAccessListContainer', page).hide();
} else {
$('.folderAccessListContainer', page).show();
}
});
2015-05-17 18:27:48 -07:00
$('.newUserProfileForm').off('submit', onSubmit).on('submit', onSubmit);
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#newUserPage", function () {
2014-10-29 15:01:02 -07:00
var page = this;
loadData(page);
});
})(jQuery, window, document);