mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-29 15:26:09 +00:00
132 lines
2.9 KiB
JavaScript
132 lines
2.9 KiB
JavaScript
|
|
import ko from 'ko';
|
|
import _ from '_';
|
|
|
|
import {
|
|
trim, createCommand,
|
|
triggerAutocompleteInputChange
|
|
} from 'Common/Utils';
|
|
|
|
import {StorageResultType, Notification, Magics} from 'Common/Enums';
|
|
import {getNotification} from 'Common/Translator';
|
|
|
|
import * as Settings from 'Storage/Settings';
|
|
|
|
import Remote from 'Remote/Admin/Ajax';
|
|
|
|
import {getApp} from 'Helper/Apps/Admin';
|
|
|
|
import {view, ViewType, routeOff} from 'Knoin/Knoin';
|
|
import {AbstractViewNext} from 'Knoin/AbstractViewNext';
|
|
|
|
@view({
|
|
name: 'View/Admin/Login',
|
|
type: ViewType.Center,
|
|
templateID: 'AdminLogin'
|
|
})
|
|
class LoginAdminView extends AbstractViewNext
|
|
{
|
|
constructor() {
|
|
super();
|
|
|
|
this.logoPowered = !!Settings.settingsGet('LoginPowered');
|
|
|
|
this.mobile = !!Settings.appSettingsGet('mobile');
|
|
this.mobileDevice = !!Settings.appSettingsGet('mobileDevice');
|
|
|
|
this.login = ko.observable('');
|
|
this.password = ko.observable('');
|
|
|
|
this.loginError = ko.observable(false);
|
|
this.passwordError = ko.observable(false);
|
|
|
|
this.loginErrorAnimation = ko.observable(false).extend({'falseTimeout': 500});
|
|
this.passwordErrorAnimation = ko.observable(false).extend({'falseTimeout': 500});
|
|
|
|
this.loginFocus = ko.observable(false);
|
|
|
|
this.formHidden = ko.observable(false);
|
|
|
|
this.formError = ko.computed(() => this.loginErrorAnimation() || this.passwordErrorAnimation());
|
|
|
|
this.login.subscribe(() => this.loginError(false));
|
|
|
|
this.password.subscribe(() => this.passwordError(false));
|
|
|
|
this.loginError.subscribe((v) => this.loginErrorAnimation(!!v));
|
|
|
|
this.passwordError.subscribe((v) => {
|
|
this.passwordErrorAnimation(!!v);
|
|
});
|
|
|
|
this.submitRequest = ko.observable(false);
|
|
this.submitError = ko.observable('');
|
|
|
|
this.submitCommand = createCommand(() => {
|
|
|
|
triggerAutocompleteInputChange();
|
|
|
|
this.loginError(false);
|
|
this.passwordError(false);
|
|
|
|
this.loginError('' === trim(this.login()));
|
|
this.passwordError('' === trim(this.password()));
|
|
|
|
if (this.loginError() || this.passwordError())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
this.submitRequest(true);
|
|
|
|
Remote.adminLogin((sResult, oData) => {
|
|
|
|
if (StorageResultType.Success === sResult && oData && 'AdminLogin' === oData.Action)
|
|
{
|
|
if (oData.Result)
|
|
{
|
|
getApp().loginAndLogoutReload(true);
|
|
}
|
|
else if (oData.ErrorCode)
|
|
{
|
|
this.submitRequest(false);
|
|
this.submitError(getNotification(oData.ErrorCode));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.submitRequest(false);
|
|
this.submitError(getNotification(Notification.UnknownError));
|
|
}
|
|
|
|
}, this.login(), this.password());
|
|
|
|
return true;
|
|
|
|
}, () => !this.submitRequest());
|
|
}
|
|
|
|
onShow() {
|
|
|
|
routeOff();
|
|
|
|
_.delay(() => {
|
|
this.loginFocus(true);
|
|
}, Magics.Time100ms);
|
|
}
|
|
|
|
onHide() {
|
|
this.loginFocus(false);
|
|
}
|
|
|
|
onBuild() {
|
|
triggerAutocompleteInputChange(true);
|
|
}
|
|
|
|
submitForm() {
|
|
this.submitCommand();
|
|
}
|
|
}
|
|
|
|
export {LoginAdminView, LoginAdminView as default};
|