From 65d73f2727a18fc900a8ce2ee628e6383ea3bea9 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 13 Apr 2018 00:06:16 -0400 Subject: [PATCH] move folder add/edit to jslib --- jslib | 2 +- src/app/vault/folder-add-edit.component.ts | 78 +++------------------- 2 files changed, 10 insertions(+), 70 deletions(-) diff --git a/jslib b/jslib index 2782ae33..df9074a0 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 2782ae33fcd60f9b84396e54a7d08cfa583f47be +Subproject commit df9074a0e58a1b4a499a0682e964013b546d786f diff --git a/src/app/vault/folder-add-edit.component.ts b/src/app/vault/folder-add-edit.component.ts index 62b11d0e..685a8d09 100644 --- a/src/app/vault/folder-add-edit.component.ts +++ b/src/app/vault/folder-add-edit.component.ts @@ -1,10 +1,4 @@ -import { - Component, - EventEmitter, - Input, - OnInit, - Output, -} from '@angular/core'; +import { Component } from '@angular/core'; import { ToasterService } from 'angular2-toaster'; import { Angulartics2 } from 'angulartics2'; @@ -13,72 +7,18 @@ import { FolderService } from 'jslib/abstractions/folder.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; -import { FolderView } from 'jslib/models/view/folderView'; +import { + FolderAddEditComponent as BaseFolderAddEditComponent, +} from 'jslib/angular/components/folder-add-edit.component'; @Component({ selector: 'app-folder-add-edit', templateUrl: 'folder-add-edit.component.html', }) -export class FolderAddEditComponent implements OnInit { - @Input() folderId: string; - @Output() onSavedFolder = new EventEmitter(); - @Output() onDeletedFolder = new EventEmitter(); - - editMode: boolean = false; - folder: FolderView = new FolderView(); - title: string; - formPromise: Promise; - deletePromise: Promise; - - constructor(private folderService: FolderService, private i18nService: I18nService, - private analytics: Angulartics2, private toasterService: ToasterService, - private platformUtilsService: PlatformUtilsService) { } - - async ngOnInit() { - this.editMode = this.folderId != null; - - if (this.editMode) { - this.editMode = true; - this.title = this.i18nService.t('editFolder'); - const folder = await this.folderService.get(this.folderId); - this.folder = await folder.decrypt(); - } else { - this.title = this.i18nService.t('addFolder'); - } - } - - async submit() { - if (this.folder.name == null || this.folder.name === '') { - this.toasterService.popAsync('error', this.i18nService.t('errorOccurred'), - this.i18nService.t('nameRequired')); - return; - } - - try { - const folder = await this.folderService.encrypt(this.folder); - this.formPromise = this.folderService.saveWithServer(folder); - await this.formPromise; - this.analytics.eventTrack.next({ action: this.editMode ? 'Edited Folder' : 'Added Folder' }); - this.toasterService.popAsync('success', null, - this.i18nService.t(this.editMode ? 'editedFolder' : 'addedFolder')); - this.onSavedFolder.emit(this.folder); - } catch { } - } - - async delete() { - const confirmed = await this.platformUtilsService.showDialog( - this.i18nService.t('deleteFolderConfirmation'), this.i18nService.t('deleteFolder'), - this.i18nService.t('yes'), this.i18nService.t('no'), 'warning'); - if (!confirmed) { - return; - } - - try { - this.deletePromise = this.folderService.deleteWithServer(this.folder.id); - await this.deletePromise; - this.analytics.eventTrack.next({ action: 'Deleted Folder' }); - this.toasterService.popAsync('success', null, this.i18nService.t('deletedFolder')); - this.onDeletedFolder.emit(this.folder); - } catch { } +export class FolderAddEditComponent extends BaseFolderAddEditComponent { + constructor(folderService: FolderService, i18nService: I18nService, + analytics: Angulartics2, toasterService: ToasterService, + platformUtilsService: PlatformUtilsService) { + super(folderService, i18nService, analytics, toasterService, platformUtilsService); } }