From a61cdb088f2050e061040bab2224bc17199f504e Mon Sep 17 00:00:00 2001 From: Drew Ansbacher Date: Thu, 19 Aug 2021 16:59:05 -0600 Subject: [PATCH] more items crossed off --- .../form-object/form-object.component.html | 2 +- .../form-object/form-object.component.ts | 42 ++++++++++++------- .../app/modals/enum-list/enum-list.page.html | 2 +- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/ui/src/app/components/form-object/form-object.component.html b/ui/src/app/components/form-object/form-object.component.html index 314e4cf5f..3f5249e4c 100644 --- a/ui/src/app/components/form-object/form-object.component.html +++ b/ui/src/app/components/form-object/form-object.component.html @@ -82,7 +82,7 @@ isNew: current && current[entry.key] === undefined, isEdited: entry.value.dirty }"> - + Add diff --git a/ui/src/app/components/form-object/form-object.component.ts b/ui/src/app/components/form-object/form-object.component.ts index b5877109d..90a381149 100644 --- a/ui/src/app/components/form-object/form-object.component.ts +++ b/ui/src/app/components/form-object/form-object.component.ts @@ -80,6 +80,10 @@ export class FormObjectComponent { }) } + addListItemWrapper (key: string, spec: ValueSpec) { + this.presentAlertChangeWarning(key, spec, () => this.addListItem(key)) + } + addListItem (key: string, markDirty = true, val?: string): void { const arr = this.formGroup.get(key) as FormArray if (markDirty) arr.markAsDirty() @@ -149,28 +153,34 @@ export class FormObjectComponent { await modal.present() } - async presentAlertChangeWarning (key: string, spec: ValueSpec, okFn: Function = () => { }, cancelFn: Function = () => { }) { - if (!spec['change-warning'] || this.warningAck[key]) return + async presentAlertChangeWarning (key: string, spec: ValueSpec, okFn?: Function, cancelFn?: Function) { + console.log('Here here here', spec['change-warning']) + if (!spec['change-warning'] || this.warningAck[key]) return okFn ? okFn() : null this.warningAck[key] = true + const buttons = [ + { + text: 'Proceed', + handler: () => { + if (okFn) okFn() + }, + }, + ] + + if (okFn || cancelFn) { + buttons.unshift({ + text: 'Cancel', + handler: () => { + if (cancelFn) cancelFn() + }, + }) + } + const alert = await this.alertCtrl.create({ header: 'Warning', subHeader: `Editing ${spec.name} has consequences:`, message: spec['change-warning'], - buttons: [ - { - text: 'Cancel', - handler: () => { - cancelFn() - }, - }, - { - text: 'Proceed', - handler: () => { - okFn() - }, - }, - ], + buttons, }) await alert.present() } diff --git a/ui/src/app/modals/enum-list/enum-list.page.html b/ui/src/app/modals/enum-list/enum-list.page.html index edd340834..78b7e4719 100644 --- a/ui/src/app/modals/enum-list/enum-list.page.html +++ b/ui/src/app/modals/enum-list/enum-list.page.html @@ -14,7 +14,7 @@ - {{ option.key }} + {{ spec.spec['value-names'][option.key] }}