/
form-parameters.js
297 lines (269 loc) · 9.97 KB
/
form-parameters.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
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/**
This class creates input elements. New input parameter types should be added to the types dictionary.
*/
define(['utils/utils',
'mvc/ui/ui-misc',
'mvc/form/form-select-content',
'mvc/ui/ui-select-library',
'mvc/ui/ui-select-ftp',
'mvc/ui/ui-color-picker'],
function(Utils, Ui, SelectContent, SelectLibrary, SelectFtp, ColorPicker) {
// create form view
return Backbone.Model.extend({
/** Available parameter types */
types: {
'text' : '_fieldText',
'select' : '_fieldSelect',
'data_column' : '_fieldSelect',
'genomebuild' : '_fieldSelect',
'data' : '_fieldData',
'data_collection' : '_fieldData',
'integer' : '_fieldSlider',
'float' : '_fieldSlider',
'boolean' : '_fieldBoolean',
'drill_down' : '_fieldDrilldown',
'color' : '_fieldColor',
'hidden' : '_fieldHidden',
'hidden_data' : '_fieldHidden',
'baseurl' : '_fieldHidden',
'library_data' : '_fieldLibrary',
'ftpfile' : '_fieldFtp'
},
// initialize
initialize: function(app, options) {
this.app = app;
},
/** Returns an input field for a given field type
*/
create: function(input_def) {
// add regular/default value if missing
if (input_def.value === undefined) {
input_def.value = null;
}
if (input_def.default_value === undefined) {
input_def.default_value = input_def.value;
}
// field wrapper
var field = null;
// get field class
var fieldClass = this.types[input_def.type];
if (fieldClass && typeof(this[fieldClass]) === 'function') {
field = this[fieldClass].call(this, input_def);
}
// identify field type
if (!field) {
// flag
this.app.incompatible = true;
// with or without options
if (input_def.options) {
// assign select field
field = this._fieldSelect(input_def);
} else {
// assign text field
field = this._fieldText(input_def);
}
// log
Galaxy.emit.debug('form-parameters::_addRow()', 'Auto matched field type (' + input_def.type + ').');
}
// set field value
if (input_def.value !== undefined) {
field.value(input_def.value);
}
// return field element
return field;
},
/** Data input field
*/
_fieldData: function(input_def) {
if (this.app.options.is_workflow) {
input_def.info = 'Data input \'' + input_def.name + '\' (' + Utils.textify(input_def.extensions.toString()) + ')';
input_def.value = null;
return this._fieldHidden(input_def);
}
var self = this;
return new SelectContent.View(this.app, {
id : 'field-' + input_def.id,
extensions : input_def.extensions,
optional : input_def.optional,
multiple : input_def.multiple,
type : input_def.type,
data : input_def.options,
onchange : function() {
self.app.trigger('change');
}
});
},
/** Select/Checkbox/Radio options field
*/
_fieldSelect: function (input_def) {
// show text field in if dynamic fields are disabled e.g. in workflow editor
if (input_def.options.length == 0 && this.app.options.is_workflow) {
return this._fieldText(input_def);
}
// customize properties
if (input_def.type == 'data_column') {
input_def.error_text = 'Missing columns in referenced dataset.'
}
// configure options fields
var options = [];
for (var i in input_def.options) {
var option = input_def.options[i];
options.push({
label: option[0],
value: option[1]
});
}
// identify display type
var SelectClass = Ui.Select;
switch (input_def.display) {
case 'checkboxes':
SelectClass = Ui.Checkbox;
break;
case 'radio':
SelectClass = Ui.Radio;
break;
}
// select field
var self = this;
return new SelectClass.View({
id : 'field-' + input_def.id,
data : options,
error_text : input_def.error_text || 'No options available',
optional : input_def.optional && input_def.default_value === null,
multiple : input_def.multiple,
optional : input_def.optional,
searchable : input_def.searchable,
onchange : function() {
self.app.trigger('change');
}
});
},
/** Drill down options field
*/
_fieldDrilldown: function (input_def) {
// show text field in if dynamic fields are disabled e.g. in workflow editor
if (input_def.options.length == 0 && this.app.options.is_workflow) {
return this._fieldText(input_def);
}
// create drill down field
var self = this;
return new Ui.Drilldown.View({
id : 'field-' + input_def.id,
data : input_def.options,
display : input_def.display,
onchange : function() {
self.app.trigger('change');
}
});
},
/** Text input field
*/
_fieldText: function(input_def) {
// field replaces e.g. a select field
if (input_def.options) {
// show text area if selecting multiple entries is allowed
input_def.area = input_def.multiple;
// validate value
if (!Utils.validate(input_def.value)) {
input_def.value = '';
} else {
if ($.isArray(input_def.value)) {
var str_value = '';
for (var i in input_def.value) {
str_value += String(input_def.value[i]);
if (!input_def.multiple) {
break;
}
str_value += '\n';
}
input_def.value = str_value;
}
}
}
// create input element
var self = this;
return new Ui.Input({
id : 'field-' + input_def.id,
area : input_def.area,
onchange : function() {
self.app.trigger('change');
}
});
},
/** Slider field
*/
_fieldSlider: function(input_def) {
var self = this;
return new Ui.Slider.View({
id : 'field-' + input_def.id,
precise : input_def.type == 'float',
min : input_def.min,
max : input_def.max,
onchange : function() {
self.app.trigger('change');
}
});
},
/** Hidden field
*/
_fieldHidden: function(input_def) {
return new Ui.Hidden({
id : 'field-' + input_def.id,
info : input_def.info
});
},
/** Boolean field
*/
_fieldBoolean: function(input_def) {
var self = this;
return new Ui.RadioButton.View({
id : 'field-' + input_def.id,
data : [ { label : 'Yes', value : 'true' },
{ label : 'No', value : 'false' }],
onchange : function() {
self.app.trigger('change');
}
});
},
/** Color picker field
*/
_fieldColor: function(input_def) {
var self = this;
return new ColorPicker({
id : 'field-' + input_def.id,
onchange : function() {
self.app.trigger('change');
}
});
},
/** Library dataset field
*/
_fieldLibrary: function(input_def) {
var self = this;
return new SelectLibrary.View({
id : 'field-' + input_def.id,
optional : input_def.optional,
multiple : input_def.multiple,
onchange : function() {
self.app.trigger('change');
}
});
},
/** FTP file field
*/
_fieldFtp: function(input_def) {
var self = this;
return new SelectFtp.View({
id : 'field-' + input_def.id,
optional : input_def.optional,
multiple : input_def.multiple,
onchange : function() {
self.app.trigger('change');
}
});
}
});
return {
View: View
};
});