2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
17 import React from 'react';
19 import Icon from '../icons/Icon';
20 import iconQuestion from '../../../../../../res/ecomp/asdc/sequencer/sprites/icons/question.svg';
21 import iconExclaim from '../../../../../../res/ecomp/asdc/sequencer/sprites/icons/exclaim.svg';
22 import iconInfo from '../../../../../../res/ecomp/asdc/sequencer/sprites/icons/info.svg';
23 import iconEdit from '../../../../../../res/ecomp/asdc/sequencer/sprites/icons/edit.svg';
24 import iconClose from '../../../../../../res/ecomp/asdc/sequencer/sprites/icons/close.svg';
27 * Multi-purpose dialog. Rendered into the page on initialization, and then
28 * configured, shown and hidden as required.
30 export default class Dialog extends React.Component {
32 // ///////////////////////////////////////////////////////////////////////////////////////////////
37 constructor(props, context) {
39 super(props, context);
43 icon: 'asdcs-icon-info',
44 heading: 'Information',
47 icon: 'asdcs-icon-exclaim',
51 icon: 'asdcs-icon-edit',
57 icon: 'asdcs-icon-question',
72 this.onClickOK = this.onClickOK.bind(this);
73 this.onClickCancel = this.onClickCancel.bind(this);
74 this.onChangeText = this.onChangeText.bind(this);
75 this.showConfirmDialog = this.showConfirmDialog.bind(this);
76 this.showInfoDialog = this.showInfoDialog.bind(this);
77 this.showEditDialog = this.showEditDialog.bind(this);
78 this.showErrorDialog = this.showErrorDialog.bind(this);
79 this.showDialog = this.showDialog.bind(this);
83 // ///////////////////////////////////////////////////////////////////////////////////////////////
87 * @param message info message.
89 showInfoDialog(message) {
90 this.showDialog(this.MODE.INFO, { message });
93 // ///////////////////////////////////////////////////////////////////////////////////////////////
97 * @param message error message.
99 showErrorDialog(message) {
100 this.showDialog(this.MODE.ERROR, { message });
103 // ///////////////////////////////////////////////////////////////////////////////////////////////
107 * @param message dialog message.
108 * @param text current edit text.
109 * @param callback callback function to be invoked on OK.
111 showEditDialog(message, text, callback) {
112 this.showDialog(this.MODE.EDIT, { message, text, callback });
115 // ///////////////////////////////////////////////////////////////////////////////////////////////
118 * Show confirmation dialog.
119 * @param message dialog message.
120 * @param callback callback function to be invoked on OK.
122 showConfirmDialog(message, callback) {
123 this.showDialog(this.MODE.CONFIRM, { message, callback });
126 // ///////////////////////////////////////////////////////////////////////////////////////////////
129 * Handle buttonclick.
132 this.props.application.hideOverlay();
133 this.setState({ visible: false });
136 // So far the only thing we can return is edit text, but send it back
137 // as properties to allow for future return values.
139 this.callback({ text: this.state.text });
143 // ///////////////////////////////////////////////////////////////////////////////////////////////
146 * Handle buttonclick.
149 this.props.application.hideOverlay();
150 this.setState({ visible: false });
153 // ///////////////////////////////////////////////////////////////////////////////////////////////
156 * Handle text changes.
157 * @param event update event.
159 onChangeText(event) {
160 this.setState({ text: event.target.value });
163 // ///////////////////////////////////////////////////////////////////////////////////////////////
166 * Show dialog in specified configuration.
167 * @param mode dialog mode.
168 * @param args dialog parameters, varying slightly by dialog type.
171 showDialog(mode, args) {
172 this.props.application.showOverlay();
173 this.callback = args.callback;
177 message: args.message || '',
178 text: args.text || '',
182 // ///////////////////////////////////////////////////////////////////////////////////////////////
185 * Render dialog into the page, initially hidden.
189 const dialogClass = (this.state.visible) ? '' : 'asdcs-hidden';
190 const cancelClass = (this.callback) ? '' : 'asdcs-hidden';
191 const textClass = (this.state.mode === this.MODE.EDIT) ? '' : 'asdcs-hidden';
194 <div className={`asdcs-dialog ${dialogClass}`}>
195 <div className="asdcs-dialog-header">{this.state.mode.heading}</div>
196 <div className="asdcs-dialog-close" onClick={this.onClickCancel} >
197 <Icon glyph={iconClose} className={this.MODE.CONFIRM.icon} />
199 <div className={`asdcs-dialog-icon ${this.state.mode.icon}`}>
200 <Icon glyph={iconQuestion} className={this.MODE.CONFIRM.icon} />
201 <Icon glyph={iconExclaim} className={this.MODE.ERROR.icon} />
202 <Icon glyph={iconInfo} className={this.MODE.INFO.icon} />
203 <Icon glyph={iconEdit} className={this.MODE.EDIT.icon} />
205 <div className="asdcs-dialog-message">
208 <div className={`asdcs-dialog-text ${textClass}`}>
211 value={this.state.text}
212 onChange={this.onChangeText}
215 <div className="asdcs-dialog-buttonbar">
217 className={`asdcs-dialog-button-cancel ${cancelClass}`}
218 onClick={this.onClickCancel}
223 className="asdcs-dialog-button-ok"
224 onClick={this.onClickOK}
235 application: React.PropTypes.object.isRequired,