2021-02-01 16:44:30 +01:00
|
|
|
import { DatePipe } from '@angular/common';
|
|
|
|
|
|
|
|
import {
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
OnInit,
|
|
|
|
Output,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
2021-02-04 18:22:31 +01:00
|
|
|
import { OrganizationUserStatusType } from '../../../enums/organizationUserStatusType';
|
|
|
|
import { PolicyType } from '../../../enums/policyType';
|
2021-02-01 16:44:30 +01:00
|
|
|
import { SendType } from '../../../enums/sendType';
|
|
|
|
|
|
|
|
import { EnvironmentService } from '../../../abstractions/environment.service';
|
|
|
|
import { I18nService } from '../../../abstractions/i18n.service';
|
|
|
|
import { MessagingService } from '../../../abstractions/messaging.service';
|
|
|
|
import { PlatformUtilsService } from '../../../abstractions/platformUtils.service';
|
2021-02-04 18:22:31 +01:00
|
|
|
import { PolicyService } from '../../../abstractions/policy.service';
|
2021-02-01 16:44:30 +01:00
|
|
|
import { SendService } from '../../../abstractions/send.service';
|
|
|
|
import { UserService } from '../../../abstractions/user.service';
|
|
|
|
|
|
|
|
import { SendFileView } from '../../../models/view/sendFileView';
|
|
|
|
import { SendTextView } from '../../../models/view/sendTextView';
|
|
|
|
import { SendView } from '../../../models/view/sendView';
|
|
|
|
|
|
|
|
import { Send } from '../../../models/domain/send';
|
|
|
|
|
2021-03-08 19:09:29 +01:00
|
|
|
// TimeOption is used for the dropdown implementation of custom times
|
|
|
|
// Standard = displayed time; Military = stored time
|
|
|
|
interface TimeOption {
|
|
|
|
standard: string;
|
|
|
|
military: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum DateField {
|
|
|
|
DeletionDate = 'deletion',
|
|
|
|
ExpriationDate = 'expiration',
|
|
|
|
}
|
|
|
|
|
2021-02-01 16:44:30 +01:00
|
|
|
export class AddEditComponent implements OnInit {
|
|
|
|
@Input() sendId: string;
|
|
|
|
@Input() type: SendType;
|
|
|
|
|
|
|
|
@Output() onSavedSend = new EventEmitter<SendView>();
|
|
|
|
@Output() onDeletedSend = new EventEmitter<SendView>();
|
|
|
|
@Output() onCancelled = new EventEmitter<SendView>();
|
|
|
|
|
2021-02-08 21:55:32 +01:00
|
|
|
copyLink = false;
|
2021-02-04 18:22:31 +01:00
|
|
|
disableSend = false;
|
2021-02-01 16:44:30 +01:00
|
|
|
send: SendView;
|
|
|
|
deletionDate: string;
|
2021-03-02 16:33:43 +01:00
|
|
|
deletionDateFallback: string;
|
|
|
|
deletionTimeFallback: string;
|
2021-03-02 23:00:07 +01:00
|
|
|
expirationDate: string = null;
|
2021-03-02 16:33:43 +01:00
|
|
|
expirationDateFallback: string;
|
|
|
|
expirationTimeFallback: string;
|
2021-02-01 16:44:30 +01:00
|
|
|
hasPassword: boolean;
|
|
|
|
password: string;
|
2021-02-05 19:36:09 +01:00
|
|
|
showPassword = false;
|
2021-02-01 16:44:30 +01:00
|
|
|
formPromise: Promise<any>;
|
|
|
|
deletePromise: Promise<any>;
|
|
|
|
sendType = SendType;
|
|
|
|
typeOptions: any[];
|
|
|
|
deletionDateOptions: any[];
|
|
|
|
expirationDateOptions: any[];
|
|
|
|
deletionDateSelect = 168;
|
|
|
|
expirationDateSelect: number = null;
|
|
|
|
canAccessPremium = true;
|
|
|
|
premiumRequiredAlertShown = false;
|
2021-02-18 22:04:12 +01:00
|
|
|
showOptions = false;
|
2021-02-01 16:44:30 +01:00
|
|
|
|
2021-03-08 19:09:29 +01:00
|
|
|
safariDeletionTime: string;
|
|
|
|
safariExpirationTime: string;
|
2021-03-08 19:58:53 +01:00
|
|
|
safariDeletionTimeOptions: TimeOption[];
|
|
|
|
safariExpirationTimeOptions: TimeOption[];
|
2021-03-08 19:09:29 +01:00
|
|
|
|
2021-03-11 16:08:28 +01:00
|
|
|
private sendLinkBaseUrl: string;
|
2021-02-08 21:55:32 +01:00
|
|
|
|
2021-02-01 16:44:30 +01:00
|
|
|
constructor(protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
|
|
|
|
protected environmentService: EnvironmentService, protected datePipe: DatePipe,
|
|
|
|
protected sendService: SendService, protected userService: UserService,
|
2021-02-04 18:22:31 +01:00
|
|
|
protected messagingService: MessagingService, protected policyService: PolicyService) {
|
2021-02-01 16:44:30 +01:00
|
|
|
this.typeOptions = [
|
|
|
|
{ name: i18nService.t('sendTypeFile'), value: SendType.File },
|
|
|
|
{ name: i18nService.t('sendTypeText'), value: SendType.Text },
|
|
|
|
];
|
|
|
|
this.deletionDateOptions = this.expirationDateOptions = [
|
|
|
|
{ name: i18nService.t('oneHour'), value: 1 },
|
|
|
|
{ name: i18nService.t('oneDay'), value: 24 },
|
|
|
|
{ name: i18nService.t('days', '2'), value: 48 },
|
|
|
|
{ name: i18nService.t('days', '3'), value: 72 },
|
|
|
|
{ name: i18nService.t('days', '7'), value: 168 },
|
|
|
|
{ name: i18nService.t('days', '30'), value: 720 },
|
|
|
|
{ name: i18nService.t('custom'), value: 0 },
|
|
|
|
];
|
|
|
|
this.expirationDateOptions = [
|
|
|
|
{ name: i18nService.t('never'), value: null },
|
|
|
|
].concat([...this.deletionDateOptions]);
|
2021-02-08 21:55:32 +01:00
|
|
|
|
2021-03-11 16:08:28 +01:00
|
|
|
const webVaultUrl = this.environmentService.getWebVaultUrl();
|
|
|
|
if (webVaultUrl == null) {
|
|
|
|
this.sendLinkBaseUrl = 'https://send.bitwarden.com/#';
|
|
|
|
} else {
|
|
|
|
this.sendLinkBaseUrl = webVaultUrl + '/#/send/';
|
2021-02-08 21:55:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get link(): string {
|
|
|
|
if (this.send.id != null && this.send.accessId != null) {
|
2021-03-11 16:08:28 +01:00
|
|
|
return this.sendLinkBaseUrl + this.send.accessId + '/' + this.send.urlB64Key;
|
2021-02-08 21:55:32 +01:00
|
|
|
}
|
|
|
|
return null;
|
2021-02-01 16:44:30 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 19:09:29 +01:00
|
|
|
get isSafari() {
|
|
|
|
return this.platformUtilsService.isSafari();
|
|
|
|
}
|
|
|
|
|
2021-03-02 16:33:43 +01:00
|
|
|
get isDateTimeLocalSupported(): boolean {
|
|
|
|
return !(this.platformUtilsService.isFirefox() || this.platformUtilsService.isSafari());
|
|
|
|
}
|
|
|
|
|
2021-02-01 16:44:30 +01:00
|
|
|
async ngOnInit() {
|
|
|
|
await this.load();
|
|
|
|
}
|
|
|
|
|
2021-02-12 23:25:47 +01:00
|
|
|
get editMode(): boolean {
|
|
|
|
return this.sendId != null;
|
|
|
|
}
|
2021-02-01 16:44:30 +01:00
|
|
|
|
2021-02-12 23:25:47 +01:00
|
|
|
get title(): string {
|
|
|
|
return this.i18nService.t(
|
|
|
|
this.editMode ?
|
|
|
|
'editSend' :
|
|
|
|
'createSend'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-02 16:33:43 +01:00
|
|
|
get expirationDateTimeFallback() {
|
2021-03-03 21:02:05 +01:00
|
|
|
return this.nullOrWhiteSpaceCount([this.expirationDateFallback, this.expirationTimeFallback]) > 0 ?
|
|
|
|
null :
|
2021-03-08 19:09:29 +01:00
|
|
|
`${this.formatDateFallbacks(this.expirationDateFallback)}T${this.expirationTimeFallback}`;
|
2021-03-02 16:33:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
get deletionDateTimeFallback() {
|
2021-03-08 19:09:29 +01:00
|
|
|
return this.nullOrWhiteSpaceCount([this.deletionDateFallback, this.deletionTimeFallback]) > 0 ?
|
|
|
|
null :
|
|
|
|
`${this.formatDateFallbacks(this.deletionDateFallback)}T${this.deletionTimeFallback}`;
|
2021-03-02 16:33:43 +01:00
|
|
|
}
|
|
|
|
|
2021-02-12 23:25:47 +01:00
|
|
|
async load() {
|
2021-02-04 18:22:31 +01:00
|
|
|
const policies = await this.policyService.getAll(PolicyType.DisableSend);
|
|
|
|
const organizations = await this.userService.getAllOrganizations();
|
|
|
|
this.disableSend = organizations.some(o => {
|
|
|
|
return o.enabled &&
|
|
|
|
o.status === OrganizationUserStatusType.Confirmed &&
|
|
|
|
o.usePolicies &&
|
|
|
|
!o.canManagePolicies &&
|
|
|
|
policies.some(p => p.organizationId === o.id && p.enabled);
|
|
|
|
});
|
|
|
|
|
2021-02-01 16:44:30 +01:00
|
|
|
this.canAccessPremium = await this.userService.canAccessPremium();
|
|
|
|
if (!this.canAccessPremium) {
|
|
|
|
this.type = SendType.Text;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.send == null) {
|
|
|
|
if (this.editMode) {
|
|
|
|
const send = await this.loadSend();
|
|
|
|
this.send = await send.decrypt();
|
|
|
|
} else {
|
|
|
|
this.send = new SendView();
|
|
|
|
this.send.type = this.type == null ? SendType.File : this.type;
|
|
|
|
this.send.file = new SendFileView();
|
|
|
|
this.send.text = new SendTextView();
|
|
|
|
this.send.deletionDate = new Date();
|
|
|
|
this.send.deletionDate.setDate(this.send.deletionDate.getDate() + 7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.hasPassword = this.send.password != null && this.send.password.trim() !== '';
|
|
|
|
|
|
|
|
// Parse dates
|
2021-03-02 16:33:43 +01:00
|
|
|
if (!this.isDateTimeLocalSupported) {
|
|
|
|
const deletionDateParts = this.dateToSplitString(this.send.deletionDate);
|
2021-03-02 23:00:07 +01:00
|
|
|
if (deletionDateParts !== undefined && deletionDateParts.length > 0) {
|
|
|
|
this.deletionDateFallback = deletionDateParts[0];
|
|
|
|
this.deletionTimeFallback = deletionDateParts[1];
|
2021-03-08 19:09:29 +01:00
|
|
|
if (this.isSafari) {
|
|
|
|
this.safariDeletionTime = this.deletionTimeFallback;
|
|
|
|
}
|
2021-03-02 23:00:07 +01:00
|
|
|
}
|
|
|
|
|
2021-03-02 16:33:43 +01:00
|
|
|
const expirationDateParts = this.dateToSplitString(this.send.expirationDate);
|
2021-03-02 23:00:07 +01:00
|
|
|
if (expirationDateParts !== undefined && expirationDateParts.length > 0) {
|
|
|
|
this.expirationDateFallback = expirationDateParts[0];
|
|
|
|
this.expirationTimeFallback = expirationDateParts[1];
|
2021-03-08 19:09:29 +01:00
|
|
|
if (this.isSafari) {
|
|
|
|
this.safariExpirationTime = this.expirationTimeFallback;
|
|
|
|
}
|
2021-03-02 23:00:07 +01:00
|
|
|
}
|
2021-03-02 16:33:43 +01:00
|
|
|
} else {
|
|
|
|
this.deletionDate = this.dateToString(this.send.deletionDate);
|
|
|
|
this.expirationDate = this.dateToString(this.send.expirationDate);
|
|
|
|
}
|
2021-03-08 19:58:53 +01:00
|
|
|
|
|
|
|
if (this.isSafari) {
|
|
|
|
this.safariDeletionTimeOptions = this.safariTimeOptions(DateField.DeletionDate);
|
|
|
|
this.safariExpirationTimeOptions = this.safariTimeOptions(DateField.ExpriationDate);
|
|
|
|
}
|
2021-02-01 16:44:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async submit(): Promise<boolean> {
|
2021-03-02 23:00:07 +01:00
|
|
|
if (!this.isDateTimeLocalSupported) {
|
2021-03-08 19:09:29 +01:00
|
|
|
if (this.isSafari) {
|
|
|
|
this.expirationTimeFallback = this.safariExpirationTime ?? this.expirationTimeFallback;
|
|
|
|
this.deletionTimeFallback = this.safariDeletionTime ?? this.deletionTimeFallback;
|
|
|
|
}
|
2021-03-02 16:33:43 +01:00
|
|
|
this.deletionDate = this.deletionDateTimeFallback;
|
2021-03-08 19:09:29 +01:00
|
|
|
if (this.expirationDateTimeFallback != null && isNaN(Date.parse(this.expirationDateTimeFallback))) {
|
|
|
|
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('expirationDateIsInvalid'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isNaN(Date.parse(this.deletionDateTimeFallback))) {
|
|
|
|
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('deletionDateIsInvalid'));
|
|
|
|
return;
|
|
|
|
}
|
2021-03-03 21:02:05 +01:00
|
|
|
if (this.nullOrWhiteSpaceCount([this.expirationDateFallback, this.expirationTimeFallback]) === 1) {
|
|
|
|
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('expirationDateAndTimeRequired'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.editMode || this.expirationDateSelect === 0) {
|
2021-03-02 23:00:07 +01:00
|
|
|
this.expirationDate = this.expirationDateTimeFallback;
|
|
|
|
}
|
2021-03-02 16:33:43 +01:00
|
|
|
}
|
|
|
|
|
2021-02-04 18:22:31 +01:00
|
|
|
if (this.disableSend) {
|
|
|
|
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('sendDisabledWarning'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-01 16:44:30 +01:00
|
|
|
if (this.send.name == null || this.send.name === '') {
|
|
|
|
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('nameRequired'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
let file: File = null;
|
|
|
|
if (this.send.type === SendType.File && !this.editMode) {
|
|
|
|
const fileEl = document.getElementById('file') as HTMLInputElement;
|
|
|
|
const files = fileEl.files;
|
|
|
|
if (files == null || files.length === 0) {
|
|
|
|
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('selectFile'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = files[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.editMode) {
|
|
|
|
const now = new Date();
|
|
|
|
if (this.deletionDateSelect > 0) {
|
|
|
|
const d = new Date();
|
|
|
|
d.setHours(now.getHours() + this.deletionDateSelect);
|
|
|
|
this.deletionDate = this.dateToString(d);
|
|
|
|
}
|
|
|
|
if (this.expirationDateSelect != null && this.expirationDateSelect > 0) {
|
|
|
|
const d = new Date();
|
|
|
|
d.setHours(now.getHours() + this.expirationDateSelect);
|
|
|
|
this.expirationDate = this.dateToString(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-01 17:31:03 +01:00
|
|
|
if (this.password != null && this.password.trim() === '') {
|
|
|
|
this.password = null;
|
|
|
|
}
|
|
|
|
|
2021-02-01 16:44:30 +01:00
|
|
|
const encSend = await this.encryptSend(file);
|
|
|
|
try {
|
|
|
|
this.formPromise = this.sendService.saveWithServer(encSend);
|
|
|
|
await this.formPromise;
|
2021-02-08 21:55:32 +01:00
|
|
|
if (this.send.id == null) {
|
|
|
|
this.send.id = encSend[0].id;
|
|
|
|
}
|
|
|
|
if (this.send.accessId == null) {
|
|
|
|
this.send.accessId = encSend[0].accessId;
|
|
|
|
}
|
2021-02-01 16:44:30 +01:00
|
|
|
this.platformUtilsService.showToast('success', null,
|
|
|
|
this.i18nService.t(this.editMode ? 'editedSend' : 'createdSend'));
|
|
|
|
this.onSavedSend.emit(this.send);
|
2021-02-08 21:55:32 +01:00
|
|
|
if (this.copyLink) {
|
|
|
|
this.copyLinkToClipboard(this.link);
|
|
|
|
}
|
2021-02-01 16:44:30 +01:00
|
|
|
return true;
|
|
|
|
} catch { }
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearExpiration() {
|
|
|
|
this.expirationDate = null;
|
2021-03-03 21:02:05 +01:00
|
|
|
this.expirationDateFallback = null;
|
|
|
|
this.expirationTimeFallback = null;
|
2021-03-08 19:09:29 +01:00
|
|
|
this.safariExpirationTime = null;
|
2021-02-01 16:44:30 +01:00
|
|
|
}
|
|
|
|
|
2021-02-08 21:55:32 +01:00
|
|
|
copyLinkToClipboard(link: string) {
|
|
|
|
if (link != null) {
|
|
|
|
this.platformUtilsService.copyToClipboard(link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-19 17:23:51 +01:00
|
|
|
async delete(): Promise<boolean> {
|
2021-02-01 16:44:30 +01:00
|
|
|
if (this.deletePromise != null) {
|
2021-02-19 17:23:51 +01:00
|
|
|
return false;
|
2021-02-01 16:44:30 +01:00
|
|
|
}
|
|
|
|
const confirmed = await this.platformUtilsService.showDialog(
|
|
|
|
this.i18nService.t('deleteSendConfirmation'),
|
|
|
|
this.i18nService.t('deleteSend'),
|
|
|
|
this.i18nService.t('yes'), this.i18nService.t('no'), 'warning');
|
|
|
|
if (!confirmed) {
|
2021-02-19 17:23:51 +01:00
|
|
|
return false;
|
2021-02-01 16:44:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
this.deletePromise = this.sendService.deleteWithServer(this.send.id);
|
|
|
|
await this.deletePromise;
|
|
|
|
this.platformUtilsService.showToast('success', null, this.i18nService.t('deletedSend'));
|
|
|
|
await this.load();
|
|
|
|
this.onDeletedSend.emit(this.send);
|
2021-02-19 17:23:51 +01:00
|
|
|
return true;
|
2021-02-01 16:44:30 +01:00
|
|
|
} catch { }
|
2021-02-19 17:23:51 +01:00
|
|
|
|
|
|
|
return false;
|
2021-02-01 16:44:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
typeChanged() {
|
|
|
|
if (!this.canAccessPremium && this.send.type === SendType.File && !this.premiumRequiredAlertShown) {
|
|
|
|
this.premiumRequiredAlertShown = true;
|
|
|
|
this.messagingService.send('premiumRequired');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 22:04:12 +01:00
|
|
|
toggleOptions() {
|
|
|
|
this.showOptions = !this.showOptions;
|
|
|
|
}
|
|
|
|
|
2021-03-09 16:31:05 +01:00
|
|
|
expirationDateFallbackChanged() {
|
|
|
|
this.isSafari ?
|
|
|
|
this.safariExpirationTime = this.safariExpirationTime ?? '00:00' :
|
|
|
|
this.expirationTimeFallback = this.expirationTimeFallback ?? this.datePipe.transform(new Date(), 'HH:mm');
|
|
|
|
}
|
|
|
|
|
2021-02-01 16:44:30 +01:00
|
|
|
protected async loadSend(): Promise<Send> {
|
|
|
|
return this.sendService.get(this.sendId);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async encryptSend(file: File): Promise<[Send, ArrayBuffer]> {
|
|
|
|
const sendData = await this.sendService.encrypt(this.send, file, this.password, null);
|
|
|
|
|
|
|
|
// Parse dates
|
|
|
|
try {
|
|
|
|
sendData[0].deletionDate = this.deletionDate == null ? null : new Date(this.deletionDate);
|
|
|
|
} catch {
|
|
|
|
sendData[0].deletionDate = null;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
sendData[0].expirationDate = this.expirationDate == null ? null : new Date(this.expirationDate);
|
|
|
|
} catch {
|
|
|
|
sendData[0].expirationDate = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sendData;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected dateToString(d: Date) {
|
|
|
|
return d == null ? null : this.datePipe.transform(d, 'yyyy-MM-ddTHH:mm');
|
|
|
|
}
|
2021-02-05 19:36:09 +01:00
|
|
|
|
2021-03-08 19:09:29 +01:00
|
|
|
protected formatDateFallbacks(dateString: string) {
|
|
|
|
try {
|
|
|
|
// The Firefox date picker doesn't supply a time, safari's polyfill does.
|
|
|
|
// Unknown if Safari's native date picker will or not when it releases.
|
|
|
|
if (!this.isSafari) {
|
|
|
|
dateString += ' 00:00';
|
|
|
|
}
|
|
|
|
return this.datePipe.transform(new Date(dateString), 'yyyy-MM-dd');
|
|
|
|
} catch {
|
|
|
|
// this should never happen
|
|
|
|
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
|
|
|
|
this.i18nService.t('dateParsingError'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-02 16:33:43 +01:00
|
|
|
protected dateToSplitString(d: Date) {
|
|
|
|
if (d != null) {
|
2021-03-08 19:09:29 +01:00
|
|
|
const date = !this.isSafari ?
|
|
|
|
this.datePipe.transform(d, 'yyyy-MM-dd') :
|
|
|
|
this.datePipe.transform(d, 'MM/dd/yyyy');
|
2021-03-02 16:33:43 +01:00
|
|
|
const time = this.datePipe.transform(d, 'HH:mm');
|
|
|
|
return [date, time];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-05 19:36:09 +01:00
|
|
|
protected togglePasswordVisible() {
|
|
|
|
this.showPassword = !this.showPassword;
|
|
|
|
document.getElementById('password').focus();
|
|
|
|
}
|
2021-03-03 21:02:05 +01:00
|
|
|
|
|
|
|
protected nullOrWhiteSpaceCount(strarray: string[]): number {
|
|
|
|
return strarray.filter(str => str == null || str.trim() === '').length;
|
|
|
|
}
|
2021-03-08 19:58:53 +01:00
|
|
|
|
|
|
|
protected safariTimeOptions(field: DateField): TimeOption[] {
|
|
|
|
// init individual arrays for major sort groups
|
|
|
|
const noon: TimeOption[] = [];
|
|
|
|
const midnight: TimeOption[] = [];
|
|
|
|
const ams: TimeOption[] = [];
|
|
|
|
const pms: TimeOption[] = [];
|
|
|
|
|
|
|
|
// determine minute skip (5 min, 10 min, 15 min, etc.)
|
|
|
|
const minuteIncrementer = 15;
|
|
|
|
|
|
|
|
// loop through each hour on a 12 hour system
|
|
|
|
for (let h = 1; h <= 12; h++) {
|
|
|
|
// loop through each minute in the hour using the skip to incriment
|
|
|
|
for (let m = 0; m < 60; m += minuteIncrementer) {
|
|
|
|
// init the final strings that will be added to the lists
|
|
|
|
let hour = h.toString();
|
|
|
|
let minutes = m.toString();
|
|
|
|
|
|
|
|
// add prepending 0s to single digit hours/minutes
|
|
|
|
if (h < 10) {
|
|
|
|
hour = '0' + hour;
|
|
|
|
}
|
|
|
|
if (m < 10) {
|
|
|
|
minutes = '0' + minutes;
|
|
|
|
}
|
|
|
|
|
|
|
|
// build time strings and push to relevant sort groups
|
|
|
|
if (h === 12) {
|
|
|
|
const midnightOption: TimeOption = {
|
|
|
|
standard: `${hour}:${minutes} AM`,
|
|
|
|
military: `00:${minutes}`,
|
|
|
|
};
|
|
|
|
midnight.push(midnightOption);
|
|
|
|
|
|
|
|
const noonOption: TimeOption = {
|
|
|
|
standard: `${hour}:${minutes} PM`,
|
|
|
|
military: `${hour}:${minutes}`,
|
|
|
|
};
|
|
|
|
noon.push(noonOption);
|
|
|
|
} else {
|
|
|
|
const amOption: TimeOption = {
|
|
|
|
standard: `${hour}:${minutes} AM`,
|
|
|
|
military: `${hour}:${minutes}`,
|
|
|
|
};
|
|
|
|
ams.push(amOption);
|
|
|
|
|
|
|
|
const pmOption: TimeOption = {
|
|
|
|
standard: `${hour}:${minutes} PM`,
|
|
|
|
military: `${h + 12}:${minutes}`,
|
|
|
|
};
|
|
|
|
pms.push(pmOption);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// bring all the arrays together in the right order
|
|
|
|
const validTimes = [...midnight, ...ams, ...noon, ...pms];
|
|
|
|
|
|
|
|
// determine if an unsupported value already exists on the send & add that to the top of the option list
|
|
|
|
// example: if the Send was created with a different client
|
2021-03-09 16:31:05 +01:00
|
|
|
if (field === DateField.ExpriationDate && this.expirationDateTimeFallback != null && this.editMode) {
|
2021-03-08 19:58:53 +01:00
|
|
|
const previousValue: TimeOption = {
|
|
|
|
standard: this.datePipe.transform(this.expirationDateTimeFallback, 'hh:mm a'),
|
|
|
|
military: this.datePipe.transform(this.expirationDateTimeFallback, 'HH:mm'),
|
|
|
|
};
|
2021-03-11 16:08:28 +01:00
|
|
|
return [previousValue, { standard: null, military: null }, ...validTimes];
|
2021-03-09 16:31:05 +01:00
|
|
|
} else if (field === DateField.DeletionDate && this.deletionDateTimeFallback != null && this.editMode) {
|
2021-03-08 19:58:53 +01:00
|
|
|
const previousValue: TimeOption = {
|
|
|
|
standard: this.datePipe.transform(this.deletionDateTimeFallback, 'hh:mm a'),
|
|
|
|
military: this.datePipe.transform(this.deletionDateTimeFallback, 'HH:mm'),
|
|
|
|
};
|
|
|
|
return [previousValue, ...validTimes];
|
|
|
|
} else {
|
2021-03-11 16:08:28 +01:00
|
|
|
return [{ standard: null, military: null }, ...validTimes];
|
2021-03-08 19:58:53 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-01 16:44:30 +01:00
|
|
|
}
|