-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathField.js
66 lines (60 loc) · 1.61 KB
/
Field.js
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
class Field {
constructor({ id, name, type }) {
this.id = id;
this.name = name;
this.type = type;
}
}
class QCMField extends Field {
constructor({ id, name, proposals }) {
super({ id, name, type: 'qcm' });
this.proposals = proposals;
}
}
class QCUField extends Field {
constructor({ id, name, proposals }) {
super({ id, name, type: 'qcu' });
this.proposals = proposals;
}
}
class SelectField extends Field {
constructor({ id, name, proposals }) {
super({ id, name, type: 'select' });
this.proposals = proposals;
}
}
class IdentityField extends Field {
constructor({ id, name }) {
super({ id, name, type: 'identity' });
}
}
class FieldFactory {
static createField(field) {
switch (field.type) {
case 0:
// QROC
case 1:
// QRO
return new Field({ ...field, type: 'text' });
case 2:
return new QCMField({ ...field, proposals: field.values.split('||') });
case 3:
return new QCUField({ ...field, proposals: field.values.split('||') });
case 4:
return new SelectField({ ...field, proposals: field.values.split('||') });
case 5:
// Title
return new Field({ ...field, type: 'title' });
case 6:
if (field.subtype === 1) {
return new IdentityField({ ...field });
}
return new Field({ ...field, type: 'asset' });
default:
console.log(`Type ${field.type} not supported, field ${field.name} with id ${field.id}`);
console.log({ field });
return new Field(field);
}
}
}
export { Field, QCMField, FieldFactory };