4
4
5
5
import React , { PureComponent } from 'react' ;
6
6
import PropTypes from 'prop-types' ;
7
- import { set , cloneDeep } from 'lodash' ;
7
+ import { set , cloneDeep , get } from 'lodash' ;
8
8
9
9
import { flux } from '../Firefly.js' ;
10
10
import DialogRootContainer from './DialogRootContainer.jsx' ;
@@ -13,16 +13,17 @@ import {dispatchShowDialog, dispatchHideDialog} from '../core/ComponentCntlr.js'
13
13
import { FormPanel } from './FormPanel.jsx' ;
14
14
import { FieldGroup } from './FieldGroup.jsx' ;
15
15
import Validate from '../util/Validate.js' ;
16
+ import { InputField } from './InputField.jsx' ;
16
17
import { ListBoxInputField } from './ListBoxInputField.jsx' ;
17
18
import { CheckboxGroupInputField } from './CheckboxGroupInputField.jsx' ;
18
- import FieldGroupUtils from '../fieldGroup/FieldGroupUtils.js' ;
19
19
import { ValidationField } from './ValidationField.jsx' ;
20
20
import { showInfoPopup } from './PopupUtil.jsx' ;
21
+ import { SimpleComponent } from './SimpleComponent.jsx' ;
21
22
22
23
import { makeTblRequest , getTblInfoById , getActiveTableId } from '../tables/TableUtil.js' ;
23
- import { dispatchPackage , doOnPackage } from '../core/background/BackgroundCntlr.js' ;
24
+ import { dispatchPackage , dispatchBgSetEmailInfo } from '../core/background/BackgroundCntlr.js' ;
25
+ import { getBgEmailInfo } from '../core/background/BackgroundUtil.js' ;
24
26
import { SelectInfo } from '../tables/SelectInfo.js' ;
25
- import { dispatchAddSaga } from '../core/MasterSaga.js' ;
26
27
import { DataTagMeta } from '../tables/TableUtil.js' ;
27
28
28
29
const DOWNLOAD_DIALOG_ID = 'Download Options' ;
@@ -124,59 +125,49 @@ DownloadButton.propTypes = {
124
125
} ;
125
126
126
127
127
- export class DownloadOptionPanel extends PureComponent {
128
+ export class DownloadOptionPanel extends SimpleComponent {
128
129
129
- constructor ( props ) {
130
- super ( props ) ;
131
- const sendEmail = FieldGroupUtils . getFldValue ( FieldGroupUtils . getGroupFields ( props . groupKey ) , 'sendEmail' ) ;
132
- this . state = { sendEmail, mask : false } ;
133
- this . onSubmit = this . onSubmit . bind ( this ) ;
134
- }
135
-
136
- componentDidMount ( ) {
137
- this . removeListener = flux . addListener ( ( ) => this . storeUpdate ( ) ) ;
138
- }
139
-
140
- componentWillUnmount ( ) {
141
- this . removeListener && this . removeListener ( ) ;
142
- this . isUnmounted = true ;
130
+ getNextState ( ) {
131
+ const { email, enableEmail} = getBgEmailInfo ( ) ;
132
+ return { mask :false , email, enableEmail} ;
143
133
}
144
134
145
- storeUpdate ( ) {
146
- const { groupKey} = this . props ;
147
- if ( ! this . isUnmounted ) {
148
- const sendEmail = FieldGroupUtils . getFldValue ( FieldGroupUtils . getGroupFields ( groupKey ) , 'sendEmail' ) ;
149
- this . setState ( { sendEmail} ) ;
135
+ onEmailChanged ( v ) {
136
+ if ( get ( v , 'valid' ) ) {
137
+ const { email} = this . state ;
138
+ if ( email !== v . value ) dispatchBgSetEmailInfo ( { email : v . value } ) ;
150
139
}
151
140
}
152
141
153
- onSubmit ( options ) {
154
- const { tbl_id, dlParams, dataTag, cutoutSize} = this . props ;
155
- var { request, selectInfo} = getTblInfoById ( tbl_id ) ;
156
- const { FileGroupProcessor} = dlParams ;
157
- const Title = dlParams . Title || options . Title ;
158
- const dreq = makeTblRequest ( FileGroupProcessor , Title , Object . assign ( dlParams , { cutoutSize} , options ) ) ;
159
- this . setState ( { mask : true } ) ;
160
- request = set ( cloneDeep ( request ) , DataTagMeta , dataTag ) ;
161
- dispatchAddSaga ( doOnPackage , { title : Title , callback :( ) => {
162
- this . setState ( { mask : false } ) ;
163
- showDownloadDialog ( this , false ) ;
164
- } } ) ;
165
- dispatchPackage ( dreq , request , SelectInfo . newInstance ( selectInfo ) . toString ( ) ) ;
166
- }
167
-
168
142
render ( ) {
169
- const { groupKey, cutoutSize, help_id, children, style, title} = this . props ;
170
- const { mask, sendEmail } = this . state ;
143
+ const { groupKey, cutoutSize, help_id, children, style, title, tbl_id , dlParams , dataTag } = this . props ;
144
+ const { mask, email , enableEmail } = this . state ;
171
145
const labelWidth = 110 ;
172
146
const ttl = title || DOWNLOAD_DIALOG_ID ;
147
+
148
+ const onSubmit = ( options ) => {
149
+ var { request, selectInfo} = getTblInfoById ( tbl_id ) ;
150
+ const { FileGroupProcessor} = dlParams ;
151
+ const Title = dlParams . Title || options . Title ;
152
+ const dreq = makeTblRequest ( FileGroupProcessor , Title , Object . assign ( dlParams , { cutoutSize} , options ) ) ;
153
+ request = set ( cloneDeep ( request ) , DataTagMeta , dataTag ) ;
154
+ dispatchPackage ( dreq , request , SelectInfo . newInstance ( selectInfo ) . toString ( ) ) ;
155
+ showDownloadDialog ( this , false ) ;
156
+ } ;
157
+
158
+ const toggleEnableEmail = ( e ) => {
159
+ const enableEmail = e . target . checked ;
160
+ const email = enableEmail ? email : '' ;
161
+ dispatchBgSetEmailInfo ( { email, enableEmail} ) ;
162
+ } ;
163
+
173
164
return (
174
165
< div style = { Object . assign ( { margin : '4px' , position : 'relative' , minWidth : 350 } , style ) } >
175
166
{ mask && < div style = { { width : '100%' , height : '100%' } } className = 'loading-mask' /> }
176
167
< FormPanel
177
168
submitText = 'Prepare Download'
178
169
groupKey = { groupKey }
179
- onSubmit = { this . onSubmit }
170
+ onSubmit = { onSubmit }
180
171
onCancel = { ( ) => dispatchHideDialog ( ttl ) }
181
172
help_id = { help_id } >
182
173
< FieldGroup groupKey = { 'DownloadDialog' } keepState = { true } >
@@ -211,29 +202,20 @@ export class DownloadOptionPanel extends PureComponent {
211
202
] }
212
203
labelWidth = { labelWidth }
213
204
/>
214
- < CheckboxGroupInputField
215
- wrapperStyle = { { marginTop : 20 } }
216
- fieldKey = 'sendEmail'
217
- initialState = { { label : ' ' } }
218
- options = { [
219
- { label : 'Also send me email with URLs to download' , value : 'true' }
220
- ] }
221
- labelWidth = { 0 }
205
+
206
+ < div style = { { width : 235 , marginTop : 10 } } > < input type = 'checkbox' checked = { enableEmail } onChange = { toggleEnableEmail } /> Enable email notification</ div >
207
+ { enableEmail &&
208
+ < InputField
209
+ validator = { Validate . validateEmail . bind ( null , 'an email field' ) }
210
+ tooltip = 'Enter an email to be notified when a process completes.'
211
+ label = 'Email:'
212
+ labelStyle = { { display : 'inline-block' , marginLeft : 18 , width : 32 , fontWeight : 'bold' } }
213
+ value = { email }
214
+ placeholder = 'Enter an email to get notification'
215
+ size = { 27 }
216
+ onChange = { this . onEmailChanged . bind ( this ) }
217
+ actOn = { [ 'blur' , 'enter' ] }
222
218
/>
223
- { sendEmail &&
224
- < div >
225
- < ValidationField
226
- wrapperStyle = { { marginTop : 5 , marginLeft : 80 } }
227
- initialState = { {
228
- value : '' ,
229
- validator : Validate . validateEmail . bind ( null , 'Email' ) ,
230
- label : 'Email:' ,
231
- tooltip : 'Enter or modify your email address' ,
232
- } }
233
- fieldKey = 'Email'
234
- size = { 30 }
235
- labelWidth = { 30 } />
236
- </ div >
237
219
}
238
220
</ FieldGroup >
239
221
</ FormPanel >
@@ -275,7 +257,7 @@ DownloadOptionPanel.defaultProps= {
275
257
* @param {boolean } [show=true] show or hide this dialog
276
258
*/
277
259
function showDownloadDialog ( panel , show = true ) {
278
- let ttl = panel . props . title || DOWNLOAD_DIALOG_ID ;
260
+ const ttl = panel . props . title || DOWNLOAD_DIALOG_ID ;
279
261
if ( show ) {
280
262
const content = (
281
263
< PopupPanel title = { ttl } >
0 commit comments