3 import React from 'react';
5 import Icon from '../icons/Icon';
6 import iconQuestion from '../../../../../../res/ecomp/asdc/sequencer/sprites/icon/question.svg';
7 import iconExclaim from '../../../../../../res/ecomp/asdc/sequencer/sprites/icon/exclaim.svg';
8 import iconInfo from '../../../../../../res/ecomp/asdc/sequencer/sprites/icon/info.svg';
9 import iconEdit from '../../../../../../res/ecomp/asdc/sequencer/sprites/icon/edit.svg';
10 import iconClose from '../../../../../../res/ecomp/asdc/sequencer/sprites/icon/close.svg';
13 * Multi-purpose dialog. Rendered into the page on initialization, and then
14 * configured, shown and hidden as required.
16 export default class Dialog extends React.Component {
18 // ///////////////////////////////////////////////////////////////////////////////////////////////
23 constructor(props, context) {
25 super(props, context);
29 icon: 'asdcs-icon-info',
30 heading: 'Information',
33 icon: 'asdcs-icon-exclaim',
37 icon: 'asdcs-icon-edit',
43 icon: 'asdcs-icon-question',
58 this.onClickOK = this.onClickOK.bind(this);
59 this.onClickCancel = this.onClickCancel.bind(this);
60 this.onChangeText = this.onChangeText.bind(this);
61 this.showConfirmDialog = this.showConfirmDialog.bind(this);
62 this.showInfoDialog = this.showInfoDialog.bind(this);
63 this.showEditDialog = this.showEditDialog.bind(this);
64 this.showErrorDialog = this.showErrorDialog.bind(this);
65 this.showDialog = this.showDialog.bind(this);
69 // ///////////////////////////////////////////////////////////////////////////////////////////////
73 * @param message info message.
75 showInfoDialog(message) {
76 this.showDialog(this.MODE.INFO, { message });
79 // ///////////////////////////////////////////////////////////////////////////////////////////////
83 * @param message error message.
85 showErrorDialog(message) {
86 this.showDialog(this.MODE.ERROR, { message });
89 // ///////////////////////////////////////////////////////////////////////////////////////////////
93 * @param message dialog message.
94 * @param text current edit text.
95 * @param callback callback function to be invoked on OK.
97 showEditDialog(message, text, callback) {
98 this.showDialog(this.MODE.EDIT, { message, text, callback });
101 // ///////////////////////////////////////////////////////////////////////////////////////////////
104 * Show confirmation dialog.
105 * @param message dialog message.
106 * @param callback callback function to be invoked on OK.
108 showConfirmDialog(message, callback) {
109 this.showDialog(this.MODE.CONFIRM, { message, callback });
112 // ///////////////////////////////////////////////////////////////////////////////////////////////
115 * Handle buttonclick.
118 this.props.application.hideOverlay();
119 this.setState({ visible: false });
122 // So far the only thing we can return is edit text, but send it back
123 // as properties to allow for future return values.
125 this.callback({ text: this.state.text });
129 // ///////////////////////////////////////////////////////////////////////////////////////////////
132 * Handle buttonclick.
135 this.props.application.hideOverlay();
136 this.setState({ visible: false });
139 // ///////////////////////////////////////////////////////////////////////////////////////////////
142 * Handle text changes.
143 * @param event update event.
145 onChangeText(event) {
146 this.setState({ text: event.target.value });
149 // ///////////////////////////////////////////////////////////////////////////////////////////////
152 * Show dialog in specified configuration.
153 * @param mode dialog mode.
154 * @param args dialog parameters, varying slightly by dialog type.
157 showDialog(mode, args) {
158 this.props.application.showOverlay();
159 this.callback = args.callback;
163 message: args.message || '',
164 text: args.text || '',
168 // ///////////////////////////////////////////////////////////////////////////////////////////////
171 * Render dialog into the page, initially hidden.
175 const dialogClass = (this.state.visible) ? '' : 'asdcs-hidden';
176 const cancelClass = (this.callback) ? '' : 'asdcs-hidden';
177 const textClass = (this.state.mode === this.MODE.EDIT) ? '' : 'asdcs-hidden';
180 <div className={`asdcs-dialog ${dialogClass}`}>
181 <div className="asdcs-dialog-header">{this.state.mode.heading}</div>
182 <div className="asdcs-dialog-close" onClick={this.onClickCancel} >
183 <Icon glyph={iconClose} className={this.MODE.CONFIRM.icon} />
185 <div className={`asdcs-dialog-icon ${this.state.mode.icon}`}>
186 <Icon glyph={iconQuestion} className={this.MODE.CONFIRM.icon} />
187 <Icon glyph={iconExclaim} className={this.MODE.ERROR.icon} />
188 <Icon glyph={iconInfo} className={this.MODE.INFO.icon} />
189 <Icon glyph={iconEdit} className={this.MODE.EDIT.icon} />
191 <div className="asdcs-dialog-message">
194 <div className={`asdcs-dialog-text ${textClass}`}>
197 value={this.state.text}
198 onChange={this.onChangeText}
201 <div className="asdcs-dialog-buttonbar">
203 className={`asdcs-dialog-button-cancel ${cancelClass}`}
204 onClick={this.onClickCancel}
209 className="asdcs-dialog-button-ok"
210 onClick={this.onClickOK}
221 application: React.PropTypes.object.isRequired,