2020-08-14 08:46:34 +02:00
|
|
|
import loading from '../../../components/loading/loading';
|
|
|
|
import globalize from '../../../scripts/globalize';
|
2021-01-26 15:31:58 -05:00
|
|
|
import '../../../assets/css/dashboard.scss';
|
2020-08-14 08:46:34 +02:00
|
|
|
import '../../../elements/emby-input/emby-input';
|
|
|
|
import '../../../elements/emby-button/emby-button';
|
2020-10-12 23:08:55 +01:00
|
|
|
import Dashboard from '../../../scripts/clientUtils';
|
2020-10-18 15:18:15 +01:00
|
|
|
import toast from '../../../components/toast/toast';
|
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-08-31 15:48:24 +02:00
|
|
|
url: apiClient.getUrl('Startup/User'),
|
|
|
|
contentType: 'application/json'
|
2020-07-17 19:04:56 +01:00
|
|
|
}).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-10-18 15:18:15 +01:00
|
|
|
toast(globalize.translate('PasswordMatchError'));
|
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);
|
|
|
|
}
|