From 5b92d9d31fecc6c5526d29885f4b19fc3d0c0d1d Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 25 Jan 2018 23:15:56 -0500 Subject: [PATCH] save cipher --- src/app/vault/add.component.ts | 16 +++++++++++++++- src/locales/en/messages.json | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/app/vault/add.component.ts b/src/app/vault/add.component.ts index e16102f6..cc56b52a 100644 --- a/src/app/vault/add.component.ts +++ b/src/app/vault/add.component.ts @@ -13,6 +13,7 @@ import { SecureNoteType } from 'jslib/enums/secureNoteType'; import { CipherService } from 'jslib/abstractions/cipher.service'; import { FolderService } from 'jslib/abstractions/folder.service'; import { I18nService } from 'jslib/abstractions/i18n.service'; +import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; import { CardView } from 'jslib/models/view/cardView'; import { CipherView } from 'jslib/models/view/cipherView'; @@ -40,7 +41,7 @@ export class AddComponent implements OnChanges { addFieldTypeOptions: any[]; constructor(private cipherService: CipherService, private folderService: FolderService, - private i18nService: I18nService) { + private i18nService: I18nService, private platformUtilsService: PlatformUtilsService) { this.typeOptions = [ { name: i18nService.t('typeLogin'), value: CipherType.Login }, { name: i18nService.t('typeCard'), value: CipherType.Card }, @@ -101,6 +102,19 @@ export class AddComponent implements OnChanges { this.folders = await this.folderService.getAllDecrypted(); } + async save() { + if (this.cipher.name == null || this.cipher.name === '') { + this.platformUtilsService.alertError(this.i18nService.t('errorOccurred'), + this.i18nService.t('nameRequired')); + return; + } + + const cipher = await this.cipherService.encrypt(this.cipher); + await this.cipherService.saveWithServer(cipher); + //$analytics.eventTrack('Added Cipher'); + // TODO: success message + }; + addField() { if (this.cipher.fields == null) { this.cipher.fields = []; diff --git a/src/locales/en/messages.json b/src/locales/en/messages.json index dad80abb..e781d47e 100644 --- a/src/locales/en/messages.json +++ b/src/locales/en/messages.json @@ -283,5 +283,8 @@ }, "remove": { "message": "Remove" + }, + "nameRequired": { + "message": "Name is required." } }