-
Notifications
You must be signed in to change notification settings - Fork 0
/
itemlist.js
171 lines (152 loc) · 4.9 KB
/
itemlist.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
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
function getItemList(form) {
let json = {};
json.title = form.getTitle();
json.description = form.getDescription();
let list = [];
let items = form.getItems();
for(let i=0;i<items.length;i++) {
let object = {};
let item = items[i];
object.title = item.getTitle();
object.helpText = item.getHelpText();
object.id = item.getId();
object.type = item.getType();
object.extra = getExtraObject(item,object.type);
list.push(object);
}
json.items = list;
return JSON.stringify(json);
}
/**
* Returns question data of form item
*
* @param {FormApp.Item} tmpitem Form item to get data
* @param {FormApp.ItemType} type Type of form item
* @returns
*/
function getExtraObject(tmpitem,type) {
let extra = {};
switch(type)
{
case FormApp.ItemType.MULTIPLE_CHOICE: {
let item = tmpitem.asMultipleChoiceItem();
let choices = item.getChoices();
let choiceList = [];
for(let i=0;i<choices.length;i++)
{
let choice = choices[i];
let choiceObject = {};
choiceObject.value = choice.getValue();
choiceList.push(choiceObject);
}
extra.choices = choiceList;
extra.hasOtherOption = item.hasOtherOption();
extra.required = item.isRequired();
break;
}
case FormApp.ItemType.CHECKBOX:{
const item = tmpitem.asCheckboxItem();
let choices = item.getChoices();
let choiceList = [];
for(let i=0;i<choices.length;i++)
{
let choice = choices[i];
let choiceObject = {};
choiceObject.value = choice.getValue();
choiceList.push(choiceObject);
}
extra.choices = choiceList;
extra.hasOtherOption = item.hasOtherOption();
extra.required = item.isRequired();
break;
}
case FormApp.ItemType.LIST: {
const item = tmpitem.asListItem();
let choices = item.getChoices();
let choiceList = [];
for(let i=0;i<choices.length;i++)
{
let choice = choices[i];
let choiceObject = {};
choiceObject.value = choice.getValue();
choiceList.push(choiceObject);
}
extra.choices = choiceList;
extra.required = item.isRequired();
break;
}
case FormApp.ItemType.TEXT: {
const item = tmpitem.asTextItem();
extra.required = item.isRequired();
break;
}
case FormApp.ItemType.PARAGRAPH_TEXT: {
const item = tmpitem.asParagraphTextItem();
extra.required = item.isRequired();
break;
}
case FormApp.ItemType.SCALE: {
const item = tmpitem.asScaleItem();
extra.leftLabel = item.getLeftLabel();
extra.rightLabel = item.getRightLabel();
extra.lowerBound = item.getLowerBound();
extra.upperBound = item.getUpperBound();
extra.required = item.isRequired();
break;
}
case FormApp.ItemType.GRID: {
const item = tmpitem.asGridItem();
extra.rows = item.getRows();
extra.columns = item.getColumns();
extra.required = item.isRequired();
//@TODO GridValidation
break;
}
case FormApp.ItemType.CHECKBOX_GRID: {
const item = tmpitem.asCheckboxGridItem();
extra.rows = item.getRows();
extra.columns = item.getColumns();
extra.required = item.isRequired();
//@TODO CheckboxGridValidation
break;
}
case FormApp.ItemType.DATE: {
const item = tmpitem.asDateItem();
extra.includesYear = item.includesYear();
extra.required = item.isRequired();
break;
}
case FormApp.ItemType.DATETIME: {
const item = tmpitem.asDateTimeItem();
extra.includesYear = item.includesYear();
extra.required = item.isRequired();
break;
}
case FormApp.ItemType.TIME: {
const item = tmpitem.asTimeItem();
extra.required = item.isRequired();
break;
}
case FormApp.ItemType.DURATION: {
const item = tmpitem.asDurationItem();
extra.required = item.isRequired();
break;
}
case FormApp.ItemType.IMAGE: {
const item = tmpitem.asImageItem();
extra.image = Utilities.base64Encode(item.getImage().getBytes());
extra.imageType = item.getImage().getContentType();
//extra.width = item.getWidth();
extra.alignment = item.getAlignment(); // LEFT, CENTER, RIGHT
break;
}
case FormApp.ItemType.SECTION_HEADER:
break;
case FormApp.ItemType.VIDEO:
case FormApp.ItemType.PAGE_BREAK:
throw new Error(getTranslation('itemlist.workingType', type));
default:
throw new Error(getTranslation('itemlist.unknownType', type));
}
return extra;
}