2013-04-18 09:59:54 -07:00
|
|
|
|
(function ($, window, document) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-12-26 08:40:38 -07:00
|
|
|
|
function loadUser(page, user, loggedInUser) {
|
2013-04-18 09:59:54 -07:00
|
|
|
|
|
2013-05-07 11:56:44 -07:00
|
|
|
|
if (!loggedInUser.Configuration.IsAdministrator) {
|
2014-05-31 21:11:04 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
$('#fldIsAdmin', page).hide();
|
2014-01-13 13:31:09 -07:00
|
|
|
|
$('#featureAccessFields', page).hide();
|
2013-07-08 12:31:45 -07:00
|
|
|
|
$('#accessControlDiv', page).hide();
|
2014-05-31 21:11:04 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
} else {
|
2014-05-31 21:11:04 -07:00
|
|
|
|
|
2013-07-08 09:13:21 -07:00
|
|
|
|
$('#accessControlDiv', page).show();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
$('#fldIsAdmin', page).show();
|
2014-01-13 13:31:09 -07:00
|
|
|
|
$('#featureAccessFields', page).show();
|
2014-05-31 21:11:04 -07:00
|
|
|
|
$('.lnkEditUserPreferencesContainer', page).show();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-17 22:16:00 -07:00
|
|
|
|
if (!loggedInUser.Configuration.IsAdministrator || !user.Id) {
|
2014-05-31 21:11:04 -07:00
|
|
|
|
|
|
|
|
|
$('.lnkEditUserPreferencesContainer', page).hide();
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
$('.lnkEditUserPreferencesContainer', page).show();
|
|
|
|
|
$('.lnkEditUserPreferences', page).attr('href', 'mypreferencesdisplay.html?userId=' + user.Id);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
Dashboard.setPageTitle(user.Name || Globalize.translate('AddUser'));
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
$('#txtUserName', page).val(user.Name);
|
|
|
|
|
|
|
|
|
|
$('#chkIsAdmin', page).checked(user.Configuration.IsAdministrator || false).checkboxradio("refresh");
|
2013-05-23 08:07:25 -07:00
|
|
|
|
$('#chkBlockNotRated', page).checked(user.Configuration.BlockNotRated || false).checkboxradio("refresh");
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-07-08 09:13:21 -07:00
|
|
|
|
$('#chkDisabled', page).checked(user.Configuration.IsDisabled || false).checkboxradio("refresh");
|
|
|
|
|
$('#chkIsHidden', page).checked(user.Configuration.IsHidden || false).checkboxradio("refresh");
|
2013-10-30 08:55:55 -07:00
|
|
|
|
$('#chkEnableRemoteControlOtherUsers', page).checked(user.Configuration.EnableRemoteControlOfOtherUsers || false).checkboxradio("refresh");
|
2014-01-22 19:19:04 -07:00
|
|
|
|
$('#chkEnableMediaPlayback', page).checked(user.Configuration.EnableMediaPlayback || false).checkboxradio("refresh");
|
2013-07-08 09:13:21 -07:00
|
|
|
|
|
2014-01-13 13:31:09 -07:00
|
|
|
|
$('#chkManageLiveTv', page).checked(user.Configuration.EnableLiveTvManagement || false).checkboxradio("refresh");
|
2014-01-23 14:09:00 -07:00
|
|
|
|
$('#chkEnableLiveTvAccess', page).checked(user.Configuration.EnableLiveTvAccess || false).checkboxradio("refresh");
|
2014-03-25 14:13:55 -07:00
|
|
|
|
$('#chkEnableContentDeletion', page).checked(user.Configuration.EnableContentDeletion || false).checkboxradio("refresh");
|
2014-01-13 13:31:09 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
2013-04-18 09:59:54 -07:00
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
function onSaveComplete(page) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
var userId = getParameterByName("userId");
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
if (userId) {
|
2014-05-30 12:23:56 -07:00
|
|
|
|
Dashboard.alert(Globalize.translate('SettingsSaved'));
|
2013-04-18 09:59:54 -07:00
|
|
|
|
} else {
|
|
|
|
|
Dashboard.navigate("userprofiles.html");
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
2013-04-18 09:59:54 -07:00
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
function saveUser(user, page) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
user.Name = $('#txtUserName', page).val();
|
|
|
|
|
|
|
|
|
|
user.Configuration.IsAdministrator = $('#chkIsAdmin', page).checked();
|
|
|
|
|
|
2013-05-23 08:07:25 -07:00
|
|
|
|
user.Configuration.BlockNotRated = $('#chkBlockNotRated', page).checked();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-07-08 09:13:21 -07:00
|
|
|
|
user.Configuration.IsHidden = $('#chkIsHidden', page).checked();
|
|
|
|
|
user.Configuration.IsDisabled = $('#chkDisabled', page).checked();
|
2013-10-30 08:55:55 -07:00
|
|
|
|
user.Configuration.EnableRemoteControlOfOtherUsers = $('#chkEnableRemoteControlOtherUsers', page).checked();
|
2014-01-13 13:31:09 -07:00
|
|
|
|
user.Configuration.EnableLiveTvManagement = $('#chkManageLiveTv', page).checked();
|
2014-01-22 19:19:04 -07:00
|
|
|
|
user.Configuration.EnableMediaPlayback = $('#chkEnableMediaPlayback', page).checked();
|
2014-01-23 14:09:00 -07:00
|
|
|
|
user.Configuration.EnableLiveTvAccess = $('#chkEnableLiveTvAccess', page).checked();
|
2014-03-25 14:13:55 -07:00
|
|
|
|
user.Configuration.EnableContentDeletion = $('#chkEnableContentDeletion', page).checked();
|
2013-07-08 09:13:21 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
var userId = getParameterByName("userId");
|
|
|
|
|
|
|
|
|
|
if (userId) {
|
2013-04-18 09:59:54 -07:00
|
|
|
|
ApiClient.updateUser(user).done(function () {
|
|
|
|
|
onSaveComplete(page);
|
|
|
|
|
});
|
2013-02-20 18:33:05 -07:00
|
|
|
|
} else {
|
2013-04-18 09:59:54 -07:00
|
|
|
|
ApiClient.createUser(user).done(function () {
|
|
|
|
|
onSaveComplete(page);
|
|
|
|
|
});
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
2013-04-18 09:59:54 -07:00
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
function editUserPage() {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
var self = this;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
self.onSubmit = function () {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
var page = $(this).parents('.page');
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var userId = getParameterByName("userId");
|
|
|
|
|
|
|
|
|
|
if (!userId) {
|
|
|
|
|
saveUser({
|
|
|
|
|
Configuration: {}
|
|
|
|
|
}, page);
|
|
|
|
|
} else {
|
|
|
|
|
ApiClient.getUser(userId).done(function (result) {
|
|
|
|
|
saveUser(result, page);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Disable default form submission
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.EditUserPage = new editUserPage();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 12:09:07 -07:00
|
|
|
|
$(document).on('pagebeforeshow', "#editUserPage", function () {
|
2013-04-18 09:59:54 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
2013-04-22 09:04:54 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
var userId = getParameterByName("userId");
|
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
if (userId) {
|
|
|
|
|
$('#userProfileNavigation', page).show();
|
|
|
|
|
} else {
|
|
|
|
|
$('#userProfileNavigation', page).hide();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 12:09:07 -07:00
|
|
|
|
Dashboard.getCurrentUser().done(function (loggedInUser) {
|
|
|
|
|
|
|
|
|
|
if (loggedInUser.Configuration.IsAdministrator) {
|
2013-12-26 08:40:38 -07:00
|
|
|
|
$('#lnkParentalControl', page).show();
|
2013-04-18 12:09:07 -07:00
|
|
|
|
} else {
|
2013-12-26 08:40:38 -07:00
|
|
|
|
$('#lnkParentalControl', page).hide();
|
2013-04-18 12:09:07 -07:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).on('pageshow', "#editUserPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var userId = getParameterByName("userId");
|
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
var promise1;
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
if (!userId) {
|
2013-04-18 09:59:54 -07:00
|
|
|
|
|
|
|
|
|
var deferred = $.Deferred();
|
|
|
|
|
|
|
|
|
|
deferred.resolveWith(null, [{
|
2014-05-16 10:11:07 -07:00
|
|
|
|
Configuration: {
|
|
|
|
|
IsAdministrator: true,
|
|
|
|
|
EnableLiveTvManagement: true,
|
|
|
|
|
EnableLiveTvAccess: true,
|
|
|
|
|
EnableRemoteControlOfOtherUsers: true,
|
|
|
|
|
EnableMediaPlayback: true
|
|
|
|
|
}
|
2013-04-18 09:59:54 -07:00
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
promise1 = deferred.promise();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
} else {
|
2013-04-18 09:59:54 -07:00
|
|
|
|
|
|
|
|
|
promise1 = ApiClient.getUser(userId);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
var promise2 = Dashboard.getCurrentUser();
|
|
|
|
|
|
|
|
|
|
$.when(promise1, promise2).done(function (response1, response2) {
|
|
|
|
|
|
2013-12-26 08:40:38 -07:00
|
|
|
|
loadUser(page, response1[0] || response1, response2[0]);
|
2013-04-18 09:59:54 -07:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2013-12-26 08:40:38 -07:00
|
|
|
|
$("form input:first", page).focus();
|
2013-04-18 09:59:54 -07:00
|
|
|
|
});
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
})(jQuery, window, document);
|