1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-23 11:56:00 +01:00

added date/time fallbacks for safar/ff (#290)

This commit is contained in:
Addison Beck 2021-03-02 10:33:43 -05:00 committed by GitHub
parent 1324416784
commit 70654926ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,7 +37,11 @@ export class AddEditComponent implements OnInit {
disableSend = false;
send: SendView;
deletionDate: string;
deletionDateFallback: string;
deletionTimeFallback: string;
expirationDate: string;
expirationDateFallback: string;
expirationTimeFallback: string;
hasPassword: boolean;
password: string;
showPassword = false;
@ -89,6 +93,10 @@ export class AddEditComponent implements OnInit {
return null;
}
get isDateTimeLocalSupported(): boolean {
return !(this.platformUtilsService.isFirefox() || this.platformUtilsService.isSafari());
}
async ngOnInit() {
await this.load();
}
@ -105,6 +113,14 @@ export class AddEditComponent implements OnInit {
);
}
get expirationDateTimeFallback() {
return `${this.expirationDateFallback}T${this.expirationTimeFallback}`;
}
get deletionDateTimeFallback() {
return `${this.deletionDateFallback}T${this.deletionTimeFallback}`;
}
async load() {
const policies = await this.policyService.getAll(PolicyType.DisableSend);
const organizations = await this.userService.getAllOrganizations();
@ -138,11 +154,28 @@ export class AddEditComponent implements OnInit {
this.hasPassword = this.send.password != null && this.send.password.trim() !== '';
// Parse dates
this.deletionDate = this.dateToString(this.send.deletionDate);
this.expirationDate = this.dateToString(this.send.expirationDate);
if (!this.isDateTimeLocalSupported) {
const deletionDateParts = this.dateToSplitString(this.send.deletionDate);
this.deletionDateFallback = deletionDateParts[0];
this.deletionTimeFallback = deletionDateParts[1];
const expirationDateParts = this.dateToSplitString(this.send.expirationDate);
this.expirationDateFallback = expirationDateParts[0];
this.expirationTimeFallback = expirationDateParts[1];
} else {
this.deletionDate = this.dateToString(this.send.deletionDate);
this.expirationDate = this.dateToString(this.send.expirationDate);
}
}
async submit(): Promise<boolean> {
if (!this.isDateTimeLocalSupported && this.expirationDateTimeFallback !== null) {
this.expirationDate = this.expirationDateTimeFallback;
}
if (!this.isDateTimeLocalSupported && this.deletionDateTimeFallback !== null) {
this.deletionDate = this.deletionDateTimeFallback;
}
if (this.disableSend) {
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('sendDisabledWarning'));
@ -284,6 +317,14 @@ export class AddEditComponent implements OnInit {
return d == null ? null : this.datePipe.transform(d, 'yyyy-MM-ddTHH:mm');
}
protected dateToSplitString(d: Date) {
if (d != null) {
const date = this.datePipe.transform(d, 'yyyy-MM-dd');
const time = this.datePipe.transform(d, 'HH:mm');
return [date, time];
}
}
protected togglePasswordVisible() {
this.showPassword = !this.showPassword;
document.getElementById('password').focus();