-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetOptions.js
More file actions
68 lines (66 loc) · 1.8 KB
/
getOptions.js
File metadata and controls
68 lines (66 loc) · 1.8 KB
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
var _ = require('underscore');
/**
* Gets the options for the List, as used by the React components
*/
function getOptions () {
var ops = {
autocreate: this.options.autocreate,
autokey: this.autokey,
defaultColumns: this.options.defaultColumns,
defaultSort: this.options.defaultSort,
fields: {},
hidden: this.options.hidden,
initialFields: _.pluck(this.initialFields, 'path'),
key: this.key,
label: this.label,
nameField: this.nameField ? this.nameField.getOptions() : null,
nameIsEditable: this.nameIsEditable,
nameIsInitial: this.nameIsInitial,
nameIsVirtual: this.nameIsVirtual,
namePath: this.namePath,
nocreate: this.options.nocreate,
nodelete: this.options.nodelete,
noedit: this.options.noedit,
path: this.path,
plural: this.plural,
searchFields: this.options.searchFields,
singular: this.singular,
sortable: this.options.sortable,
sortContext: this.options.sortContext,
track: this.options.track,
tracking: this.tracking,
uiElements: []
};
_.each(this.uiElements, function (el) {
switch (el.type) {
// TODO: handle indentation
case 'field':
// add the field options by path
ops.fields[el.field.path] = el.field.getOptions();
// don't output the name field as a ui element if it's editable as it'll
// appear as an input in the header
if (el.field === this.nameField && this.nameIsEditable) {
return;
}
// don't output hidden fields
if (el.field.hidden && el.field.type !== 'boolean') {
return;
}
// add the field to the elements array
ops.uiElements.push({
type: 'field',
field: el.field.path
});
break;
case 'heading':
ops.uiElements.push({
type: 'heading',
content: el.heading,
options: el.options
});
break;
}
}, this);
return ops;
}
module.exports = getOptions;