blob: 5c5bad2199a73cbb2bd35b7758343713125f0b3f [file] [log] [blame]
Sean Condon2aa86092018-07-16 09:04:05 +01001/*
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 */
16import { Component, Input, Output, EventEmitter } from '@angular/core';
17import { trigger, state, style, animate, transition } from '@angular/animations';
18import { LogService } from '../../../log.service';
prai9d445962018-07-27 13:27:43 +053019import { LionService } from '../../../fw/util/lion.service';
Sean Condon2aa86092018-07-16 09:04:05 +010020
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})
58export class ConfirmComponent {
prai9d445962018-07-27 13:27:43 +053059
60 lionFn; // Function
61
Sean Condon2aa86092018-07-16 09:04:05 +010062 @Input() message: string;
63 @Input() warning: string;
64 @Output() chosen: EventEmitter<boolean> = new EventEmitter();
65
66 constructor(
67 private log: LogService,
prai9d445962018-07-27 13:27:43 +053068 private lion: LionService,
Sean Condon2aa86092018-07-16 09:04:05 +010069 ) {
70 this.log.debug('ConfirmComponent constructed');
prai9d445962018-07-27 13:27:43 +053071 this.doLion();
Sean Condon2aa86092018-07-16 09:04:05 +010072 }
73
74 /**
75 * When OK or Cancel is pressed, send an event to parent with choice
76 */
77 choice(chosen: boolean): void {
78 this.chosen.emit(chosen);
79 }
prai9d445962018-07-27 13:27:43 +053080
81 /**
82 * Read the LION bundle for App to get confirm dialouge header
83 */
84 doLion() {
85 this.lionFn = this.lion.bundle('core.view.App');
86 }
Sean Condon2aa86092018-07-16 09:04:05 +010087}