@oat-sa/tao-core-ui 1.58.1 → 1.58.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actionbar.js +386 -395
- package/dist/adder.js +21 -19
- package/dist/animable/absorbable/absorbable.js +204 -213
- package/dist/animable/absorbable/css/absorb.css +1 -0
- package/dist/animable/absorbable/css/absorb.css.map +1 -1
- package/dist/animable/pulsable/pulsable.js +168 -177
- package/dist/autocomplete/css/autocomplete.css +1 -0
- package/dist/autocomplete/css/autocomplete.css.map +1 -1
- package/dist/autocomplete.js +68 -66
- package/dist/badge/badge.js +188 -197
- package/dist/badge/css/badge.css +1 -0
- package/dist/badge/css/badge.css.map +1 -1
- package/dist/breadcrumbs.js +275 -284
- package/dist/btngrouper.js +5 -5
- package/dist/bulkActionPopup.js +490 -495
- package/dist/button.js +283 -291
- package/dist/cascadingComboBox.js +249 -258
- package/dist/ckeditor/ckConfigurator.js +26 -19
- package/dist/ckeditor/dtdHandler.js +11 -9
- package/dist/class/selector.js +441 -450
- package/dist/component/resizable.js +1 -1
- package/dist/component/windowed.js +285 -294
- package/dist/component.js +419 -428
- package/dist/contextualPopup.js +417 -426
- package/dist/dashboard.js +300 -309
- package/dist/datalist.js +753 -762
- package/dist/datatable/filterStrategy/multiple.js +1 -1
- package/dist/datatable/filterStrategy/single.js +1 -1
- package/dist/datatable.js +1527 -1550
- package/dist/dateRange/dateRange.js +393 -402
- package/dist/datetime/picker.js +665 -672
- package/dist/deleter.js +368 -377
- package/dist/destination/selector.js +286 -295
- package/dist/dialog/alert.js +3 -3
- package/dist/dialog/confirm.js +1 -1
- package/dist/dialog/confirmDelete.js +216 -225
- package/dist/dialog.js +650 -654
- package/dist/disabler.js +8 -8
- package/dist/documentViewer/providers/pdfViewer/fallback/viewer.js +166 -175
- package/dist/documentViewer/providers/pdfViewer/pdfjs/findBar.js +518 -527
- package/dist/documentViewer/providers/pdfViewer/pdfjs/pageView.js +380 -389
- package/dist/documentViewer/providers/pdfViewer/pdfjs/searchEngine.js +539 -548
- package/dist/documentViewer/providers/pdfViewer/pdfjs/viewer.js +369 -378
- package/dist/documentViewer/providers/pdfViewer.js +184 -193
- package/dist/documentViewer.js +292 -301
- package/dist/dropdown.js +383 -392
- package/dist/durationer.js +5 -5
- package/dist/dynamicComponent.js +597 -598
- package/dist/feedback.js +356 -362
- package/dist/figure/FigureStateActive.js +117 -108
- package/dist/filesender.js +2 -2
- package/dist/filter.js +230 -239
- package/dist/form/dropdownForm.js +355 -357
- package/dist/form/form.js +919 -690
- package/dist/form/simpleForm.js +1 -1
- package/dist/form/validator/renderer.js +233 -235
- package/dist/form/validator/validator.js +257 -189
- package/dist/form/widget/definitions.js +1 -1
- package/dist/form/widget/providers/checkBox.js +254 -259
- package/dist/form/widget/providers/comboBox.js +187 -192
- package/dist/form/widget/providers/default.js +8 -9
- package/dist/form/widget/providers/hidden.js +170 -179
- package/dist/form/widget/providers/hiddenBox.js +262 -267
- package/dist/form/widget/providers/radioBox.js +216 -225
- package/dist/form/widget/providers/textArea.js +187 -196
- package/dist/form/widget/providers/textBox.js +2 -3
- package/dist/form/widget/widget.js +473 -475
- package/dist/formValidator/formValidator.js +1 -1
- package/dist/formValidator/highlighters/message.js +1 -1
- package/dist/generis/form/form.js +314 -323
- package/dist/generis/validator/validator.js +209 -218
- package/dist/generis/widget/checkBox/checkBox.js +218 -227
- package/dist/generis/widget/comboBox/comboBox.js +179 -188
- package/dist/generis/widget/hiddenBox/hiddenBox.js +220 -229
- package/dist/generis/widget/textBox/textBox.js +169 -178
- package/dist/generis/widget/widget.js +246 -255
- package/dist/groupedComboBox.js +222 -231
- package/dist/groupvalidator.js +2 -2
- package/dist/highlighter.js +967 -958
- package/dist/image/ImgStateActive/helper.js +7 -5
- package/dist/image/ImgStateActive/initHelper.js +49 -43
- package/dist/image/ImgStateActive/initMediaEditor.js +24 -20
- package/dist/image/ImgStateActive/mediaSizer.js +14 -12
- package/dist/image/ImgStateActive.js +72 -70
- package/dist/incrementer.js +6 -6
- package/dist/inplacer.js +6 -6
- package/dist/itemButtonList/css/item-button-list.css +1 -0
- package/dist/itemButtonList/css/item-button-list.css.map +1 -1
- package/dist/itemButtonList.js +439 -435
- package/dist/keyNavigation/navigableDomElement.js +51 -38
- package/dist/keyNavigation/navigator.js +85 -70
- package/dist/listbox.js +460 -469
- package/dist/liststyler.js +8 -8
- package/dist/loadingButton/loadingButton.js +209 -218
- package/dist/lock.js +476 -485
- package/dist/login/login.js +475 -484
- package/dist/maths/calculator/basicCalculator.js +235 -244
- package/dist/maths/calculator/calculatorComponent.js +3 -3
- package/dist/maths/calculator/core/board.js +772 -781
- package/dist/maths/calculator/core/expression.js +476 -485
- package/dist/maths/calculator/core/labels.js +228 -237
- package/dist/maths/calculator/core/tokenizer.js +1 -1
- package/dist/maths/calculator/core/tokens.js +163 -170
- package/dist/maths/calculator/plugins/keyboard/templateKeyboard/templateKeyboard.js +244 -253
- package/dist/maths/calculator/plugins/screen/simpleScreen/simpleScreen.js +279 -288
- package/dist/maths/calculator/scientificCalculator.js +327 -336
- package/dist/mediaEditor/mediaEditorComponent.js +238 -245
- package/dist/mediaEditor/plugins/mediaAlignment/helper.js +7 -7
- package/dist/mediaEditor/plugins/mediaAlignment/mediaAlignmentComponent.js +229 -235
- package/dist/mediaEditor/plugins/mediaDimension/mediaDimensionComponent.js +580 -589
- package/dist/mediaplayer/players/html5.js +666 -675
- package/dist/mediaplayer/players/youtube.js +419 -424
- package/dist/mediaplayer/support.js +11 -10
- package/dist/mediaplayer/utils/reminder.js +14 -13
- package/dist/mediaplayer/utils/timeObserver.js +10 -11
- package/dist/mediaplayer/youtubeManager.js +164 -145
- package/dist/mediaplayer.js +1565 -1520
- package/dist/mediasizer.js +669 -678
- package/dist/modal.js +10 -17
- package/dist/pageSizeSelector.js +219 -228
- package/dist/pagination/providers/pages.js +280 -289
- package/dist/pagination/providers/simple.js +192 -201
- package/dist/previewer.js +30 -30
- package/dist/progressbar.js +4 -4
- package/dist/report.js +347 -356
- package/dist/resource/filters.js +271 -280
- package/dist/resource/list.js +1264 -1273
- package/dist/resource/selector.js +865 -874
- package/dist/resource/tree.js +1483 -1492
- package/dist/resourcemgr/fileBrowser.js +564 -569
- package/dist/resourcemgr/filePreview.js +16 -16
- package/dist/resourcemgr/fileSelector.js +515 -524
- package/dist/resourcemgr/util/updatePermissions.js +2 -2
- package/dist/resourcemgr.js +306 -315
- package/dist/searchModal/advancedSearch.js +796 -767
- package/dist/searchModal.js +114 -91
- package/dist/switch/switch.js +298 -307
- package/dist/tabs.js +598 -575
- package/dist/taskQueue/status.js +312 -321
- package/dist/taskQueue/table.js +375 -384
- package/dist/taskQueue/taskQueueModel.js +488 -472
- package/dist/taskQueueButton/taskable.js +264 -273
- package/dist/taskQueueButton/treeButton.js +189 -198
- package/dist/themeLoader.js +24 -23
- package/dist/themes.js +1 -1
- package/dist/toggler.js +3 -3
- package/dist/tooltip.js +295 -304
- package/dist/transformer.js +2 -2
- package/dist/tristateCheckboxGroup.js +311 -320
- package/dist/uploader.js +687 -696
- package/dist/validator/Report.js +1 -1
- package/dist/validator/Validator.js +3 -3
- package/dist/validator/validators.js +9 -9
- package/dist/validator.js +240 -230
- package/dist/waitForMedia.js +1 -1
- package/package.json +3 -3
- package/src/animable/absorbable/css/absorb.css +1 -0
- package/src/animable/absorbable/css/absorb.css.map +1 -1
- package/src/autocomplete/css/autocomplete.css +1 -0
- package/src/autocomplete/css/autocomplete.css.map +1 -1
- package/src/badge/css/badge.css +1 -0
- package/src/badge/css/badge.css.map +1 -1
- package/src/ckeditor/ckConfigurator.js +4 -0
- package/src/itemButtonList/css/item-button-list.css +1 -0
- package/src/itemButtonList/css/item-button-list.css.map +1 -1
- package/src/.DS_Store +0 -0
- package/src/css/basic.css +0 -7826
- package/src/css/basic.css.map +0 -1
- package/src/css/ckeditor/skins/tao/css/dialog.css +0 -950
- package/src/css/ckeditor/skins/tao/css/dialog.css.map +0 -1
- package/src/css/ckeditor/skins/tao/css/editor.css +0 -1850
- package/src/css/ckeditor/skins/tao/css/editor.css.map +0 -1
- package/src/scss/.DS_Store +0 -0
- package/src/scss/basic.scss +0 -16
- package/src/scss/ckeditor/skins/tao/scss/dialog.scss +0 -763
- package/src/scss/ckeditor/skins/tao/scss/editor.scss +0 -111
- package/src/scss/ckeditor/skins/tao/scss/inc/_ck-icons.scss +0 -59
- package/src/scss/ckeditor/skins/tao/scss/inc/_colorpanel.scss +0 -118
- package/src/scss/ckeditor/skins/tao/scss/inc/_elementspath.scss +0 -69
- package/src/scss/ckeditor/skins/tao/scss/inc/_mainui.scss +0 -194
- package/src/scss/ckeditor/skins/tao/scss/inc/_menu.scss +0 -181
- package/src/scss/ckeditor/skins/tao/scss/inc/_panel.scss +0 -200
- package/src/scss/ckeditor/skins/tao/scss/inc/_presets.scss +0 -32
- package/src/scss/ckeditor/skins/tao/scss/inc/_reset.scss +0 -101
- package/src/scss/ckeditor/skins/tao/scss/inc/_richcombo.scss +0 -213
- package/src/scss/ckeditor/skins/tao/scss/inc/_tao.scss +0 -59
- package/src/scss/ckeditor/skins/tao/scss/inc/_toolbar.scss +0 -301
- package/src/scss/font/source-sans-pro/source-sans-pro-italic.eot +0 -0
- package/src/scss/font/source-sans-pro/source-sans-pro-italic.eot.b64 +0 -1
- package/src/scss/font/source-sans-pro/source-sans-pro-italic.woff +0 -0
- package/src/scss/font/source-sans-pro/source-sans-pro-italic.woff.b64 +0 -1
- package/src/scss/font/source-sans-pro/source-sans-pro-regular.eot +0 -0
- package/src/scss/font/source-sans-pro/source-sans-pro-regular.eot.b64 +0 -1
- package/src/scss/font/source-sans-pro/source-sans-pro-regular.woff +0 -0
- package/src/scss/font/source-sans-pro/source-sans-pro-regular.woff.b64 +0 -1
- package/src/scss/font/source-sans-pro/source-sans-pro-semibold-italic.eot +0 -0
- package/src/scss/font/source-sans-pro/source-sans-pro-semibold-italic.eot.b64 +0 -1
- package/src/scss/font/source-sans-pro/source-sans-pro-semibold-italic.woff +0 -0
- package/src/scss/font/source-sans-pro/source-sans-pro-semibold-italic.woff.b64 +0 -1
- package/src/scss/font/source-sans-pro/source-sans-pro-semibold.eot +0 -0
- package/src/scss/font/source-sans-pro/source-sans-pro-semibold.eot.b64 +0 -1
- package/src/scss/font/source-sans-pro/source-sans-pro-semibold.woff +0 -0
- package/src/scss/font/source-sans-pro/source-sans-pro-semibold.woff.b64 +0 -1
- package/src/scss/font/tao/tao.eot +0 -0
- package/src/scss/font/tao/tao.svg +0 -235
- package/src/scss/font/tao/tao.ttf +0 -0
- package/src/scss/font/tao/tao.woff +0 -0
- package/src/scss/inc/_base.scss +0 -496
- package/src/scss/inc/_bootstrap.scss +0 -6
- package/src/scss/inc/_buttons.scss +0 -114
- package/src/scss/inc/_colors.scss +0 -88
- package/src/scss/inc/_feedback.scss +0 -150
- package/src/scss/inc/_flex-grid.scss +0 -15
- package/src/scss/inc/_fonts.scss +0 -4
- package/src/scss/inc/_forms.scss +0 -827
- package/src/scss/inc/_functions.scss +0 -283
- package/src/scss/inc/_grid.scss +0 -66
- package/src/scss/inc/_jquery.nouislider.scss +0 -254
- package/src/scss/inc/_normalize.scss +0 -528
- package/src/scss/inc/_report.scss +0 -68
- package/src/scss/inc/_secondary-properties.scss +0 -89
- package/src/scss/inc/_select2.scss +0 -634
- package/src/scss/inc/_toolbars.scss +0 -155
- package/src/scss/inc/_tooltip.scss +0 -312
- package/src/scss/inc/_variables.scss +0 -21
- package/src/scss/inc/base/_highlight.scss +0 -5
- package/src/scss/inc/base/_list-style.scss +0 -59
- package/src/scss/inc/base/_svg.scss +0 -3
- package/src/scss/inc/base/_table.scss +0 -63
- package/src/scss/inc/fonts/_source-sans-pro.scss +0 -29
- package/src/scss/inc/fonts/_tao-icon-classes.scss +0 -226
- package/src/scss/inc/fonts/_tao-icon-def.scss +0 -12
- package/src/scss/inc/fonts/_tao-icon-vars.scss +0 -240
package/dist/form/form.js
CHANGED
|
@@ -1,836 +1,1065 @@
|
|
|
1
1
|
define(['lodash', 'ui/component', 'ui/button', 'ui/hider', 'ui/form/widget/definitions', 'ui/form/widget/loader', 'handlebars', 'i18n', 'lib/dompurify/purify', 'css!ui/form/css/form.css'], function (_, componentFactory, buttonFactory, hider, widgetDefinitions, widgetFactory, Handlebars, __, DOMPurify, form_css) { 'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
_ = _ && Object.prototype.hasOwnProperty.call(_, 'default') ? _['default'] : _;
|
|
4
|
+
componentFactory = componentFactory && Object.prototype.hasOwnProperty.call(componentFactory, 'default') ? componentFactory['default'] : componentFactory;
|
|
5
|
+
buttonFactory = buttonFactory && Object.prototype.hasOwnProperty.call(buttonFactory, 'default') ? buttonFactory['default'] : buttonFactory;
|
|
6
|
+
hider = hider && Object.prototype.hasOwnProperty.call(hider, 'default') ? hider['default'] : hider;
|
|
7
|
+
widgetDefinitions = widgetDefinitions && Object.prototype.hasOwnProperty.call(widgetDefinitions, 'default') ? widgetDefinitions['default'] : widgetDefinitions;
|
|
8
|
+
widgetFactory = widgetFactory && Object.prototype.hasOwnProperty.call(widgetFactory, 'default') ? widgetFactory['default'] : widgetFactory;
|
|
9
|
+
Handlebars = Handlebars && Object.prototype.hasOwnProperty.call(Handlebars, 'default') ? Handlebars['default'] : Handlebars;
|
|
10
|
+
__ = __ && Object.prototype.hasOwnProperty.call(__, 'default') ? __['default'] : __;
|
|
11
|
+
DOMPurify = DOMPurify && Object.prototype.hasOwnProperty.call(DOMPurify, 'default') ? DOMPurify['default'] : DOMPurify;
|
|
12
|
+
|
|
13
|
+
function _typeof(obj) {
|
|
14
|
+
"@babel/helpers - typeof";
|
|
15
|
+
|
|
16
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
17
|
+
return typeof obj;
|
|
18
|
+
} : function (obj) {
|
|
19
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
20
|
+
}, _typeof(obj);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function _slicedToArray(arr, i) {
|
|
24
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function _arrayWithHoles(arr) {
|
|
28
|
+
if (Array.isArray(arr)) return arr;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function _iterableToArrayLimit(arr, i) {
|
|
32
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
33
|
+
|
|
34
|
+
if (_i == null) return;
|
|
35
|
+
var _arr = [];
|
|
36
|
+
var _n = true;
|
|
37
|
+
var _d = false;
|
|
38
|
+
|
|
39
|
+
var _s, _e;
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
43
|
+
_arr.push(_s.value);
|
|
44
|
+
|
|
45
|
+
if (i && _arr.length === i) break;
|
|
46
|
+
}
|
|
47
|
+
} catch (err) {
|
|
48
|
+
_d = true;
|
|
49
|
+
_e = err;
|
|
50
|
+
} finally {
|
|
51
|
+
try {
|
|
52
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
53
|
+
} finally {
|
|
54
|
+
if (_d) throw _e;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return _arr;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
62
|
+
if (!o) return;
|
|
63
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
64
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
65
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
66
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
67
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function _arrayLikeToArray(arr, len) {
|
|
71
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
72
|
+
|
|
73
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
74
|
+
|
|
75
|
+
return arr2;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function _nonIterableRest() {
|
|
79
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
83
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
84
|
+
|
|
85
|
+
if (!it) {
|
|
86
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
87
|
+
if (it) o = it;
|
|
88
|
+
var i = 0;
|
|
89
|
+
|
|
90
|
+
var F = function () {};
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
s: F,
|
|
94
|
+
n: function () {
|
|
95
|
+
if (i >= o.length) return {
|
|
96
|
+
done: true
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
done: false,
|
|
100
|
+
value: o[i++]
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
e: function (e) {
|
|
104
|
+
throw e;
|
|
105
|
+
},
|
|
106
|
+
f: F
|
|
107
|
+
};
|
|
108
|
+
}
|
|
12
109
|
|
|
110
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
var normalCompletion = true,
|
|
114
|
+
didErr = false,
|
|
115
|
+
err;
|
|
116
|
+
return {
|
|
117
|
+
s: function () {
|
|
118
|
+
it = it.call(o);
|
|
119
|
+
},
|
|
120
|
+
n: function () {
|
|
121
|
+
var step = it.next();
|
|
122
|
+
normalCompletion = step.done;
|
|
123
|
+
return step;
|
|
124
|
+
},
|
|
125
|
+
e: function (e) {
|
|
126
|
+
didErr = true;
|
|
127
|
+
err = e;
|
|
128
|
+
},
|
|
129
|
+
f: function () {
|
|
130
|
+
try {
|
|
131
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
132
|
+
} finally {
|
|
133
|
+
if (didErr) throw err;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function Helpers0 (hb) {
|
|
140
|
+
//register a i18n helper
|
|
141
|
+
hb.registerHelper('__', function (key) {
|
|
142
|
+
return __(key);
|
|
143
|
+
});
|
|
13
144
|
/**
|
|
14
|
-
*
|
|
15
|
-
* modify it under the terms of the GNU General Public License
|
|
16
|
-
* as published by the Free Software Foundation; under version 2
|
|
17
|
-
* of the License (non-upgradable).
|
|
18
|
-
*
|
|
19
|
-
* This program is distributed in the hope that it will be useful,
|
|
20
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22
|
-
* GNU General Public License for more details.
|
|
23
|
-
*
|
|
24
|
-
* You should have received a copy of the GNU General Public License
|
|
25
|
-
* along with this program; if not, write to the Free Software
|
|
26
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
27
|
-
*
|
|
28
|
-
* Copyright (c) 2013-2019 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
|
|
145
|
+
* Register dompurify helper
|
|
29
146
|
*
|
|
147
|
+
* https://github.com/cure53/DOMPurify
|
|
148
|
+
* with config SAFE_FOR_TEMPLATES: true
|
|
149
|
+
* to make output safe for template systems
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
hb.registerHelper('dompurify', function (context) {
|
|
153
|
+
return DOMPurify.sanitize(context);
|
|
154
|
+
});
|
|
155
|
+
/**
|
|
156
|
+
* Register join helper
|
|
30
157
|
*
|
|
158
|
+
* Example :
|
|
159
|
+
* var values = {a:v1, b:v2, c:v3};
|
|
160
|
+
* Using {{{join attributes '=' ' ' '"'}}} will return : a="v1" b="v2" c="v3"
|
|
161
|
+
* Using {{{join values null ' or ' '*'}}} will return : *v1* or *v2* or *v3*
|
|
31
162
|
*/
|
|
32
|
-
function Helpers0 (hb) {
|
|
33
|
-
//register a i18n helper
|
|
34
|
-
hb.registerHelper('__', function (key) {
|
|
35
|
-
return __(key);
|
|
36
|
-
});
|
|
37
|
-
/**
|
|
38
|
-
* Register dompurify helper
|
|
39
|
-
*
|
|
40
|
-
* https://github.com/cure53/DOMPurify
|
|
41
|
-
* with config SAFE_FOR_TEMPLATES: true
|
|
42
|
-
* to make output safe for template systems
|
|
43
|
-
*/
|
|
44
163
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*
|
|
51
|
-
* Example :
|
|
52
|
-
* var values = {a:v1, b:v2, c:v3};
|
|
53
|
-
* Using {{{join attributes '=' ' ' '"'}}} will return : a="v1" b="v2" c="v3"
|
|
54
|
-
* Using {{{join values null ' or ' '*'}}} will return : *v1* or *v2* or *v3*
|
|
55
|
-
*/
|
|
164
|
+
hb.registerHelper('join', function (arr, keyValueGlue, fragmentGlue, wrapper) {
|
|
165
|
+
var fragments = [];
|
|
166
|
+
keyValueGlue = typeof keyValueGlue === 'string' ? keyValueGlue : undefined;
|
|
167
|
+
fragmentGlue = typeof fragmentGlue === 'string' ? fragmentGlue : ' ';
|
|
168
|
+
wrapper = typeof wrapper === 'string' ? wrapper : '"';
|
|
56
169
|
|
|
57
|
-
|
|
58
|
-
var
|
|
59
|
-
keyValueGlue = typeof keyValueGlue === 'string' ? keyValueGlue : undefined;
|
|
60
|
-
fragmentGlue = typeof fragmentGlue === 'string' ? fragmentGlue : ' ';
|
|
61
|
-
wrapper = typeof wrapper === 'string' ? wrapper : '"';
|
|
62
|
-
|
|
63
|
-
_.forIn(arr, function (value, key) {
|
|
64
|
-
var fragment = '';
|
|
65
|
-
|
|
66
|
-
if (value !== null || value !== undefined) {
|
|
67
|
-
if (typeof value === 'boolean') {
|
|
68
|
-
value = value ? 'true' : 'false';
|
|
69
|
-
} else if (typeof value === 'object') {
|
|
70
|
-
value = _.values(value).join(' ');
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
value = '';
|
|
74
|
-
}
|
|
170
|
+
_.forIn(arr, function (value, key) {
|
|
171
|
+
var fragment = '';
|
|
75
172
|
|
|
76
|
-
|
|
77
|
-
|
|
173
|
+
if (value !== null || value !== undefined) {
|
|
174
|
+
if (typeof value === 'boolean') {
|
|
175
|
+
value = value ? 'true' : 'false';
|
|
176
|
+
} else if (_typeof(value) === 'object') {
|
|
177
|
+
value = _.values(value).join(' ');
|
|
78
178
|
}
|
|
179
|
+
} else {
|
|
180
|
+
value = '';
|
|
181
|
+
}
|
|
79
182
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return fragments.join(fragmentGlue);
|
|
85
|
-
}); //register a classic "for loop" helper
|
|
86
|
-
//it also adds a local variable "i" as the index in each iteration loop
|
|
87
|
-
|
|
88
|
-
hb.registerHelper('for', function (startIndex, stopIndex, increment, options) {
|
|
89
|
-
var ret = '';
|
|
90
|
-
startIndex = parseInt(startIndex);
|
|
91
|
-
stopIndex = parseInt(stopIndex);
|
|
92
|
-
increment = parseInt(increment);
|
|
93
|
-
|
|
94
|
-
for (var i = startIndex; i < stopIndex; i += increment) {
|
|
95
|
-
ret += options.fn(_.extend({}, this, {
|
|
96
|
-
i: i
|
|
97
|
-
}));
|
|
183
|
+
if (keyValueGlue !== undefined) {
|
|
184
|
+
fragment += key + keyValueGlue;
|
|
98
185
|
}
|
|
99
186
|
|
|
100
|
-
|
|
187
|
+
fragment += wrapper + value + wrapper;
|
|
188
|
+
fragments.push(fragment);
|
|
101
189
|
});
|
|
102
|
-
hb.registerHelper('equal', function (var1, var2, options) {
|
|
103
|
-
if (var1 == var2) {
|
|
104
|
-
return options.fn(this);
|
|
105
|
-
} else {
|
|
106
|
-
return options.inverse(this);
|
|
107
|
-
}
|
|
108
|
-
}); // register a "get property" helper
|
|
109
|
-
// it gets the named property from the provided context
|
|
110
190
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
// it checks if value is in array
|
|
191
|
+
return fragments.join(fragmentGlue);
|
|
192
|
+
}); //register a classic "for loop" helper
|
|
193
|
+
//it also adds a local variable "i" as the index in each iteration loop
|
|
115
194
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
195
|
+
hb.registerHelper('for', function (startIndex, stopIndex, increment, options) {
|
|
196
|
+
var ret = '';
|
|
197
|
+
startIndex = parseInt(startIndex);
|
|
198
|
+
stopIndex = parseInt(stopIndex);
|
|
199
|
+
increment = parseInt(increment);
|
|
122
200
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
var Template = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
|
|
128
|
-
this.compilerInfo = [4,'>= 1.0.0'];
|
|
129
|
-
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|
130
|
-
var buffer = "", stack1, helper, functionType="function", escapeExpression=this.escapeExpression, self=this;
|
|
131
|
-
|
|
132
|
-
function program1(depth0,data) {
|
|
133
|
-
|
|
134
|
-
var buffer = "", stack1, helper;
|
|
135
|
-
buffer += " action=\"";
|
|
136
|
-
if (helper = helpers.formAction) { stack1 = helper.call(depth0, {hash:{},data:data}); }
|
|
137
|
-
else { helper = (depth0 && depth0.formAction); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
|
|
138
|
-
buffer += escapeExpression(stack1)
|
|
139
|
-
+ "\"";
|
|
140
|
-
return buffer;
|
|
201
|
+
for (var i = startIndex; i < stopIndex; i += increment) {
|
|
202
|
+
ret += options.fn(_.extend({}, this, {
|
|
203
|
+
i: i
|
|
204
|
+
}));
|
|
141
205
|
}
|
|
142
206
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
else {
|
|
149
|
-
|
|
150
|
-
+ "\"";
|
|
151
|
-
return buffer;
|
|
207
|
+
return ret;
|
|
208
|
+
});
|
|
209
|
+
hb.registerHelper('equal', function (var1, var2, options) {
|
|
210
|
+
if (var1 == var2) {
|
|
211
|
+
return options.fn(this);
|
|
212
|
+
} else {
|
|
213
|
+
return options.inverse(this);
|
|
152
214
|
}
|
|
215
|
+
}); // register a "get property" helper
|
|
216
|
+
// it gets the named property from the provided context
|
|
153
217
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
+ "</h2>\n <form";
|
|
159
|
-
stack1 = helpers['if'].call(depth0, (depth0 && depth0.formAction), {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
|
|
160
|
-
if(stack1 || stack1 === 0) { buffer += stack1; }
|
|
161
|
-
stack1 = helpers['if'].call(depth0, (depth0 && depth0.formMethod), {hash:{},inverse:self.noop,fn:self.program(3, program3, data),data:data});
|
|
162
|
-
if(stack1 || stack1 === 0) { buffer += stack1; }
|
|
163
|
-
buffer += ">\n <fieldset class=\"fieldset\"></fieldset>\n <div class=\"form-actions\"></div>\n </form>\n</div>\n";
|
|
164
|
-
return buffer;
|
|
165
|
-
});
|
|
166
|
-
function formTpl(data, options, asString) {
|
|
167
|
-
var html = Template(data, options);
|
|
168
|
-
return (asString || true) ? html : $(html);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* This program is free software; you can redistribute it and/or
|
|
173
|
-
* modify it under the terms of the GNU General Public License
|
|
174
|
-
* as published by the Free Software Foundation; under version 2
|
|
175
|
-
* of the License (non-upgradable).
|
|
176
|
-
*
|
|
177
|
-
* This program is distributed in the hope that it will be useful,
|
|
178
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
179
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
180
|
-
* GNU General Public License for more details.
|
|
181
|
-
*
|
|
182
|
-
* You should have received a copy of the GNU General Public License
|
|
183
|
-
* along with this program; if not, write to the Free Software
|
|
184
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
185
|
-
*
|
|
186
|
-
* Copyright (c) 2019 Open Assessment Technologies SA ;
|
|
187
|
-
*/
|
|
188
|
-
/**
|
|
189
|
-
* @typedef {Object} formConfig Defines the config entries available to setup a form
|
|
190
|
-
* @property {String} [title] - An optional title for the form (default none)
|
|
191
|
-
* @property {String} [formAction] - The url the form is targeting (default '')
|
|
192
|
-
* @property {String} [formMethod] - The HTTP method the form should use (default '')
|
|
193
|
-
* @property {widgetConfig[]} [widgets] - The list of widgets to set in the form (default none)
|
|
194
|
-
* @property {buttonConfig[]} [buttons] - The list of buttons to set in the form (default none)
|
|
195
|
-
* @property {Object} [values] - Initial values for the widgets
|
|
196
|
-
* @property {Object} [ranges] - An optional list of ranges for the widgets (@see widgetConfig.range)
|
|
197
|
-
*/
|
|
218
|
+
hb.registerHelper('property', function (name, context) {
|
|
219
|
+
return context[name] || '';
|
|
220
|
+
}); // register an 'includes' helper
|
|
221
|
+
// it checks if value is in array
|
|
198
222
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
223
|
+
hb.registerHelper('includes', function (haystack, needle, options) {
|
|
224
|
+
if (_.contains(haystack, needle)) {
|
|
225
|
+
return options.fn(this);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (!Helpers0.__initialized) {
|
|
231
|
+
Helpers0(Handlebars);
|
|
232
|
+
Helpers0.__initialized = true;
|
|
233
|
+
}
|
|
234
|
+
var Template = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
|
|
235
|
+
this.compilerInfo = [4,'>= 1.0.0'];
|
|
236
|
+
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|
237
|
+
var buffer = "", stack1, helper, functionType="function", escapeExpression=this.escapeExpression, self=this;
|
|
238
|
+
|
|
239
|
+
function program1(depth0,data) {
|
|
240
|
+
|
|
241
|
+
var buffer = "", stack1, helper;
|
|
242
|
+
buffer += " action=\"";
|
|
243
|
+
if (helper = helpers.formAction) { stack1 = helper.call(depth0, {hash:{},data:data}); }
|
|
244
|
+
else { helper = (depth0 && depth0.formAction); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
|
|
245
|
+
buffer += escapeExpression(stack1)
|
|
246
|
+
+ "\"";
|
|
247
|
+
return buffer;
|
|
248
|
+
}
|
|
209
249
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
250
|
+
function program3(depth0,data) {
|
|
251
|
+
|
|
252
|
+
var buffer = "", stack1, helper;
|
|
253
|
+
buffer += " method=\"";
|
|
254
|
+
if (helper = helpers.formMethod) { stack1 = helper.call(depth0, {hash:{},data:data}); }
|
|
255
|
+
else { helper = (depth0 && depth0.formMethod); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
|
|
256
|
+
buffer += escapeExpression(stack1)
|
|
257
|
+
+ "\"";
|
|
258
|
+
return buffer;
|
|
259
|
+
}
|
|
218
260
|
|
|
219
|
-
|
|
220
|
-
|
|
261
|
+
buffer += "<div class=\"form-component\">\n <h2 class=\"form-title\">";
|
|
262
|
+
if (helper = helpers.title) { stack1 = helper.call(depth0, {hash:{},data:data}); }
|
|
263
|
+
else { helper = (depth0 && depth0.title); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
|
|
264
|
+
buffer += escapeExpression(stack1)
|
|
265
|
+
+ "</h2>\n <form";
|
|
266
|
+
stack1 = helpers['if'].call(depth0, (depth0 && depth0.formAction), {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
|
|
267
|
+
if(stack1 || stack1 === 0) { buffer += stack1; }
|
|
268
|
+
stack1 = helpers['if'].call(depth0, (depth0 && depth0.formMethod), {hash:{},inverse:self.noop,fn:self.program(3, program3, data),data:data});
|
|
269
|
+
if(stack1 || stack1 === 0) { buffer += stack1; }
|
|
270
|
+
buffer += ">\n <fieldset class=\"fieldset\"></fieldset>\n <div class=\"form-actions\"></div>\n </form>\n</div>\n";
|
|
271
|
+
return buffer;
|
|
272
|
+
});
|
|
273
|
+
function formTpl(data, options, asString) {
|
|
274
|
+
var html = Template(data, options);
|
|
275
|
+
return (asString || true) ? html : $(html);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* @typedef {Object} formConfig Defines the config entries available to setup a form
|
|
280
|
+
* @property {String} [title] - An optional title for the form (default none)
|
|
281
|
+
* @property {String} [formAction] - The url the form is targeting (default '')
|
|
282
|
+
* @property {String} [formMethod] - The HTTP method the form should use (default '')
|
|
283
|
+
* @property {widgetConfig[]} [widgets] - The list of widgets to set in the form (default none)
|
|
284
|
+
* @property {buttonConfig[]} [buttons] - The list of buttons to set in the form (default none)
|
|
285
|
+
* @property {Object} [values] - Initial values for the widgets
|
|
286
|
+
* @property {Object} [ranges] - An optional list of ranges for the widgets (@see widgetConfig.range)
|
|
287
|
+
*/
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @typedef {Object} widgetValue Defines the value serialized from a widget
|
|
291
|
+
* @property {String} name - The identifier of the widget
|
|
292
|
+
* @property {String} value - The value of the widget
|
|
293
|
+
*/
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Some default config
|
|
297
|
+
* @type {formConfig}
|
|
298
|
+
*/
|
|
299
|
+
|
|
300
|
+
var defaults = {
|
|
301
|
+
formAction: '',
|
|
302
|
+
formMethod: ''
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Enables all components from the list
|
|
306
|
+
* @param {Map} collection
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
function enableComponents(collection) {
|
|
310
|
+
var _iterator = _createForOfIteratorHelper(collection.values()),
|
|
311
|
+
_step;
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
315
|
+
var component = _step.value;
|
|
221
316
|
component.enable();
|
|
222
317
|
}
|
|
318
|
+
} catch (err) {
|
|
319
|
+
_iterator.e(err);
|
|
320
|
+
} finally {
|
|
321
|
+
_iterator.f();
|
|
223
322
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Disables all components from the list
|
|
326
|
+
* @param {Map} collection
|
|
327
|
+
*/
|
|
228
328
|
|
|
229
329
|
|
|
230
|
-
|
|
231
|
-
|
|
330
|
+
function disableComponents(collection) {
|
|
331
|
+
var _iterator2 = _createForOfIteratorHelper(collection.values()),
|
|
332
|
+
_step2;
|
|
333
|
+
|
|
334
|
+
try {
|
|
335
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
336
|
+
var component = _step2.value;
|
|
232
337
|
component.disable();
|
|
233
338
|
}
|
|
339
|
+
} catch (err) {
|
|
340
|
+
_iterator2.e(err);
|
|
341
|
+
} finally {
|
|
342
|
+
_iterator2.f();
|
|
234
343
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Remove and destroy a component from a collection.
|
|
347
|
+
* @param {Map} collection
|
|
348
|
+
* @param {String} key
|
|
349
|
+
*/
|
|
240
350
|
|
|
241
351
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
352
|
+
function removeComponent(collection, key) {
|
|
353
|
+
collection.get(key).off('.form').destroy();
|
|
354
|
+
collection.delete(key);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Gets indexed components from a collection.
|
|
358
|
+
* @param {Map} collection
|
|
359
|
+
* @returns {Object}
|
|
360
|
+
*/
|
|
251
361
|
|
|
252
362
|
|
|
253
|
-
|
|
254
|
-
|
|
363
|
+
function getComponents(collection) {
|
|
364
|
+
var components = {};
|
|
365
|
+
|
|
366
|
+
var _iterator3 = _createForOfIteratorHelper(collection),
|
|
367
|
+
_step3;
|
|
368
|
+
|
|
369
|
+
try {
|
|
370
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
371
|
+
var _step3$value = _slicedToArray(_step3.value, 2),
|
|
372
|
+
id = _step3$value[0],
|
|
373
|
+
component = _step3$value[1];
|
|
255
374
|
|
|
256
|
-
for (let [id, component] of collection) {
|
|
257
375
|
components[id] = component;
|
|
258
376
|
}
|
|
259
|
-
|
|
260
|
-
|
|
377
|
+
} catch (err) {
|
|
378
|
+
_iterator3.e(err);
|
|
379
|
+
} finally {
|
|
380
|
+
_iterator3.f();
|
|
261
381
|
}
|
|
262
|
-
/**
|
|
263
|
-
* Wait for a component to be ready
|
|
264
|
-
* @param {component} component - The target component
|
|
265
|
-
* @returns {Promise<component>}
|
|
266
|
-
*/
|
|
267
382
|
|
|
383
|
+
return components;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Wait for a component to be ready
|
|
387
|
+
* @param {component} component - The target component
|
|
388
|
+
* @returns {Promise<component>}
|
|
389
|
+
*/
|
|
268
390
|
|
|
269
|
-
function waitForRender(component) {
|
|
270
|
-
return new Promise(function renderPromise(resolve) {
|
|
271
|
-
const resolveRender = () => resolve(component);
|
|
272
391
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Validates a widget/button definition, then returns a promise
|
|
282
|
-
* @param {component} component - The target component
|
|
283
|
-
* @param {Object} definition - The definition to check
|
|
284
|
-
* @param {String} key - The key name for the identifier within the definition object
|
|
285
|
-
* @returns {Promise<component>}
|
|
286
|
-
*/
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
function validateDefinition(component, definition, key) {
|
|
290
|
-
if (!_.isPlainObject(definition)) {
|
|
291
|
-
return Promise.reject(new TypeError('The definition must be an object'));
|
|
292
|
-
}
|
|
392
|
+
function waitForRender(component) {
|
|
393
|
+
return new Promise(function renderPromise(resolve) {
|
|
394
|
+
var resolveRender = function resolveRender() {
|
|
395
|
+
return resolve(component);
|
|
396
|
+
};
|
|
293
397
|
|
|
294
|
-
if (
|
|
295
|
-
|
|
398
|
+
if (component.is('rendered')) {
|
|
399
|
+
resolveRender();
|
|
400
|
+
} else {
|
|
401
|
+
component.on('ready', resolveRender);
|
|
296
402
|
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Validates a widget/button definition, then returns a promise
|
|
407
|
+
* @param {component} component - The target component
|
|
408
|
+
* @param {Object} definition - The definition to check
|
|
409
|
+
* @param {String} key - The key name for the identifier within the definition object
|
|
410
|
+
* @returns {Promise<component>}
|
|
411
|
+
*/
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
function validateDefinition(component, definition, key) {
|
|
415
|
+
if (!_.isPlainObject(definition)) {
|
|
416
|
+
return Promise.reject(new TypeError('The definition must be an object'));
|
|
417
|
+
}
|
|
297
418
|
|
|
298
|
-
|
|
419
|
+
if (!definition[key] || !_.isString(definition[key])) {
|
|
420
|
+
return Promise.reject(new TypeError('The definition must contain an identifier'));
|
|
299
421
|
}
|
|
300
|
-
/**
|
|
301
|
-
* Builds a form component.
|
|
302
|
-
*
|
|
303
|
-
* @example
|
|
304
|
-
* const container = $('.my-container', $container);
|
|
305
|
-
*
|
|
306
|
-
* const config = {
|
|
307
|
-
* title: 'My fancy form',
|
|
308
|
-
* widgets: [{
|
|
309
|
-
* widget: widgetDefinitions.TEXTBOX
|
|
310
|
-
* uri: 'nickname',
|
|
311
|
-
* label: 'Name',
|
|
312
|
-
* required: true
|
|
313
|
-
* }, {
|
|
314
|
-
* widget: widgetDefinitions.TEXTAREA
|
|
315
|
-
* uri: 'comment',
|
|
316
|
-
* label: 'Comment',
|
|
317
|
-
* required: true
|
|
318
|
-
* }],
|
|
319
|
-
* buttons = [{
|
|
320
|
-
* id: 'publish',
|
|
321
|
-
* label: 'Publish',
|
|
322
|
-
* icon: 'save
|
|
323
|
-
* }]
|
|
324
|
-
* };
|
|
325
|
-
*
|
|
326
|
-
* const form = formFactory(container, config)
|
|
327
|
-
* .on('button-publish', () => {
|
|
328
|
-
* this.submit()
|
|
329
|
-
* .then(values => dataProvider('comment').send(values))
|
|
330
|
-
* .catch(reason => feedback().error('Invalid input!'))
|
|
331
|
-
* });
|
|
332
|
-
*
|
|
333
|
-
* @param {HTMLElement|String} container
|
|
334
|
-
* @param {formConfig} config
|
|
335
|
-
* @param {String} [config.title] - An optional title for the form (default none)
|
|
336
|
-
* @param {String} [config.formAction] - The url the form is targeting (default '')
|
|
337
|
-
* @param {String} [config.formMethod] - The HTTP method the form should use (default '')
|
|
338
|
-
* @param {widgetConfig[]} [config.widgets] - The list of widgets to set in the form (default none)
|
|
339
|
-
* @param {buttonConfig[]} [config.buttons] - The list of buttons to set in the form (default none)
|
|
340
|
-
* @param {Object} [config.values] - Initial values for the widgets
|
|
341
|
-
* @param {Object} [config.ranges] - An optional list of ranges for the widgets (@see widgetConfig.range)
|
|
342
|
-
* @returns {form}
|
|
343
|
-
* @fires ready - When the component is ready to work
|
|
344
|
-
*/
|
|
345
422
|
|
|
423
|
+
return waitForRender(component);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Builds a form component.
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* const container = $('.my-container', $container);
|
|
430
|
+
*
|
|
431
|
+
* const config = {
|
|
432
|
+
* title: 'My fancy form',
|
|
433
|
+
* widgets: [{
|
|
434
|
+
* widget: widgetDefinitions.TEXTBOX
|
|
435
|
+
* uri: 'nickname',
|
|
436
|
+
* label: 'Name',
|
|
437
|
+
* required: true
|
|
438
|
+
* }, {
|
|
439
|
+
* widget: widgetDefinitions.TEXTAREA
|
|
440
|
+
* uri: 'comment',
|
|
441
|
+
* label: 'Comment',
|
|
442
|
+
* required: true
|
|
443
|
+
* }],
|
|
444
|
+
* buttons = [{
|
|
445
|
+
* id: 'publish',
|
|
446
|
+
* label: 'Publish',
|
|
447
|
+
* icon: 'save
|
|
448
|
+
* }]
|
|
449
|
+
* };
|
|
450
|
+
*
|
|
451
|
+
* const form = formFactory(container, config)
|
|
452
|
+
* .on('button-publish', () => {
|
|
453
|
+
* this.submit()
|
|
454
|
+
* .then(values => dataProvider('comment').send(values))
|
|
455
|
+
* .catch(reason => feedback().error('Invalid input!'))
|
|
456
|
+
* });
|
|
457
|
+
*
|
|
458
|
+
* @param {HTMLElement|String} container
|
|
459
|
+
* @param {formConfig} config
|
|
460
|
+
* @param {String} [config.title] - An optional title for the form (default none)
|
|
461
|
+
* @param {String} [config.formAction] - The url the form is targeting (default '')
|
|
462
|
+
* @param {String} [config.formMethod] - The HTTP method the form should use (default '')
|
|
463
|
+
* @param {widgetConfig[]} [config.widgets] - The list of widgets to set in the form (default none)
|
|
464
|
+
* @param {buttonConfig[]} [config.buttons] - The list of buttons to set in the form (default none)
|
|
465
|
+
* @param {Object} [config.values] - Initial values for the widgets
|
|
466
|
+
* @param {Object} [config.ranges] - An optional list of ranges for the widgets (@see widgetConfig.range)
|
|
467
|
+
* @returns {form}
|
|
468
|
+
* @fires ready - When the component is ready to work
|
|
469
|
+
*/
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
function formFactory(container, config) {
|
|
473
|
+
var widgets = new Map();
|
|
474
|
+
var buttons = new Map();
|
|
475
|
+
var controls = null;
|
|
476
|
+
var api = {
|
|
477
|
+
/**
|
|
478
|
+
* Gets the url the form is targeting.
|
|
479
|
+
* @returns {String}
|
|
480
|
+
*/
|
|
481
|
+
getFormAction: function getFormAction() {
|
|
482
|
+
return this.getConfig().formAction;
|
|
483
|
+
},
|
|
346
484
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
* @returns {String}
|
|
355
|
-
*/
|
|
356
|
-
getFormAction() {
|
|
357
|
-
return this.getConfig().formAction;
|
|
358
|
-
},
|
|
485
|
+
/**
|
|
486
|
+
* Gets the HTTP method the form should use.
|
|
487
|
+
* @returns {String}
|
|
488
|
+
*/
|
|
489
|
+
getFormMethod: function getFormMethod() {
|
|
490
|
+
return this.getConfig().formMethod;
|
|
491
|
+
},
|
|
359
492
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
493
|
+
/**
|
|
494
|
+
* Gets access to the ranges set for the widgets (generis related)
|
|
495
|
+
* @returns {Object}
|
|
496
|
+
*/
|
|
497
|
+
getRanges: function getRanges() {
|
|
498
|
+
return this.getConfig().ranges || {};
|
|
499
|
+
},
|
|
367
500
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
501
|
+
/**
|
|
502
|
+
* Gets the title set to the form.
|
|
503
|
+
* @returns {String}
|
|
504
|
+
*/
|
|
505
|
+
getTitle: function getTitle() {
|
|
506
|
+
return this.getConfig().title;
|
|
507
|
+
},
|
|
375
508
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
509
|
+
/**
|
|
510
|
+
* Change the title of the form
|
|
511
|
+
* @param {String} title
|
|
512
|
+
* @returns {form}
|
|
513
|
+
* @fires titlechange after the title has been changed
|
|
514
|
+
*/
|
|
515
|
+
setTitle: function setTitle(title) {
|
|
516
|
+
this.getConfig().title = title;
|
|
383
517
|
|
|
518
|
+
if (this.is('rendered')) {
|
|
519
|
+
controls.$title.text(title);
|
|
520
|
+
hider.toggle(controls.$title, !!title);
|
|
521
|
+
}
|
|
384
522
|
/**
|
|
385
|
-
*
|
|
523
|
+
* @event titlechange
|
|
386
524
|
* @param {String} title
|
|
387
|
-
* @returns {form}
|
|
388
|
-
* @fires titlechange after the title has been changed
|
|
389
525
|
*/
|
|
390
|
-
setTitle(title) {
|
|
391
|
-
this.getConfig().title = title;
|
|
392
526
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
527
|
+
|
|
528
|
+
this.trigger('titlechange', title);
|
|
529
|
+
return this;
|
|
530
|
+
},
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Gets a widget by its uri
|
|
534
|
+
* @param {String} uri
|
|
535
|
+
* @returns {widgetForm}
|
|
536
|
+
*/
|
|
537
|
+
getWidget: function getWidget(uri) {
|
|
538
|
+
return widgets.get(uri) || null;
|
|
539
|
+
},
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Adds a widget to the form
|
|
543
|
+
* @param {widgetConfig} definition
|
|
544
|
+
* @returns {Promise<widgetForm>}
|
|
545
|
+
* @throws TypeError if the widget definition is invalid
|
|
546
|
+
* @fires change when the widget's value changes
|
|
547
|
+
* @fires change-<uri> when the widget's value changes
|
|
548
|
+
* @fires widgetadd after the widget has been added
|
|
549
|
+
*/
|
|
550
|
+
addWidget: function addWidget(definition) {
|
|
551
|
+
var _this = this;
|
|
552
|
+
|
|
553
|
+
return validateDefinition(this, definition, 'uri').then(function () {
|
|
554
|
+
var ranges = _this.getRanges();
|
|
555
|
+
|
|
556
|
+
if (definition.range && 'string' === typeof definition.range) {
|
|
557
|
+
definition.range = ranges[definition.range];
|
|
396
558
|
}
|
|
397
|
-
/**
|
|
398
|
-
* @event titlechange
|
|
399
|
-
* @param {String} title
|
|
400
|
-
*/
|
|
401
559
|
|
|
560
|
+
if (!definition.widget) {
|
|
561
|
+
definition.widget = widgetDefinitions.DEFAULT;
|
|
562
|
+
}
|
|
402
563
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
564
|
+
return new Promise(function (resolve) {
|
|
565
|
+
var widget = widgetFactory(controls.$widgets, definition);
|
|
566
|
+
widgets.set(definition.uri, widget);
|
|
567
|
+
widget.on('change.form', function (value) {
|
|
568
|
+
/**
|
|
569
|
+
* @event change
|
|
570
|
+
* @param {String} uri
|
|
571
|
+
* @param {String} value
|
|
572
|
+
*/
|
|
573
|
+
_this.trigger('change', definition.uri, value);
|
|
574
|
+
/**
|
|
575
|
+
* @event change-<uri>
|
|
576
|
+
* @param {String} value
|
|
577
|
+
*/
|
|
406
578
|
|
|
407
|
-
/**
|
|
408
|
-
* Gets a widget by its uri
|
|
409
|
-
* @param {String} uri
|
|
410
|
-
* @returns {widgetForm}
|
|
411
|
-
*/
|
|
412
|
-
getWidget(uri) {
|
|
413
|
-
return widgets.get(uri) || null;
|
|
414
|
-
},
|
|
415
579
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
return validateDefinition(this, definition, 'uri').then(() => {
|
|
427
|
-
const ranges = this.getRanges();
|
|
428
|
-
|
|
429
|
-
if (definition.range && 'string' === typeof definition.range) {
|
|
430
|
-
definition.range = ranges[definition.range];
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
if (!definition.widget) {
|
|
434
|
-
definition.widget = widgetDefinitions.DEFAULT;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
return new Promise(resolve => {
|
|
438
|
-
const widget = widgetFactory(controls.$widgets, definition);
|
|
439
|
-
widgets.set(definition.uri, widget);
|
|
440
|
-
widget.on('change.form', value => {
|
|
441
|
-
/**
|
|
442
|
-
* @event change
|
|
443
|
-
* @param {String} uri
|
|
444
|
-
* @param {String} value
|
|
445
|
-
*/
|
|
446
|
-
this.trigger('change', definition.uri, value);
|
|
447
|
-
/**
|
|
448
|
-
* @event change-<uri>
|
|
449
|
-
* @param {String} value
|
|
450
|
-
*/
|
|
451
|
-
|
|
452
|
-
this.trigger(`change-${definition.uri}`, value);
|
|
453
|
-
}).on('ready.form', () => {
|
|
454
|
-
/**
|
|
455
|
-
* @event widgetadd
|
|
456
|
-
* @param {String} uri
|
|
457
|
-
* @param {widgetForm} widget
|
|
458
|
-
*/
|
|
459
|
-
this.trigger('widgetadd', definition.uri, widget);
|
|
460
|
-
resolve(widget);
|
|
461
|
-
});
|
|
580
|
+
_this.trigger("change-".concat(definition.uri), value);
|
|
581
|
+
}).on('ready.form', function () {
|
|
582
|
+
/**
|
|
583
|
+
* @event widgetadd
|
|
584
|
+
* @param {String} uri
|
|
585
|
+
* @param {widgetForm} widget
|
|
586
|
+
*/
|
|
587
|
+
_this.trigger('widgetadd', definition.uri, widget);
|
|
588
|
+
|
|
589
|
+
resolve(widget);
|
|
462
590
|
});
|
|
463
591
|
});
|
|
464
|
-
}
|
|
592
|
+
});
|
|
593
|
+
},
|
|
465
594
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
595
|
+
/**
|
|
596
|
+
* Removes a widget
|
|
597
|
+
* @param {String} uri
|
|
598
|
+
* @returns {form}
|
|
599
|
+
* @fires widgetremove after the widget has been removed
|
|
600
|
+
*/
|
|
601
|
+
removeWidget: function removeWidget(uri) {
|
|
602
|
+
if (widgets.has(uri)) {
|
|
603
|
+
removeComponent(widgets, uri);
|
|
604
|
+
/**
|
|
605
|
+
* @event widgetremove
|
|
606
|
+
* @param {String} uri
|
|
607
|
+
*/
|
|
479
608
|
|
|
480
|
-
|
|
481
|
-
|
|
609
|
+
this.trigger('widgetremove', uri);
|
|
610
|
+
}
|
|
482
611
|
|
|
483
|
-
|
|
484
|
-
|
|
612
|
+
return this;
|
|
613
|
+
},
|
|
485
614
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
615
|
+
/**
|
|
616
|
+
* Gets the list of widgets.
|
|
617
|
+
* @returns {Object}
|
|
618
|
+
*/
|
|
619
|
+
getWidgets: function getWidgets() {
|
|
620
|
+
return getComponents(widgets);
|
|
621
|
+
},
|
|
493
622
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
return Promise.all(_.map(definitions, definition => this.addWidget(definition)));
|
|
502
|
-
},
|
|
623
|
+
/**
|
|
624
|
+
* Replace the widgets
|
|
625
|
+
* @param {widgetConfig[]} definitions
|
|
626
|
+
* @returns {Promise<widgetForm[]>}
|
|
627
|
+
*/
|
|
628
|
+
setWidgets: function setWidgets(definitions) {
|
|
629
|
+
var _this2 = this;
|
|
503
630
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
631
|
+
this.removeWidgets();
|
|
632
|
+
return Promise.all(_.map(definitions, function (definition) {
|
|
633
|
+
return _this2.addWidget(definition);
|
|
634
|
+
}));
|
|
635
|
+
},
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Removes all widgets
|
|
639
|
+
* @returns {form}
|
|
640
|
+
*/
|
|
641
|
+
removeWidgets: function removeWidgets() {
|
|
642
|
+
var _iterator4 = _createForOfIteratorHelper(widgets.keys()),
|
|
643
|
+
_step4;
|
|
644
|
+
|
|
645
|
+
try {
|
|
646
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
647
|
+
var uri = _step4.value;
|
|
510
648
|
this.removeWidget(uri);
|
|
511
649
|
}
|
|
650
|
+
} catch (err) {
|
|
651
|
+
_iterator4.e(err);
|
|
652
|
+
} finally {
|
|
653
|
+
_iterator4.f();
|
|
654
|
+
}
|
|
512
655
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
656
|
+
widgets.clear();
|
|
657
|
+
return this;
|
|
658
|
+
},
|
|
516
659
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
660
|
+
/**
|
|
661
|
+
* Gets a button by its identifier
|
|
662
|
+
* @param {String} id
|
|
663
|
+
* @returns {button}
|
|
664
|
+
*/
|
|
665
|
+
getButton: function getButton(id) {
|
|
666
|
+
return buttons.get(id) || null;
|
|
667
|
+
},
|
|
525
668
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
669
|
+
/**
|
|
670
|
+
* Adds a button to the form
|
|
671
|
+
* @param {buttonConfig} definition
|
|
672
|
+
* @returns {Promise<button>}
|
|
673
|
+
* @throws TypeError if the button definition is invalid
|
|
674
|
+
* @fires button when the button is triggered
|
|
675
|
+
* @fires button-<id> when the button is triggered
|
|
676
|
+
* @fires buttonadd after the button has been added
|
|
677
|
+
*/
|
|
678
|
+
addButton: function addButton(definition) {
|
|
679
|
+
var _this3 = this;
|
|
680
|
+
|
|
681
|
+
return validateDefinition(this, definition, 'id').then(function () {
|
|
682
|
+
return new Promise(function (resolve) {
|
|
683
|
+
var button = buttonFactory(definition);
|
|
538
684
|
buttons.set(definition.id, button);
|
|
539
|
-
button.on('click.form', ()
|
|
685
|
+
button.on('click.form', function () {
|
|
540
686
|
/**
|
|
541
687
|
* @event button
|
|
542
688
|
* @param {String} id
|
|
543
689
|
*/
|
|
544
|
-
|
|
690
|
+
_this3.trigger('button', definition.id);
|
|
545
691
|
/**
|
|
546
692
|
* @event button-<id>
|
|
547
693
|
*/
|
|
548
694
|
|
|
549
|
-
|
|
550
|
-
|
|
695
|
+
|
|
696
|
+
_this3.trigger("button-".concat(definition.id));
|
|
697
|
+
}).on('ready.form', function () {
|
|
551
698
|
/**
|
|
552
699
|
* @event buttonadd
|
|
553
700
|
* @param {String} id
|
|
554
701
|
* @param {button} button
|
|
555
702
|
*/
|
|
556
|
-
|
|
703
|
+
_this3.trigger('buttonadd', definition.id, button);
|
|
704
|
+
|
|
557
705
|
resolve(button);
|
|
558
706
|
});
|
|
559
707
|
button.render(controls.$buttons);
|
|
560
|
-
})
|
|
561
|
-
}
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
},
|
|
562
711
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
712
|
+
/**
|
|
713
|
+
* Removes a button
|
|
714
|
+
* @param {String} id
|
|
715
|
+
* @returns {form}
|
|
716
|
+
* @fires buttonremove after the button has been removed
|
|
717
|
+
*/
|
|
718
|
+
removeButton: function removeButton(id) {
|
|
719
|
+
if (buttons.has(id)) {
|
|
720
|
+
removeComponent(buttons, id);
|
|
721
|
+
/**
|
|
722
|
+
* @event buttonremove
|
|
723
|
+
* @param {String} id
|
|
724
|
+
*/
|
|
576
725
|
|
|
577
|
-
|
|
578
|
-
|
|
726
|
+
this.trigger('buttonremove', id);
|
|
727
|
+
}
|
|
579
728
|
|
|
580
|
-
|
|
581
|
-
|
|
729
|
+
return this;
|
|
730
|
+
},
|
|
582
731
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
732
|
+
/**
|
|
733
|
+
* Gets the list of buttons.
|
|
734
|
+
* @returns {Object}
|
|
735
|
+
*/
|
|
736
|
+
getButtons: function getButtons() {
|
|
737
|
+
return getComponents(buttons);
|
|
738
|
+
},
|
|
590
739
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
return Promise.all(_.map(definitions, definition => this.addButton(definition)));
|
|
599
|
-
},
|
|
740
|
+
/**
|
|
741
|
+
* Replace the buttons
|
|
742
|
+
* @param {buttonConfig[]} definitions
|
|
743
|
+
* @returns {Promise<button[]>}
|
|
744
|
+
*/
|
|
745
|
+
setButtons: function setButtons(definitions) {
|
|
746
|
+
var _this4 = this;
|
|
600
747
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
748
|
+
this.removeButtons();
|
|
749
|
+
return Promise.all(_.map(definitions, function (definition) {
|
|
750
|
+
return _this4.addButton(definition);
|
|
751
|
+
}));
|
|
752
|
+
},
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Removes all buttons
|
|
756
|
+
* @returns {form}
|
|
757
|
+
*/
|
|
758
|
+
removeButtons: function removeButtons() {
|
|
759
|
+
var _iterator5 = _createForOfIteratorHelper(buttons.keys()),
|
|
760
|
+
_step5;
|
|
761
|
+
|
|
762
|
+
try {
|
|
763
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
764
|
+
var id = _step5.value;
|
|
607
765
|
this.removeButton(id);
|
|
608
766
|
}
|
|
767
|
+
} catch (err) {
|
|
768
|
+
_iterator5.e(err);
|
|
769
|
+
} finally {
|
|
770
|
+
_iterator5.f();
|
|
771
|
+
}
|
|
609
772
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
773
|
+
buttons.clear();
|
|
774
|
+
return this;
|
|
775
|
+
},
|
|
613
776
|
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
777
|
+
/**
|
|
778
|
+
* Gets the value of a widget
|
|
779
|
+
* @param {String} uri
|
|
780
|
+
* @returns {String}
|
|
781
|
+
*/
|
|
782
|
+
getValue: function getValue(uri) {
|
|
783
|
+
if (widgets.has(uri)) {
|
|
784
|
+
return widgets.get(uri).getValue();
|
|
785
|
+
}
|
|
623
786
|
|
|
624
|
-
|
|
625
|
-
|
|
787
|
+
return '';
|
|
788
|
+
},
|
|
626
789
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
790
|
+
/**
|
|
791
|
+
* Sets the value of a widget
|
|
792
|
+
* @param {String} uri
|
|
793
|
+
* @param {String} value
|
|
794
|
+
* @returns {form}
|
|
795
|
+
*/
|
|
796
|
+
setValue: function setValue(uri, value) {
|
|
797
|
+
if (widgets.has(uri)) {
|
|
798
|
+
widgets.get(uri).setValue(value);
|
|
799
|
+
}
|
|
637
800
|
|
|
638
|
-
|
|
639
|
-
|
|
801
|
+
return this;
|
|
802
|
+
},
|
|
640
803
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
804
|
+
/**
|
|
805
|
+
* Gets the values from all the form widgets
|
|
806
|
+
* @returns {Object}
|
|
807
|
+
*/
|
|
808
|
+
getValues: function getValues() {
|
|
809
|
+
var values = {};
|
|
810
|
+
|
|
811
|
+
var _iterator6 = _createForOfIteratorHelper(widgets),
|
|
812
|
+
_step6;
|
|
813
|
+
|
|
814
|
+
try {
|
|
815
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
816
|
+
var _step6$value = _slicedToArray(_step6.value, 2),
|
|
817
|
+
uri = _step6$value[0],
|
|
818
|
+
widget = _step6$value[1];
|
|
647
819
|
|
|
648
|
-
for (let [uri, widget] of widgets) {
|
|
649
820
|
values[uri] = widget.getValue();
|
|
650
821
|
}
|
|
822
|
+
} catch (err) {
|
|
823
|
+
_iterator6.e(err);
|
|
824
|
+
} finally {
|
|
825
|
+
_iterator6.f();
|
|
826
|
+
}
|
|
651
827
|
|
|
652
|
-
|
|
653
|
-
|
|
828
|
+
return values;
|
|
829
|
+
},
|
|
654
830
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
831
|
+
/**
|
|
832
|
+
* Sets the values for the form widgets
|
|
833
|
+
* @param {Object} values
|
|
834
|
+
* @returns {form}
|
|
835
|
+
*/
|
|
836
|
+
setValues: function setValues(values) {
|
|
837
|
+
_.forEach(values, function (value, uri) {
|
|
838
|
+
if (widgets.has(uri)) {
|
|
839
|
+
widgets.get(uri).setValue(value);
|
|
840
|
+
}
|
|
841
|
+
});
|
|
666
842
|
|
|
667
|
-
|
|
668
|
-
|
|
843
|
+
return this;
|
|
844
|
+
},
|
|
669
845
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
846
|
+
/**
|
|
847
|
+
* Serializes form values to an array of name/value objects
|
|
848
|
+
* @returns {widgetValue[]}
|
|
849
|
+
*/
|
|
850
|
+
serializeValues: function serializeValues() {
|
|
851
|
+
var values = [];
|
|
852
|
+
|
|
853
|
+
var _iterator7 = _createForOfIteratorHelper(widgets.values()),
|
|
854
|
+
_step7;
|
|
676
855
|
|
|
677
|
-
|
|
856
|
+
try {
|
|
857
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
858
|
+
var widget = _step7.value;
|
|
678
859
|
values.push({
|
|
679
860
|
name: widget.getUri(),
|
|
680
861
|
value: widget.getValue()
|
|
681
862
|
});
|
|
682
863
|
}
|
|
864
|
+
} catch (err) {
|
|
865
|
+
_iterator7.e(err);
|
|
866
|
+
} finally {
|
|
867
|
+
_iterator7.f();
|
|
868
|
+
}
|
|
683
869
|
|
|
684
|
-
|
|
685
|
-
|
|
870
|
+
return values;
|
|
871
|
+
},
|
|
686
872
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
873
|
+
/**
|
|
874
|
+
* Validate the form widgets
|
|
875
|
+
* @returns {Promise}
|
|
876
|
+
*/
|
|
877
|
+
validate: function validate() {
|
|
878
|
+
var _this5 = this;
|
|
879
|
+
|
|
880
|
+
var promises = [];
|
|
881
|
+
|
|
882
|
+
var _iterator8 = _createForOfIteratorHelper(widgets),
|
|
883
|
+
_step8;
|
|
884
|
+
|
|
885
|
+
try {
|
|
886
|
+
var _loop = function _loop() {
|
|
887
|
+
var _step8$value = _slicedToArray(_step8.value, 2),
|
|
888
|
+
uri = _step8$value[0],
|
|
889
|
+
widget = _step8$value[1];
|
|
890
|
+
|
|
891
|
+
promises.push(widget.validate().catch(function (messages) {
|
|
892
|
+
return Promise.resolve({
|
|
893
|
+
uri: uri,
|
|
894
|
+
messages: messages
|
|
895
|
+
});
|
|
896
|
+
}));
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
900
|
+
_loop();
|
|
699
901
|
}
|
|
902
|
+
} catch (err) {
|
|
903
|
+
_iterator8.e(err);
|
|
904
|
+
} finally {
|
|
905
|
+
_iterator8.f();
|
|
906
|
+
}
|
|
700
907
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
908
|
+
return Promise.all(promises).then(function (result) {
|
|
909
|
+
var invalid = false;
|
|
910
|
+
result = _.compact(result);
|
|
704
911
|
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
912
|
+
if (result.length) {
|
|
913
|
+
result = Promise.reject(result);
|
|
914
|
+
invalid = true;
|
|
915
|
+
}
|
|
709
916
|
|
|
710
|
-
|
|
711
|
-
return result;
|
|
712
|
-
});
|
|
713
|
-
},
|
|
917
|
+
_this5.setState('invalid', invalid);
|
|
714
918
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
919
|
+
return result;
|
|
920
|
+
});
|
|
921
|
+
},
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Submits the form
|
|
925
|
+
* @returns {form}
|
|
926
|
+
* @fires submit in case of successful validation
|
|
927
|
+
* @fires invalid in case of failed validation
|
|
928
|
+
* @fires error when an error is raised
|
|
929
|
+
*/
|
|
930
|
+
submit: function submit() {
|
|
931
|
+
var _this6 = this;
|
|
932
|
+
|
|
933
|
+
this.validate().then(function () {
|
|
934
|
+
/**
|
|
935
|
+
* @event submit
|
|
936
|
+
* @param {widgetValue[]} values
|
|
937
|
+
*/
|
|
938
|
+
_this6.trigger('submit', _this6.serializeValues());
|
|
939
|
+
}).catch(function (reason) {
|
|
940
|
+
/**
|
|
941
|
+
* @event invalid
|
|
942
|
+
* @param {Object} reason
|
|
943
|
+
*/
|
|
944
|
+
_this6.trigger('invalid', reason);
|
|
945
|
+
|
|
946
|
+
if (reason instanceof Error) {
|
|
730
947
|
/**
|
|
731
|
-
* @event
|
|
732
|
-
* @param {
|
|
948
|
+
* @event error
|
|
949
|
+
* @param {Error} err
|
|
733
950
|
*/
|
|
734
|
-
|
|
951
|
+
_this6.trigger('error', reason);
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
return this;
|
|
955
|
+
},
|
|
735
956
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
return this;
|
|
745
|
-
},
|
|
957
|
+
/**
|
|
958
|
+
* Resets the form
|
|
959
|
+
* @returns {form}
|
|
960
|
+
* @fires reset
|
|
961
|
+
*/
|
|
962
|
+
reset: function reset() {
|
|
963
|
+
var _iterator9 = _createForOfIteratorHelper(widgets.values()),
|
|
964
|
+
_step9;
|
|
746
965
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
* @fires reset
|
|
751
|
-
*/
|
|
752
|
-
reset() {
|
|
753
|
-
for (let widget of widgets.values()) {
|
|
966
|
+
try {
|
|
967
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
968
|
+
var widget = _step9.value;
|
|
754
969
|
widget.reset();
|
|
755
970
|
}
|
|
756
971
|
/**
|
|
757
972
|
* @event reset
|
|
758
973
|
*/
|
|
759
974
|
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
975
|
+
} catch (err) {
|
|
976
|
+
_iterator9.e(err);
|
|
977
|
+
} finally {
|
|
978
|
+
_iterator9.f();
|
|
763
979
|
}
|
|
764
980
|
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
981
|
+
this.trigger('reset');
|
|
982
|
+
return this;
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
var form = componentFactory(api, defaults) // set the component's layout
|
|
986
|
+
.setTemplate(formTpl) // auto render on init
|
|
987
|
+
.on('init', function onFormInit() {
|
|
988
|
+
var _this7 = this;
|
|
989
|
+
|
|
990
|
+
// auto render on init (defer the call to give a chance to the init event to be completed before)
|
|
991
|
+
_.defer(function () {
|
|
992
|
+
return _this7.render(container);
|
|
993
|
+
});
|
|
994
|
+
}) // renders the component
|
|
995
|
+
.on('render', function onFormRender() {
|
|
996
|
+
var _this8 = this;
|
|
997
|
+
|
|
998
|
+
var $element = this.getElement();
|
|
999
|
+
var initConfig = this.getConfig();
|
|
1000
|
+
var initPromises = [];
|
|
1001
|
+
controls = {
|
|
1002
|
+
$title: $element.find('.form-title'),
|
|
1003
|
+
$form: $element.find('form'),
|
|
1004
|
+
$widgets: $element.find('fieldset'),
|
|
1005
|
+
$buttons: $element.find('.form-actions')
|
|
1006
|
+
}; // prevent the default behavior of the form for submitting
|
|
1007
|
+
|
|
1008
|
+
controls.$form.on('submit', function (e) {
|
|
1009
|
+
e.preventDefault();
|
|
1010
|
+
|
|
1011
|
+
_this8.submit();
|
|
1012
|
+
});
|
|
1013
|
+
controls.$form.on('reset', function (e) {
|
|
1014
|
+
e.preventDefault();
|
|
797
1015
|
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
}
|
|
1016
|
+
_this8.reset();
|
|
1017
|
+
}); // hide the title if empty
|
|
801
1018
|
|
|
802
|
-
|
|
803
|
-
if (_.size(initConfig.values)) {
|
|
804
|
-
this.setValues(initConfig.values);
|
|
805
|
-
}
|
|
806
|
-
}).catch(err => {
|
|
807
|
-
this.trigger('error', err);
|
|
808
|
-
}).then(() => {
|
|
809
|
-
/**
|
|
810
|
-
* @event ready
|
|
811
|
-
*/
|
|
812
|
-
this.trigger('ready');
|
|
813
|
-
});
|
|
814
|
-
}) // take care of the disable state
|
|
815
|
-
.on('disable', () => {
|
|
816
|
-
disableComponents(widgets);
|
|
817
|
-
disableComponents(buttons);
|
|
818
|
-
}).on('enable', () => {
|
|
819
|
-
enableComponents(widgets);
|
|
820
|
-
enableComponents(buttons);
|
|
821
|
-
}) // cleanup the place
|
|
822
|
-
.on('destroy', function onFormDestroy() {
|
|
823
|
-
this.removeButtons();
|
|
824
|
-
this.removeWidgets();
|
|
825
|
-
controls = null;
|
|
826
|
-
}); // initialize the component with the provided config
|
|
827
|
-
// defer the call to allow to listen to the init event
|
|
1019
|
+
hider.toggle(controls.$title, !!initConfig.title); // initial widgets and buttons
|
|
828
1020
|
|
|
829
|
-
_.
|
|
1021
|
+
if (_.size(initConfig.widgets)) {
|
|
1022
|
+
initPromises.push(this.setWidgets(initConfig.widgets));
|
|
1023
|
+
}
|
|
830
1024
|
|
|
831
|
-
|
|
832
|
-
|
|
1025
|
+
if (_.size(initConfig.buttons)) {
|
|
1026
|
+
initPromises.push(this.setButtons(initConfig.buttons));
|
|
1027
|
+
}
|
|
833
1028
|
|
|
834
|
-
|
|
1029
|
+
Promise.all(initPromises).then(function () {
|
|
1030
|
+
if (_.size(initConfig.values)) {
|
|
1031
|
+
_this8.setValues(initConfig.values);
|
|
1032
|
+
}
|
|
1033
|
+
}).catch(function (err) {
|
|
1034
|
+
_this8.trigger('error', err);
|
|
1035
|
+
}).then(function () {
|
|
1036
|
+
/**
|
|
1037
|
+
* @event ready
|
|
1038
|
+
*/
|
|
1039
|
+
_this8.trigger('ready');
|
|
1040
|
+
});
|
|
1041
|
+
}) // take care of the disable state
|
|
1042
|
+
.on('disable', function () {
|
|
1043
|
+
disableComponents(widgets);
|
|
1044
|
+
disableComponents(buttons);
|
|
1045
|
+
}).on('enable', function () {
|
|
1046
|
+
enableComponents(widgets);
|
|
1047
|
+
enableComponents(buttons);
|
|
1048
|
+
}) // cleanup the place
|
|
1049
|
+
.on('destroy', function onFormDestroy() {
|
|
1050
|
+
this.removeButtons();
|
|
1051
|
+
this.removeWidgets();
|
|
1052
|
+
controls = null;
|
|
1053
|
+
}); // initialize the component with the provided config
|
|
1054
|
+
// defer the call to allow to listen to the init event
|
|
1055
|
+
|
|
1056
|
+
_.defer(function () {
|
|
1057
|
+
return form.init(config);
|
|
1058
|
+
});
|
|
1059
|
+
|
|
1060
|
+
return form;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
return formFactory;
|
|
835
1064
|
|
|
836
1065
|
});
|