1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/controllers/wizard/user/index.js

70 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-07-17 19:04:56 +01:00
import loading from 'loading';
import globalize from 'globalize';
import 'dashboardcss';
import 'emby-input';
import 'emby-button';
2018-10-23 01:05:09 +03:00
2020-07-17 19:04:56 +01:00
function getApiClient() {
return ApiClient;
}
2018-10-23 01:05:09 +03:00
2020-07-17 19:04:56 +01:00
function nextWizardPage() {
Dashboard.navigate('wizardlibrary.html');
}
2018-10-23 01:05:09 +03:00
2020-07-17 19:04:56 +01:00
function onUpdateUserComplete(result) {
console.debug('user update complete: ' + result);
loading.hide();
nextWizardPage();
}
2018-10-23 01:05:09 +03:00
2020-07-17 19:04:56 +01:00
function submit(form) {
loading.show();
const apiClient = getApiClient();
apiClient.ajax({
type: 'POST',
2020-08-12 21:17:07 +02:00
data: JSON.stringify({
2020-07-17 19:04:56 +01:00
Name: form.querySelector('#txtUsername').value,
Password: form.querySelector('#txtManualPassword').value
2020-08-12 21:17:07 +02:00
}),
2020-07-17 19:04:56 +01:00
url: apiClient.getUrl('Startup/User')
}).then(onUpdateUserComplete);
}
2019-10-08 01:29:20 +03:00
2020-07-17 19:04:56 +01:00
function onSubmit(e) {
const form = this;
2019-10-08 01:29:20 +03:00
2020-07-17 19:04:56 +01:00
if (form.querySelector('#txtManualPassword').value != form.querySelector('#txtPasswordConfirm').value) {
2020-07-17 19:10:07 +01:00
import('toast').then(({default: toast}) => {
2020-07-17 19:04:56 +01:00
toast(globalize.translate('PasswordMatchError'));
2019-10-08 01:29:20 +03:00
});
2020-07-17 19:04:56 +01:00
} else {
submit(form);
2018-10-23 01:05:09 +03:00
}
2019-10-08 01:29:20 +03:00
2020-07-17 19:04:56 +01:00
e.preventDefault();
return false;
}
function onViewShow() {
loading.show();
const page = this;
const apiClient = getApiClient();
apiClient.getJSON(apiClient.getUrl('Startup/User')).then(function (user) {
page.querySelector('#txtUsername').value = user.Name || '';
page.querySelector('#txtManualPassword').value = user.Password || '';
loading.hide();
});
}
export default function (view, params) {
view.querySelector('.wizardUserForm').addEventListener('submit', onSubmit);
view.addEventListener('viewshow', function () {
document.querySelector('.skinHeader').classList.add('noHomeButtonHeader');
});
view.addEventListener('viewhide', function () {
document.querySelector('.skinHeader').classList.remove('noHomeButtonHeader');
});
view.addEventListener('viewshow', onViewShow);
}