2013-04-18 09:59:54 -07:00
|
|
|
|
(function ($, window, document) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
function populateLanguages(select, allCultures) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
var html = "";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
html += "<option value=''>None</option>";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
for (var i = 0, length = allCultures.length; i < length; i++) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
var culture = allCultures[i];
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
html += "<option value='" + culture.ThreeLetterISOLanguageName + "'>" + culture.DisplayName + "</option>";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
select.html(html).selectmenu("refresh");
|
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
function populateRatings(allParentalRatings, page) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
var html = "";
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
html += "<option value=''>None</option>";
|
2013-03-28 20:50:46 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
for (var i = 0, length = allParentalRatings.length; i < length; i++) {
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
var rating = allParentalRatings[i];
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
html += "<option value='" + rating.Value + "'>" + rating.Name + "</option>";
|
|
|
|
|
}
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
$('#selectMaxParentalRating', page).html(html).selectmenu("refresh");
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-22 08:38:38 -07:00
|
|
|
|
function loadUser(page, user, loggedInUser, allCulturesPromise) {
|
2013-04-18 09:59:54 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
if (!loggedInUser.Configuration.IsAdministrator || user.Id == loggedInUser.Id) {
|
|
|
|
|
|
|
|
|
|
$('#fldIsAdmin', page).hide();
|
|
|
|
|
$('#fldMaxParentalRating', page).hide();
|
|
|
|
|
} else {
|
|
|
|
|
$('#fldIsAdmin', page).show();
|
|
|
|
|
$('#fldMaxParentalRating', page).show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dashboard.setPageTitle(user.Name || "Add User");
|
|
|
|
|
|
|
|
|
|
$('#txtUserName', page).val(user.Name);
|
|
|
|
|
|
2013-04-22 08:38:38 -07:00
|
|
|
|
$('#selectMaxParentalRating', page).val(user.Configuration.MaxParentalRating).selectmenu("refresh");
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
allCulturesPromise.done(function (allCultures) {
|
|
|
|
|
|
|
|
|
|
populateLanguages($('#selectAudioLanguage', page), allCultures);
|
|
|
|
|
populateLanguages($('#selectSubtitleLanguage', page), allCultures);
|
|
|
|
|
|
|
|
|
|
$('#selectAudioLanguage', page).val(user.Configuration.AudioLanguagePreference || "").selectmenu("refresh");
|
|
|
|
|
$('#selectSubtitleLanguage', page).val(user.Configuration.SubtitleLanguagePreference || "").selectmenu("refresh");
|
|
|
|
|
});
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
$('#chkForcedSubtitlesOnly', page).checked(user.Configuration.UseForcedSubtitlesOnly || false).checkboxradio("refresh");
|
|
|
|
|
$('#chkIsAdmin', page).checked(user.Configuration.IsAdministrator || false).checkboxradio("refresh");
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
Dashboard.validateCurrentUser(page);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
if (userId) {
|
|
|
|
|
Dashboard.alert("Settings saved.");
|
|
|
|
|
} 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.MaxParentalRating = $('#selectMaxParentalRating', page).val() || null;
|
|
|
|
|
|
|
|
|
|
user.Configuration.IsAdministrator = $('#chkIsAdmin', page).checked();
|
|
|
|
|
|
|
|
|
|
user.Configuration.AudioLanguagePreference = $('#selectAudioLanguage', page).val();
|
|
|
|
|
user.Configuration.SubtitleLanguagePreference = $('#selectSubtitleLanguage', page).val();
|
|
|
|
|
user.Configuration.UseForcedSubtitlesOnly = $('#chkForcedSubtitlesOnly', page).checked();
|
|
|
|
|
|
|
|
|
|
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-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) {
|
|
|
|
|
$('.lnkMediaLibrary', page).show().prev().removeClass('ui-last-child');
|
|
|
|
|
} else {
|
|
|
|
|
$('.lnkMediaLibrary', page).hide().prev().addClass('ui-last-child');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).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, [{
|
2013-02-20 18:33:05 -07:00
|
|
|
|
Configuration: {}
|
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();
|
|
|
|
|
|
|
|
|
|
var allCulturesPromise = ApiClient.getCultures();
|
|
|
|
|
|
|
|
|
|
$.when(promise1, promise2).done(function (response1, response2) {
|
|
|
|
|
|
2013-04-22 08:38:38 -07:00
|
|
|
|
loadUser(page, response1[0] || response1, response2[0], allCulturesPromise);
|
2013-04-18 09:59:54 -07:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#editUserProfileForm input:first").focus();
|
|
|
|
|
});
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-18 09:59:54 -07:00
|
|
|
|
})(jQuery, window, document);
|