Files
standardnotes-app-web/app/assets/javascripts/controllers/lockScreen.js
Mo Bitar 046f6ca5b9 WIP
2020-02-09 00:34:14 -06:00

90 lines
1.8 KiB
JavaScript

import template from '%/lock-screen.pug';
import { AppStateEvents } from '@/state';
const ELEMENT_ID_PASSCODE_INPUT = 'passcode-input';
class LockScreenCtrl {
/* @ngInject */
constructor(
$scope,
application,
appState
) {
this.$scope = $scope;
this.application = application;
this.appState = appState;
this.formData = {};
this.addVisibilityObserver();
this.addDestroyHandler();
}
$onInit() {
this.puppet.focusInput = () => {
this.passcodeInput.focus();
};
}
get passcodeInput() {
return document.getElementById(
ELEMENT_ID_PASSCODE_INPUT
);
}
addDestroyHandler() {
this.$scope.$on('$destroy', () => {
this.unregisterObserver();
});
}
addVisibilityObserver() {
this.unregisterObserver = this.appState.addObserver((eventName, data) => {
if (eventName === AppStateEvents.WindowDidFocus) {
const input = this.passcodeInput;
if(input) {
input.focus();
}
}
});
}
async submitPasscodeForm($event) {
if(
!this.formData.passcode ||
this.formData.passcode.length === 0
) {
return;
}
this.passcodeInput.blur();
this.onValue()(this.formData.passcode);
}
forgotPasscode() {
this.formData.showRecovery = true;
}
beginDeleteData() {
this.application.alertManager.confirm({
text: "Are you sure you want to clear all local data?",
destructive: true,
onConfirm: async () => {
await this.application.signOut();
await this.application.restart();
}
});
}
}
export class LockScreen {
constructor() {
this.restrict = 'E';
this.template = template;
this.controller = LockScreenCtrl;
this.controllerAs = 'ctrl';
this.bindToController = true;
this.scope = {
onValue: '&',
puppet: '='
};
}
}