Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | import { Component, Input, Output, EventEmitter } from '@angular/core'; |
| 17 | import { trigger, state, style, animate, transition } from '@angular/animations'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 18 | import { LogService } from '../../log.service'; |
| 19 | import { LionService } from '../../util/lion.service'; |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * ONOS GUI -- Layer -- Confirm Component |
| 23 | * |
| 24 | * Replaces Flash Service in old GUI. |
| 25 | * Provides a mechanism to present a confirm dialog to the screen |
| 26 | * |
| 27 | * To use add an element to the template like |
| 28 | * <onos-confirm message="Performing something dangerous. Would you like to proceed"></onos-flash> |
| 29 | * |
| 30 | * An event is raised with either OK or Cancel |
| 31 | */ |
| 32 | @Component({ |
| 33 | selector: 'onos-confirm', |
| 34 | templateUrl: './confirm.component.html', |
| 35 | styleUrls: [ |
| 36 | './confirm.component.css', |
| 37 | './confirm.theme.css', |
| 38 | '../dialog.css', |
| 39 | '../dialog.theme.css', |
| 40 | '../../widget/panel.css', |
| 41 | '../../widget/panel-theme.css' |
| 42 | ], |
| 43 | animations: [ |
| 44 | trigger('confirmDlgState', [ |
| 45 | state('true', style({ |
| 46 | transform: 'translateX(-100%)', |
| 47 | opacity: '100' |
| 48 | })), |
| 49 | state('false', style({ |
| 50 | transform: 'translateX(0%)', |
| 51 | opacity: '0' |
| 52 | })), |
| 53 | transition('0 => 1', animate('100ms ease-in')), |
| 54 | transition('1 => 0', animate('100ms ease-out')) |
| 55 | ]) |
| 56 | ] |
| 57 | }) |
| 58 | export class ConfirmComponent { |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame] | 59 | |
| 60 | lionFn; // Function |
| 61 | |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 62 | @Input() message: string; |
| 63 | @Input() warning: string; |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 64 | @Input() title: string; |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 65 | @Output() chosen: EventEmitter<boolean> = new EventEmitter(); |
| 66 | |
| 67 | constructor( |
| 68 | private log: LogService, |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame] | 69 | private lion: LionService, |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 70 | ) { |
| 71 | this.log.debug('ConfirmComponent constructed'); |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame] | 72 | this.doLion(); |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /** |
| 76 | * When OK or Cancel is pressed, send an event to parent with choice |
| 77 | */ |
| 78 | choice(chosen: boolean): void { |
| 79 | this.chosen.emit(chosen); |
| 80 | } |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Read the LION bundle for App to get confirm dialouge header |
| 84 | */ |
| 85 | doLion() { |
| 86 | this.lionFn = this.lion.bundle('core.view.App'); |
| 87 | } |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 88 | } |