rsanchez
2017-04-17 f11e78dacb3bbf45988a5002bed3bf8e7f97d043
securis/src/main/webapp/src/app/listing/license.list.component.ts
....@@ -1,6 +1,6 @@
11 import { ActivatedRoute, Router } from '@angular/router';
22 import { MdDialog, MdDialogConfig } from '@angular/material';
3
-import { TdDataTableService, TdPagingBarComponent, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core';
3
+import { TdDialogService, TdDataTableService, TdPagingBarComponent, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core';
44 import { IPageChangeEvent } from '@covalent/core';
55 import { Component, AfterViewInit, ViewChild } from '@angular/core';
66 import { TdMediaService } from '@covalent/core';
....@@ -48,13 +48,33 @@
4848 license_menu_options = LICENSE_ACTIONS;
4949
5050 licenseAction(action: string, license: any) {
51
- return this.licenses[action](license.id).subscribe(
52
- (actionResponse : any) => {
53
- this.toaster.success(this.$L.get('Action "{}" executed successfully', action));
54
- this.reload(this.pack.id);
55
- },
56
- (err : any) => this.toaster.error(this.$L.get('Action "{}" failed', action))
57
- );
51
+ if (action === 'cancel') {
52
+ this.dialogs.openPrompt({
53
+ message: this.$L.get('Please, specify the reason to cancel the current license'),
54
+ title: this.$L.get('License cancelation'), //OPTIONAL, hides if not provided
55
+ value: '',
56
+ cancelButton: this.$L.get('Close'),
57
+ acceptButton: this.$L.get('Cancel license'), //OPTIONAL, defaults to 'ACCEPT'
58
+ }).afterClosed().subscribe((reason: string) => {
59
+ if (reason) {
60
+ this.licenses.cancel(license.id, reason).subscribe(
61
+ (actionResponse : any) => {
62
+ this.toaster.success(this.$L.get('License cancelled sucessfully'));
63
+ this.reload(this.pack.id);
64
+ },
65
+ (err : any) => this.toaster.error(err.message, this.$L.get('Action "{}" failed', action) )
66
+ );
67
+ }
68
+ });
69
+ } else {
70
+ return this.licenses[action](license.id).subscribe(
71
+ (actionResponse : any) => {
72
+ this.toaster.success(this.$L.get('Action "{}" executed successfully', action));
73
+ this.reload(this.pack.id);
74
+ },
75
+ (err : any) => this.toaster.error(err.message, this.$L.get('Action "{}" failed', action))
76
+ );
77
+ }
5878 }
5979
6080 reload(packId: number) : void {
....@@ -73,6 +93,7 @@
7393
7494 constructor( _dataTableService: TdDataTableService,
7595 private media: TdMediaService,
96
+ private dialogs: TdDialogService,
7697 private $L: LocaleService,
7798 private router: Router,
7899 private location: Location,