blob: 7533a7ec410217df67f4ff8cd158e24463980028 [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';
Sean Condon5ca00262018-09-06 17:55:25 +010018import { LogService } from '../../log.service';
19import { LionService } from '../../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;
Sean Condon87b78502018-09-17 20:53:24 +010064 @Input() title: string;
Sean Condon2aa86092018-07-16 09:04:05 +010065 @Output() chosen: EventEmitter<boolean> = new EventEmitter();
66
67 constructor(
68 private log: LogService,
prai9d445962018-07-27 13:27:43 +053069 private lion: LionService,
Sean Condon2aa86092018-07-16 09:04:05 +010070 ) {
71 this.log.debug('ConfirmComponent constructed');
prai9d445962018-07-27 13:27:43 +053072 this.doLion();
Sean Condon2aa86092018-07-16 09:04:05 +010073 }
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 }
prai9d445962018-07-27 13:27:43 +053081
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 Condon2aa86092018-07-16 09:04:05 +010088}