From f11e78dacb3bbf45988a5002bed3bf8e7f97d043 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Mon, 17 Apr 2017 15:36:47 +0000
Subject: [PATCH] #3529 fix - Fixed cancel an delete commands on licenses

---
 securis/src/main/webapp/src/app/listing/license.list.component.ts |   37 +++++++++++++++++++++++++++++--------
 1 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/securis/src/main/webapp/src/app/listing/license.list.component.ts b/securis/src/main/webapp/src/app/listing/license.list.component.ts
index 14a6050..c184d64 100644
--- a/securis/src/main/webapp/src/app/listing/license.list.component.ts
+++ b/securis/src/main/webapp/src/app/listing/license.list.component.ts
@@ -1,6 +1,6 @@
 import { ActivatedRoute, Router } from '@angular/router';
 import { MdDialog, MdDialogConfig } from '@angular/material';
-import { TdDataTableService, TdPagingBarComponent, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core';
+import { TdDialogService, TdDataTableService, TdPagingBarComponent, TdDataTableSortingOrder, ITdDataTableSortChangeEvent, ITdDataTableColumn } from '@covalent/core';
 import { IPageChangeEvent } from '@covalent/core';
 import { Component, AfterViewInit, ViewChild } from '@angular/core';
 import { TdMediaService } from '@covalent/core';
@@ -48,13 +48,33 @@
   license_menu_options = LICENSE_ACTIONS;
   
   licenseAction(action: string, license: any) {
-    return this.licenses[action](license.id).subscribe(
-      (actionResponse : any) => {
-        this.toaster.success(this.$L.get('Action "{}" executed successfully', action));
-        this.reload(this.pack.id);
-      },
-      (err : any) => this.toaster.error(this.$L.get('Action "{}" failed', action))
-    );
+    if (action === 'cancel') {      
+      this.dialogs.openPrompt({
+        message: this.$L.get('Please, specify the reason to cancel the current license'),
+        title: this.$L.get('License cancelation'), //OPTIONAL, hides if not provided
+        value: '', 
+        cancelButton: this.$L.get('Close'), 
+        acceptButton: this.$L.get('Cancel license'), //OPTIONAL, defaults to 'ACCEPT'
+      }).afterClosed().subscribe((reason: string) => {
+        if (reason) {
+          this.licenses.cancel(license.id, reason).subscribe(
+            (actionResponse : any) => {
+              this.toaster.success(this.$L.get('License cancelled sucessfully'));
+              this.reload(this.pack.id);
+            },
+            (err : any) => this.toaster.error(err.message, this.$L.get('Action "{}" failed', action) )
+          );
+        }
+      });
+    } else {
+      return this.licenses[action](license.id).subscribe(
+        (actionResponse : any) => {
+          this.toaster.success(this.$L.get('Action "{}" executed successfully', action));
+          this.reload(this.pack.id);
+        },
+        (err : any) => this.toaster.error(err.message, this.$L.get('Action "{}" failed', action))
+      );
+    }
   }
 
   reload(packId: number) : void  {
@@ -73,6 +93,7 @@
 
   constructor( _dataTableService: TdDataTableService,
     private media: TdMediaService,
+    private dialogs: TdDialogService,
     private $L: LocaleService,
     private router: Router,
     private location: Location,

--
Gitblit v1.3.2