diff --git a/dashboard-ui/scripts/userlibraryaccess.js b/dashboard-ui/scripts/userlibraryaccess.js new file mode 100644 index 0000000000..113c6e5ae6 --- /dev/null +++ b/dashboard-ui/scripts/userlibraryaccess.js @@ -0,0 +1,151 @@ +(function ($, window, document) { + + function loadMediaFolders(page, user, mediaFolders) { + + var html = ''; + + html += '
'; + + $('.mediaFolderAccess', page).html(html).trigger('create'); + } + + function loadChannels(page, user, channels) { + + var html = ''; + + html += ''; + + $('.channelAccess', page).show().html(html).trigger('create'); + + if (channels.length) { + $('.channelAccessContainer', page).show(); + } else { + $('.channelAccessContainer', page).hide(); + } + } + + function loadUser(page, user, loggedInUser, mediaFolders, channels) { + + Dashboard.setPageTitle(user.Name); + + loadChannels(page, user, channels); + loadMediaFolders(page, user, mediaFolders); + + Dashboard.hideLoadingMsg(); + } + + function onSaveComplete(page) { + + Dashboard.hideLoadingMsg(); + + Dashboard.alert(Globalize.translate('SettingsSaved')); + } + + function saveUser(user, page) { + + user.Configuration.BlockedMediaFolders = $('.chkMediaFolder:not(:checked)', page).map(function () { + + return this.getAttribute('data-foldername'); + + }).get(); + + user.Configuration.BlockedChannels = $('.chkChannel:not(:checked)', page).map(function () { + + return this.getAttribute('data-foldername'); + + }).get(); + + ApiClient.updateUser(user).done(function () { + onSaveComplete(page); + }); + } + + window.LibraryAccessPage = { + + onSubmit: function () { + + var page = $(this).parents('.page'); + + Dashboard.showLoadingMsg(); + + var userId = getParameterByName("userId"); + + ApiClient.getUser(userId).done(function (result) { + saveUser(result, page); + }); + + // Disable default form submission + return false; + } + }; + + $(document).on('pageshow', "#userLibraryAccessPage", function () { + + var page = this; + + Dashboard.showLoadingMsg(); + + var userId = getParameterByName("userId"); + + var promise1; + + if (!userId) { + + var deferred = $.Deferred(); + + deferred.resolveWith(null, [{ + Configuration: {} + }]); + + promise1 = deferred.promise(); + } else { + + promise1 = ApiClient.getUser(userId); + } + + var promise2 = Dashboard.getCurrentUser(); + + var promise4 = ApiClient.getJSON(ApiClient.getUrl("Library/MediaFolders", { IsHidden: false })); + + var promise5 = ApiClient.getJSON(ApiClient.getUrl("Channels")); + + $.when(promise1, promise2, promise4, promise5).done(function (response1, response2, response4, response5) { + + loadUser(page, response1[0] || response1, response2[0], response4[0].Items, response5[0].Items); + + }); + }); + +})(jQuery, window, document); \ No newline at end of file diff --git a/dashboard-ui/scripts/userparentalcontrol.js b/dashboard-ui/scripts/userparentalcontrol.js index e4f95bb06b..ec5c94ab10 100644 --- a/dashboard-ui/scripts/userparentalcontrol.js +++ b/dashboard-ui/scripts/userparentalcontrol.js @@ -38,62 +38,6 @@ $('#selectMaxParentalRating', page).html(html).selectmenu("refresh"); } - function loadMediaFolders(page, user, mediaFolders) { - - var html = ''; - - html += ''; - - $('.mediaFolderAccess', page).html(html).trigger('create'); - } - - function loadChannels(page, user, channels) { - - var html = ''; - - html += ''; - - $('.channelAccess', page).show().html(html).trigger('create'); - - if (channels.length) { - $('.channelAccessContainer', page).show(); - } else { - $('.channelAccessContainer', page).hide(); - } - } - function loadUnratedItems(page, user) { var items = [ @@ -132,12 +76,10 @@ $('.blockUnratedItems', page).html(html).trigger('create'); } - function loadUser(page, user, loggedInUser, allParentalRatings, mediaFolders, channels) { + function loadUser(page, user, loggedInUser, allParentalRatings) { Dashboard.setPageTitle(user.Name); - loadChannels(page, user, channels); - loadMediaFolders(page, user, mediaFolders); loadUnratedItems(page, user); populateRatings(allParentalRatings, page); @@ -172,18 +114,6 @@ user.Configuration.MaxParentalRating = $('#selectMaxParentalRating', page).val() || null; - user.Configuration.BlockedMediaFolders = $('.chkMediaFolder:not(:checked)', page).map(function () { - - return this.getAttribute('data-foldername'); - - }).get(); - - user.Configuration.BlockedChannels = $('.chkChannel:not(:checked)', page).map(function () { - - return this.getAttribute('data-foldername'); - - }).get(); - user.Configuration.BlockUnratedItems = $('.chkUnratedItem:checked', page).map(function () { return this.getAttribute('data-itemtype'); @@ -242,13 +172,9 @@ var promise3 = ApiClient.getParentalRatings(); - var promise4 = ApiClient.getJSON(ApiClient.getUrl("Library/MediaFolders", { IsHidden: false })); + $.when(promise1, promise2, promise3).done(function (response1, response2, response3) { - var promise5 = ApiClient.getJSON(ApiClient.getUrl("Channels")); - - $.when(promise1, promise2, promise3, promise4, promise5).done(function (response1, response2, response3, response4, response5) { - - loadUser(page, response1[0] || response1, response2[0], response3[0], response4[0].Items, response5[0].Items); + loadUser(page, response1[0] || response1, response2[0], response3[0]); }); }); diff --git a/dashboard-ui/scripts/userprofilespage.js b/dashboard-ui/scripts/userprofilespage.js index 07bb5bc3d4..490d97a705 100644 --- a/dashboard-ui/scripts/userprofilespage.js +++ b/dashboard-ui/scripts/userprofilespage.js @@ -57,7 +57,7 @@ }); } - function getUserHtml(user) { + function getUserHtml(user, addConnectIndicator) { var html = ''; @@ -93,7 +93,7 @@ html += '@@ -32,7 +33,7 @@