jellyfin-web/dashboard-ui/scripts/updatepasswordpage.js

118 lines
3.1 KiB
JavaScript
Raw Normal View History

2013-04-18 12:09:07 -07:00
(function ($, document, window) {
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
function loadUser(page) {
2013-02-20 18:33:05 -07:00
var userid = getParameterByName("userId");
ApiClient.getUser(userid).done(function (user) {
Dashboard.setPageTitle(user.Name);
if (user.HasPassword) {
$('#btnResetPassword', page).show();
$('#fldCurrentPassword', page).show();
$('h3', page).html('Update Password').show();
2013-02-20 18:33:05 -07:00
} else {
$('#btnResetPassword', page).hide();
$('#fldCurrentPassword', page).hide();
$('h3', page).html('Create Password').show();
2013-02-20 18:33:05 -07:00
}
});
$('#txtCurrentPassword', page).val('');
$('#txtNewPassword', page).val('');
$('#txtNewPasswordConfirm', page).val('');
2013-04-18 12:09:07 -07:00
}
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
function save(page) {
2013-02-20 18:33:05 -07:00
var userId = getParameterByName("userId");
var currentPassword = $('#txtCurrentPassword', page).val();
var newPassword = $('#txtNewPassword', page).val();
2013-04-18 12:09:07 -07:00
ApiClient.updateUserPassword(userId, currentPassword, newPassword).done(function () {
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
Dashboard.hideLoadingMsg();
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
Dashboard.alert("Password saved.");
loadUser(page);
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
});
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
}
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
function updatePasswordPage() {
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
var self = this;
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
self.onSubmit = function () {
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
var page = $.mobile.activePage;
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
if ($('#txtNewPassword', page).val() != $('#txtNewPasswordConfirm', page).val()) {
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
Dashboard.showError("Password and password confirmation must match.");
return false;
2013-02-20 18:33:05 -07:00
}
2013-04-18 12:09:07 -07:00
Dashboard.showLoadingMsg();
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
save(page);
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
// Disable default form submission
2013-02-20 18:33:05 -07:00
return false;
2013-04-18 12:09:07 -07:00
};
self.resetPassword = function () {
var msg = "Are you sure you wish to reset the password?";
var page = $.mobile.activePage;
Dashboard.confirm(msg, "Password Reset", function (result) {
if (result) {
var userId = getParameterByName("userId");
Dashboard.showLoadingMsg();
ApiClient.resetUserPassword(userId).done(function () {
Dashboard.hideLoadingMsg();
Dashboard.alert("The password has been reset.");
loadUser(page);
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
});
}
});
2013-02-20 18:33:05 -07:00
2013-04-18 12:09:07 -07:00
};
2013-02-20 18:33:05 -07:00
}
2013-04-18 12:09:07 -07:00
window.UpdatePasswordPage = new updatePasswordPage();
$(document).on('pagebeforeshow', "#updatePasswordPage", function () {
var page = this;
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', "#updatePasswordPage", function () {
var page = this;
loadUser(page);
});
})(jQuery, document, window);