-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitchAlltComponent.jsx
244 lines (212 loc) · 10.9 KB
/
SwitchAlltComponent.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import React, { Component } from 'react'
import { Col, Row, Icon, Menu, Dropdown, Checkbox, Switch, Input, Radio, Tooltip, Button, Select } from 'antd';
import DateComponent from './DateComponent';
import RangeComponent from './RangeComponent';
import FileUploadComponent from './FileUploadComponent'
import RateComponent from './RateComponent';
import ShortAnswerComponent from './ShortAnswerComponent';
import LongAnswerComponent from './LongAnswerComponent';
import CheckBoxComponent from './CheckBoxComponent'
import SelectComponent from './SelectComponent'
import RadioButtonComponent from './RadioButtonComponent'
import TimeComponent from './TimeComponent'
const { TextArea } = Input;
const { Option } = Select;
export default class SwitchAlltComponent extends Component {
constructor(props) {
super(props);
this.state = {
type: props.data && props.data.type ? props.data.type : "shortanswer",
position: {},
childData: props.data || {},
containerProperties: {},
isMandatory: props.data && props.data.isMandatory ? true : false,
isDescription: props.data && props.data.isDescription ? true : false,
isNote: props.data && props.data.isNote ? true : false,
changeTypeList: [
{
name: 'Date',
type: "date"
},
{
name: 'Time',
type: "time"
},
{
name: 'Range',
type: "range"
},
{
name: 'FileUpload',
type: "fileupload"
},
{
name: 'Rating',
type: "rating"
},
{
name: "Short Answer",
type: "shortanswer"
},
{
name: "Long Answer",
type: "longanswer"
},
{
name: "Checkbox",
type: "checkbox"
},
{
name: "Select",
type: "select"
}, {
name: "Radio",
type: "radio"
}
],
advanceOptionList: [
{
name: 'Description',
key: 'isDescription',
event: (e) => {
this.changeCheckBox('isDescription', e.target.checked)
}
},
{
name: 'Note',
key: 'isNote',
event: (e) => {
this.changeCheckBox('isNote', e.target.checked)
}
}
]
}
}
onChangeType = (e) => {
this.setState({ type: e, childData: {} }, () => {
this.props.setData({}, this.props.index)
})
}
changeCheckBox(variableName, value) {
this.setState({ childData: { ...this.state.childData, [variableName]: value }, [variableName]: value }, () => {
this.props.setData(this.state.childData, this.props.index)
});
}
setData = (variableName, value) => {
this.setState({ childData: { ...this.state.childData, [variableName]: value } }, () => {
this.props.setData(this.state.childData, this.props.index)
})
}
setMultipleData = (obj) => {
//this.props.setData(variableName,value)
this.setState({ childData: { ...this.state.childData, ...obj } }, () => {
this.props.setData(this.state.childData, this.props.index)
})
}
setAllData = (state) => {
this.setState({ childData: { ...state, type: this.state.type }, }, () => this.props.setData(this.state.childData, this.props.index))
}
remove = () => {
this.props.remove(this.props.index)
}
switchComponent = (type) => {
switch (type) {
case "date": return <DateComponent setAllData={this.setAllData} setData={this.setData} data={this.state.childData}
viewMode={this.props.viewMode} />;
case "time": return <TimeComponent setAllData={this.setAllData} setData={this.setData} data={this.state.childData}
viewMode={this.props.viewMode} />;
case "range": return <RangeComponent setMultipleData={this.setMultipleData} setAllData={this.setAllData} setData={this.setData} data={this.state.childData}
viewMode={this.props.viewMode} />;
case "fileupload": return <FileUploadComponent setAllData={this.setAllData} setMultipleData={this.setMultipleData} setData={this.setData} data={this.state.childData}
viewMode={this.props.viewMode} />;
case "rating": return <RateComponent setMultipleData={this.setMultipleData} setAllData={this.setAllData} setData={this.setData} data={this.state.childData}
viewMode={this.props.viewMode} />;
case "longanswer": return <LongAnswerComponent setAllData={this.setAllData} setData={this.setData} data={this.state.childData} viewMode={this.props.viewMode} />;
case "checkbox": return <CheckBoxComponent setAllData={this.setAllData} setData={this.setData} data={this.state.childData} viewMode={this.props.viewMode} />;
case "select": return <SelectComponent setAllData={this.setAllData} setData={this.setData} data={this.state.childData} viewMode={this.props.viewMode} />;
case "radio": return <RadioButtonComponent setAllData={this.setAllData} setData={this.setData} data={this.state.childData} viewMode={this.props.viewMode} />;
default: return <ShortAnswerComponent setAllData={this.setAllData} setData={this.setData} data={this.state.childData} viewMode={this.props.viewMode} />;
}
}
render() {
let changeTypeList, changeTypeListMenu, menuInside, menu;
if (!this.props.viewMode) {
changeTypeList = this.state.changeTypeList.map((itm, i) => {
return <Option value={itm.type} >{itm.name}</Option>
})
menuInside = []
this.state.advanceOptionList.map((itm, i) => {
menuInside.push(
<Menu.Item key={itm.name}>
<Checkbox key={itm.key} defaultChecked={this.state[itm.key] ? true : false} onChange={itm.event}>{itm.name}</Checkbox>
</Menu.Item>
)
return {}
}) //this.state.checked.push(false);
menu = (<Menu>
{menuInside}
</Menu>)
}
let data = { ...this.state.childData };
return (
<div>
<div className="subParentBox">
<div className="form-question-option">
{!this.props.viewMode ? (
<Radio.Group >
<Tooltip title="Select this to add question description"><Checkbox onChange={(e) => { this.changeCheckBox('isDescription', e.target.checked) }}>Add Description</Checkbox></Tooltip>
<Tooltip title="Select this to show note for some specific question"> <Checkbox onChange={(e) => { this.changeCheckBox('isNote', e.target.checked) }}>Add Note</Checkbox></Tooltip>
</Radio.Group>
) : null}
</div>
<div className="form-question-title">
{!this.props.viewMode ? (
<span className="question-input-block">
<Input className="form-builder-ques-title input-field-design" defaultValue={data.title} onChange={(e) => { this.setData('title', e.target.value) }} placeholder="Title" />
</span>
) :
(<label className="ml-12 lableTitle">{data.title}</label>)}
{!this.props.viewMode ? (
<Select className="select-component-btn" defaultValue={this.state.type} onChange={(e) => this.onChangeType(e)}>
{changeTypeList}
</Select>
) : null}
</div>
<div>
{this.state.isDescription ?
(<div>
{!this.props.viewMode ? (<TextArea className="input-field-design form-add-ques-description" defaultValue={data.description} onChange={(e) => { this.setData('description', e.target.value) }} placeholder="Description" disabled={this.props.viewMode} />) :
(<label className="ml-12 lableDescription">{data.description}</label>)}
</div>) : null}
</div>
<div className="component-switch-div" >{this.switchComponent(this.state.type)}</div>
<div style={{ marginBottom: '10px' }}>
<Row>
<Col span={24}>
{this.state.isNote ? (<Col span={24}>
{!this.props.viewMode ? (<Input className="input-field-design form-add-ques-description" defaultValue={data.note} onChange={(e) => { this.setData('note', e.target.value) }} placeholder="Note" disabled={this.props.viewMode} />) :
(<label className="ml-12 lableDescription">{data.note}</label>)}
</Col>) : null}
</Col>
</Row>
</div>
<Row className="form-builder-question-bottom">
{!this.props.viewMode ? (
<span className="delete-icon">
<Tooltip title="Click to delete question"><Icon type="delete" onClick={this.remove} /></Tooltip>
</span>) : null}
{!this.props.viewMode ? (
<span className="form-ques-controls">
<span style={{ marginLeft: "10px" }}>Primary
<Switch style={{ marginLeft: "10px" }} checked={this.props.primaryfeild == this.props.index} onChange={(i, e) => { this.props.setPrimary(this.props.index) }} />
</span>
<span style={{ marginLeft: "10px" }}>Mandotory
<Switch style={{ marginLeft: "10px" }} defaultChecked={this.state.isMandatory} onChange={(i, e) => { this.changeCheckBox('isMandatory', i) }} />
</span>
</span>) : null}
</Row>
</div>
</div>
)
}
}