From 470182be4f955a1c11d912743ce9e683ac4902a5 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Mon, 20 Mar 2017 17:06:12 +0000
Subject: [PATCH] #3527 feature - Added skeleton for all other admin catalogs: users, orgs and lic types
---
securis/src/main/webapp/src/app/forms/base.ts | 37 ++++++++++++++++++++++++++++++++-----
1 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/securis/src/main/webapp/src/app/forms/base.ts b/securis/src/main/webapp/src/app/forms/base.ts
index 17cba6d..67bf752 100644
--- a/securis/src/main/webapp/src/app/forms/base.ts
+++ b/securis/src/main/webapp/src/app/forms/base.ts
@@ -1,5 +1,5 @@
import { Http } from '@angular/http';
-import { ActivatedRoute } from '@angular/router';
+import { ActivatedRoute, Router } from '@angular/router';
import { TdDialogService } from '@covalent/core';
import { ToastsManager } from 'ng2-toastr/ng2-toastr';
@@ -7,7 +7,8 @@
import { BasicService } from '../common/utils';
import { SeCurisResourceServices } from '../resources/base';
-import { AfterViewInit, Component, Input } from '@angular/core';
+import { ElementRef, ViewChild, AfterViewInit, Component, Input } from '@angular/core';
+import {FormGroup } from '@angular/forms';
export interface IComboOption {
@@ -16,13 +17,17 @@
}
-export class FormBase extends BasicService {
+export abstract class FormBase extends BasicService {
+ @ViewChild('firstField') firstField: ElementRef;
+ @ViewChild('form') form: FormGroup;
+
protected form_title: string = '';
protected form_subtitle: string = '';
protected data: any = {};
protected isNew : boolean = true;
constructor($L: LocaleService,
+ protected router: Router,
protected route: ActivatedRoute,
protected toaster: ToastsManager,
protected resourceServices: SeCurisResourceServices,
@@ -35,12 +40,31 @@
return this.$L.get(`field.${fieldId}`);
}
+ protected setFirstFocus() :void {
+ if (this.firstField) {
+ this.firstField.nativeElement.focus();
+ }
+ }
+
+ protected reset() :void {
+ if (this.form) {
+ this.form.reset();
+ }
+ }
+
protected loadCombos(): void {}
+ protected abstract init(): void;
+ protected abstract goBack(): void;
save() {
var command = this.isNew ? this.resourceServices.create(this.data) : this.resourceServices.modify(this.data.id, this.data);
command.subscribe(
- data => this.toaster.success(this.$L.get('{} saved sucessfully', this.resourceName.capitalize())),
+ data => {
+ this.toaster.success(this.$L.get('{} saved sucessfully', this.resourceName.capitalize()));
+ if (this.isNew) {
+ this.init();
+ }
+ },
err => this.toaster.error(err.message, this.$L.get('Error saving {}', this.resourceName))
);
}
@@ -56,7 +80,10 @@
if (accept) {
this.resourceServices.remove(eleId)
.subscribe(
- responseData => this.toaster.success(this.$L.get('{} was sucessfully deleted', this.resourceName.capitalize())),
+ responseData => {
+ this.toaster.success(this.$L.get('{} was sucessfully deleted', this.resourceName.capitalize()));
+ this.goBack();
+ },
err => this.toaster.success(err.message, this.$L.get('Error deleting the {}', this.resourceName))
);
}
--
Gitblit v1.3.2