2020-07-09 13:47:35 +01:00
|
|
|
import $ from 'jQuery';
|
|
|
|
import loading from 'loading';
|
|
|
|
import globalize from 'globalize';
|
|
|
|
import 'emby-checkbox';
|
|
|
|
|
|
|
|
/* eslint-disable indent */
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function loadMediaFolders(page, mediaFolders) {
|
2020-07-11 14:04:11 +01:00
|
|
|
let html = '';
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '<h3 class="checkboxListLabel">' + globalize.translate('HeaderLibraries') + '</h3>';
|
2019-06-29 23:45:07 -07:00
|
|
|
html += '<div class="checkboxList paperList" style="padding:.5em 1em;">';
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-11 14:04:11 +01:00
|
|
|
for (let i = 0; i < mediaFolders.length; i++) {
|
|
|
|
const folder = mediaFolders[i];
|
2020-05-14 13:26:52 +09:00
|
|
|
html += '<label><input type="checkbox" is="emby-checkbox" class="chkFolder" data-id="' + folder.Id + '"/><span>' + folder.Name + '</span></label>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</div>';
|
|
|
|
$('.folderAccess', page).html(html).trigger('create');
|
2020-06-07 17:14:01 -06:00
|
|
|
$('#chkEnableAllFolders', page).prop('checked', false);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadChannels(page, channels) {
|
2020-07-11 14:04:11 +01:00
|
|
|
let html = '';
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '<h3 class="checkboxListLabel">' + globalize.translate('HeaderChannels') + '</h3>';
|
2019-06-29 23:45:07 -07:00
|
|
|
html += '<div class="checkboxList paperList" style="padding:.5em 1em;">';
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-07-11 14:04:11 +01:00
|
|
|
for (let i = 0; i < channels.length; i++) {
|
|
|
|
const folder = channels[i];
|
2020-05-14 13:26:52 +09:00
|
|
|
html += '<label><input type="checkbox" is="emby-checkbox" class="chkChannel" data-id="' + folder.Id + '"/><span>' + folder.Name + '</span></label>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
html += '</div>';
|
|
|
|
$('.channelAccess', page).show().html(html).trigger('create');
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2019-07-01 12:42:15 -07:00
|
|
|
if (channels.length) {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.channelAccessContainer', page).show();
|
2019-07-01 12:42:15 -07:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.channelAccessContainer', page).hide();
|
2019-07-01 12:42:15 -07:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-06-07 17:14:01 -06:00
|
|
|
$('#chkEnableAllChannels', page).prop('checked', false);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadUser(page) {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('#txtUsername', page).val('');
|
|
|
|
$('#txtPassword', page).val('');
|
2019-06-29 23:45:07 -07:00
|
|
|
loading.show();
|
2020-07-11 14:04:11 +01:00
|
|
|
const promiseFolders = ApiClient.getJSON(ApiClient.getUrl('Library/MediaFolders', {
|
2019-11-06 13:43:39 +03:00
|
|
|
IsHidden: false
|
2019-06-29 23:45:07 -07:00
|
|
|
}));
|
2020-07-11 14:04:11 +01:00
|
|
|
const promiseChannels = ApiClient.getJSON(ApiClient.getUrl('Channels'));
|
2019-11-06 13:43:39 +03:00
|
|
|
Promise.all([promiseFolders, promiseChannels]).then(function (responses) {
|
2019-06-29 23:45:07 -07:00
|
|
|
loadMediaFolders(page, responses[0].Items);
|
|
|
|
loadChannels(page, responses[1].Items);
|
|
|
|
loading.hide();
|
2019-11-06 13:43:39 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveUser(page) {
|
2020-07-11 14:04:11 +01:00
|
|
|
const user = {};
|
2020-05-04 12:44:12 +02:00
|
|
|
user.Name = $('#txtUsername', page).val();
|
|
|
|
user.Password = $('#txtPassword', page).val();
|
2019-11-06 13:43:39 +03:00
|
|
|
ApiClient.createUser(user).then(function (user) {
|
2020-06-07 17:14:01 -06:00
|
|
|
user.Policy.EnableAllFolders = $('#chkEnableAllFolders', page).is(':checked');
|
2019-07-01 12:42:15 -07:00
|
|
|
user.Policy.EnabledFolders = [];
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2019-07-01 12:42:15 -07:00
|
|
|
if (!user.Policy.EnableAllFolders) {
|
2020-05-04 12:44:12 +02:00
|
|
|
user.Policy.EnabledFolders = $('.chkFolder', page).get().filter(function (i) {
|
2019-11-06 13:43:39 +03:00
|
|
|
return i.checked;
|
|
|
|
}).map(function (i) {
|
2020-05-04 12:44:12 +02:00
|
|
|
return i.getAttribute('data-id');
|
2019-07-01 12:42:15 -07:00
|
|
|
});
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2020-06-07 17:14:01 -06:00
|
|
|
user.Policy.EnableAllChannels = $('#chkEnableAllChannels', page).is(':checked');
|
2019-07-01 12:42:15 -07:00
|
|
|
user.Policy.EnabledChannels = [];
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2019-07-01 12:42:15 -07:00
|
|
|
if (!user.Policy.EnableAllChannels) {
|
2020-05-04 12:44:12 +02:00
|
|
|
user.Policy.EnabledChannels = $('.chkChannel', page).get().filter(function (i) {
|
2019-11-06 13:43:39 +03:00
|
|
|
return i.checked;
|
|
|
|
}).map(function (i) {
|
2020-05-04 12:44:12 +02:00
|
|
|
return i.getAttribute('data-id');
|
2019-07-01 12:42:15 -07:00
|
|
|
});
|
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
|
|
|
|
ApiClient.updateUserPolicy(user.Id, user.Policy).then(function () {
|
2020-05-04 12:44:12 +02:00
|
|
|
Dashboard.navigate('useredit.html?userId=' + user.Id);
|
2019-06-29 23:45:07 -07:00
|
|
|
});
|
2019-11-06 13:43:39 +03:00
|
|
|
}, function (response) {
|
2020-07-09 13:47:35 +01:00
|
|
|
import('toast').then(({default: toast}) => {
|
2020-08-01 00:18:24 +09:00
|
|
|
toast(globalize.translate('MessageDefaultError'));
|
2019-06-30 01:52:57 -07:00
|
|
|
});
|
2019-11-06 13:43:39 +03:00
|
|
|
|
2019-06-29 23:45:07 -07:00
|
|
|
loading.hide();
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSubmit() {
|
2020-07-11 14:04:11 +01:00
|
|
|
const page = $(this).parents('.page')[0];
|
2019-06-29 23:45:07 -07:00
|
|
|
loading.show();
|
|
|
|
saveUser(page);
|
|
|
|
return false;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadData(page) {
|
2019-06-29 23:45:07 -07:00
|
|
|
loadUser(page);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-06-29 23:45:07 -07:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
$(document).on('pageinit', '#newUserPage', function () {
|
2020-07-11 14:04:11 +01:00
|
|
|
const page = this;
|
2020-05-04 12:44:12 +02:00
|
|
|
$('#chkEnableAllChannels', page).on('change', function () {
|
2019-07-01 12:42:15 -07:00
|
|
|
if (this.checked) {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.channelAccessListContainer', page).hide();
|
2019-07-01 12:42:15 -07:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.channelAccessListContainer', page).show();
|
2019-07-01 12:42:15 -07:00
|
|
|
}
|
2019-06-29 23:45:07 -07:00
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
$('#chkEnableAllFolders', page).on('change', function () {
|
2019-07-01 12:42:15 -07:00
|
|
|
if (this.checked) {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.folderAccessListContainer', page).hide();
|
2019-07-01 12:42:15 -07:00
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.folderAccessListContainer', page).show();
|
2019-07-01 12:42:15 -07:00
|
|
|
}
|
2019-06-29 23:45:07 -07:00
|
|
|
});
|
2020-05-04 12:44:12 +02:00
|
|
|
$('.newUserProfileForm').off('submit', onSubmit).on('submit', onSubmit);
|
|
|
|
}).on('pageshow', '#newUserPage', function () {
|
2019-06-29 23:45:07 -07:00
|
|
|
loadData(this);
|
|
|
|
});
|
2020-07-09 13:47:35 +01:00
|
|
|
|
|
|
|
/* eslint-enable indent */
|