-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathbootstrap-decorator.js
66 lines (59 loc) · 3.41 KB
/
bootstrap-decorator.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
angular.module('schemaForm').config(['schemaFormDecoratorsProvider', 'sfBuilderProvider', 'sfPathProvider',
function(decoratorsProvider, sfBuilderProvider, sfPathProvider) {
var base = 'decorators/bootstrap/';
var simpleTransclusion = sfBuilderProvider.builders.simpleTransclusion;
var ngModelOptions = sfBuilderProvider.builders.ngModelOptions;
var ngModel = sfBuilderProvider.builders.ngModel;
var sfField = sfBuilderProvider.builders.sfField;
var condition = sfBuilderProvider.builders.condition;
var array = sfBuilderProvider.builders.array;
// Tabs is so bootstrap specific that it stays here.
var tabs = function(args) {
if (args.form.tabs && args.form.tabs.length > 0) {
var tabContent = args.fieldFrag.querySelector('.tab-content');
args.form.tabs.forEach(function(tab, index) {
var div = document.createElement('div');
div.className = 'tab-pane';
div.setAttribute('ng-disabled', 'form.readonly');
div.setAttribute('ng-show', 'selected.tab === ' + index);
div.setAttribute('ng-class', '{active: selected.tab === ' + index + '}');
var childFrag = args.build(tab.items, args.path + '.tabs[' + index + '].items', args.state);
div.appendChild(childFrag);
tabContent.appendChild(div);
});
}
};
// Set tabArray sortOptions.items default.
var tabArray = function(args) {
if(args.form.hasOwnProperty('sortOptions')) {
if(!args.form.sortOptions.hasOwnProperty('items')) {
args.form.sortOptions['items'] = 'li:not(:last-child)';
}
} else {
args.form['sortOptions'] = {items: 'li:not(:last-child)'};
}
}
var defaults = [sfField, ngModel, ngModelOptions, condition];
decoratorsProvider.defineDecorator('bootstrapDecorator', {
textarea: {template: base + 'textarea.html', builder: defaults},
fieldset: {template: base + 'fieldset.html', builder: [sfField, simpleTransclusion, condition]},
array: {template: base + 'array.html', builder: [sfField, ngModelOptions, ngModel, array, condition]},
tabarray: {template: base + 'tabarray.html', builder: [sfField, ngModelOptions, ngModel, array, condition, tabArray]},
tabs: {template: base + 'tabs.html', builder: [sfField, ngModelOptions, tabs, condition]},
section: {template: base + 'section.html', builder: [sfField, simpleTransclusion, condition]},
conditional: {template: base + 'section.html', builder: [sfField, simpleTransclusion, condition]},
actions: {template: base + 'actions.html', builder: defaults},
select: {template: base + 'select.html', builder: defaults},
checkbox: {template: base + 'checkbox.html', builder: defaults},
checkboxes: {template: base + 'checkboxes.html', builder: [sfField, ngModelOptions, ngModel, array, condition]},
number: {template: base + 'default.html', builder: defaults},
password: {template: base + 'default.html', builder: defaults},
submit: {template: base + 'submit.html', builder: defaults},
button: {template: base + 'submit.html', builder: defaults},
radios: {template: base + 'radios.html', builder: defaults},
'radios-inline': {template: base + 'radios-inline.html', builder: defaults},
radiobuttons: {template: base + 'radio-buttons.html', builder: defaults},
help: {template: base + 'help.html', builder: defaults},
'default': {template: base + 'default.html', builder: defaults}
}, []);
}]);