(function ($, window, document) { function loadMediaFolders(page, user, mediaFolders) { var html = ''; html += '
'; $('.folderAccess', page).html(html).trigger('create'); $('#chkEnableAllFolders', page).checked(user.Policy.EnableAllFolders).checkboxradio('refresh').trigger('change'); } 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(); } $('#chkEnableAllChannels', page).checked(user.Policy.EnableAllChannels).checkboxradio('refresh').trigger('change'); } function loadDevices(page, user, devices) { var html = ''; html += ''; $('.deviceAccess', page).show().html(html).trigger('create'); $('#chkEnableAllDevices', page).checked(user.Policy.EnableAllDevices).checkboxradio('refresh').trigger('change'); } function loadUser(page, user, loggedInUser, mediaFolders, channels, devices) { $(page).trigger('userloaded', [user]); Dashboard.setPageTitle(user.Name); loadChannels(page, user, channels); loadMediaFolders(page, user, mediaFolders); loadDevices(page, user, devices); Dashboard.hideLoadingMsg(); } function onSaveComplete(page) { Dashboard.hideLoadingMsg(); Dashboard.alert(Globalize.translate('SettingsSaved')); } function saveUser(user, page) { user.Policy.EnableAllFolders = $('#chkEnableAllFolders', page).checked(); user.Policy.EnabledFolders = user.Policy.EnableAllFolders ? [] : $('.chkFolder:checked', page).map(function () { return this.getAttribute('data-id'); }).get(); user.Policy.EnableAllChannels = $('#chkEnableAllChannels', page).checked(); user.Policy.EnabledChannels = user.Policy.EnableAllChannels ? [] : $('.chkChannel:checked', page).map(function () { return this.getAttribute('data-id'); }).get(); user.Policy.EnableAllDevices = $('#chkEnableAllDevices', page).checked(); user.Policy.EnabledDevices = user.Policy.EnableAllDevices ? [] : $('.chkDevice:checked', page).map(function () { return this.getAttribute('data-id'); }).get(); // Legacy user.Policy.BlockedChannels = null; user.Policy.BlockedMediaFolders = null; ApiClient.updateUserPolicy(user.Id, user.Policy).done(function () { onSaveComplete(page); }); } function onSubmit() { 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('pageinit', "#userLibraryAccessPage", function () { var page = this; $('#chkEnableAllDevices', page).on('change', function () { if (this.checked) { $('.deviceAccessListContainer', page).hide(); } else { $('.deviceAccessListContainer', page).show(); } }); $('#chkEnableAllChannels', page).on('change', function () { if (this.checked) { $('.channelAccessListContainer', page).hide(); } else { $('.channelAccessListContainer', page).show(); } }); $('#chkEnableAllFolders', page).on('change', function () { if (this.checked) { $('.folderAccessListContainer', page).hide(); } else { $('.folderAccessListContainer', page).show(); } }); $('.userLibraryAccessForm').off('submit', onSubmit).on('submit', onSubmit); }).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")); var promise6 = ApiClient.getJSON(ApiClient.getUrl('Devices', { SupportsPersistentIdentifier: true })); $.when(promise1, promise2, promise4, promise5, promise6).done(function (response1, response2, response4, response5, response6) { loadUser(page, response1[0] || response1, response2[0], response4[0].Items, response5[0].Items, response6[0].Items); }); }); })(jQuery, window, document);