@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
|
@@ -1,565 +1,563 @@
|
|
|
1
1
|
define(['lodash', 'i18n', 'handlebars', 'core/providerRegistry', 'ui/component', 'ui/form/validator/validator', 'ui/form/validator/renderer', 'ui/form/widget/providers/default', 'lib/dompurify/purify', 'css!ui/form/widget/css/widget.css'], function (_, __, Handlebars, providerRegistry, componentFactory, validatorFactory, validatorRendererFactory, defaultProvider, DOMPurify, widget_css) { 'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
_ = _ && Object.prototype.hasOwnProperty.call(_, 'default') ? _['default'] : _;
|
|
4
|
+
__ = __ && Object.prototype.hasOwnProperty.call(__, 'default') ? __['default'] : __;
|
|
5
|
+
Handlebars = Handlebars && Object.prototype.hasOwnProperty.call(Handlebars, 'default') ? Handlebars['default'] : Handlebars;
|
|
6
|
+
providerRegistry = providerRegistry && Object.prototype.hasOwnProperty.call(providerRegistry, 'default') ? providerRegistry['default'] : providerRegistry;
|
|
7
|
+
componentFactory = componentFactory && Object.prototype.hasOwnProperty.call(componentFactory, 'default') ? componentFactory['default'] : componentFactory;
|
|
8
|
+
validatorFactory = validatorFactory && Object.prototype.hasOwnProperty.call(validatorFactory, 'default') ? validatorFactory['default'] : validatorFactory;
|
|
9
|
+
validatorRendererFactory = validatorRendererFactory && Object.prototype.hasOwnProperty.call(validatorRendererFactory, 'default') ? validatorRendererFactory['default'] : validatorRendererFactory;
|
|
10
|
+
defaultProvider = defaultProvider && Object.prototype.hasOwnProperty.call(defaultProvider, 'default') ? defaultProvider['default'] : defaultProvider;
|
|
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 Helpers0 (hb) {
|
|
24
|
+
//register a i18n helper
|
|
25
|
+
hb.registerHelper('__', function (key) {
|
|
26
|
+
return __(key);
|
|
27
|
+
});
|
|
13
28
|
/**
|
|
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);
|
|
29
|
-
*
|
|
29
|
+
* Register dompurify helper
|
|
30
30
|
*
|
|
31
|
+
* https://github.com/cure53/DOMPurify
|
|
32
|
+
* with config SAFE_FOR_TEMPLATES: true
|
|
33
|
+
* to make output safe for template systems
|
|
31
34
|
*/
|
|
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
35
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
hb.registerHelper('dompurify', function (context) {
|
|
37
|
+
return DOMPurify.sanitize(context);
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Register join helper
|
|
41
|
+
*
|
|
42
|
+
* Example :
|
|
43
|
+
* var values = {a:v1, b:v2, c:v3};
|
|
44
|
+
* Using {{{join attributes '=' ' ' '"'}}} will return : a="v1" b="v2" c="v3"
|
|
45
|
+
* Using {{{join values null ' or ' '*'}}} will return : *v1* or *v2* or *v3*
|
|
46
|
+
*/
|
|
56
47
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
hb.registerHelper('join', function (arr, keyValueGlue, fragmentGlue, wrapper) {
|
|
49
|
+
var fragments = [];
|
|
50
|
+
keyValueGlue = typeof keyValueGlue === 'string' ? keyValueGlue : undefined;
|
|
51
|
+
fragmentGlue = typeof fragmentGlue === 'string' ? fragmentGlue : ' ';
|
|
52
|
+
wrapper = typeof wrapper === 'string' ? wrapper : '"';
|
|
62
53
|
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
_.forIn(arr, function (value, key) {
|
|
55
|
+
var fragment = '';
|
|
65
56
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
value = '';
|
|
57
|
+
if (value !== null || value !== undefined) {
|
|
58
|
+
if (typeof value === 'boolean') {
|
|
59
|
+
value = value ? 'true' : 'false';
|
|
60
|
+
} else if (_typeof(value) === 'object') {
|
|
61
|
+
value = _.values(value).join(' ');
|
|
74
62
|
}
|
|
63
|
+
} else {
|
|
64
|
+
value = '';
|
|
65
|
+
}
|
|
75
66
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
if (keyValueGlue !== undefined) {
|
|
68
|
+
fragment += key + keyValueGlue;
|
|
69
|
+
}
|
|
79
70
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
fragment += wrapper + value + wrapper;
|
|
72
|
+
fragments.push(fragment);
|
|
73
|
+
});
|
|
83
74
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
return fragments.join(fragmentGlue);
|
|
76
|
+
}); //register a classic "for loop" helper
|
|
77
|
+
//it also adds a local variable "i" as the index in each iteration loop
|
|
87
78
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
79
|
+
hb.registerHelper('for', function (startIndex, stopIndex, increment, options) {
|
|
80
|
+
var ret = '';
|
|
81
|
+
startIndex = parseInt(startIndex);
|
|
82
|
+
stopIndex = parseInt(stopIndex);
|
|
83
|
+
increment = parseInt(increment);
|
|
93
84
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
85
|
+
for (var i = startIndex; i < stopIndex; i += increment) {
|
|
86
|
+
ret += options.fn(_.extend({}, this, {
|
|
87
|
+
i: i
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
99
90
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
91
|
+
return ret;
|
|
92
|
+
});
|
|
93
|
+
hb.registerHelper('equal', function (var1, var2, options) {
|
|
94
|
+
if (var1 == var2) {
|
|
95
|
+
return options.fn(this);
|
|
96
|
+
} else {
|
|
97
|
+
return options.inverse(this);
|
|
98
|
+
}
|
|
99
|
+
}); // register a "get property" helper
|
|
100
|
+
// it gets the named property from the provided context
|
|
110
101
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
102
|
+
hb.registerHelper('property', function (name, context) {
|
|
103
|
+
return context[name] || '';
|
|
104
|
+
}); // register an 'includes' helper
|
|
105
|
+
// it checks if value is in array
|
|
115
106
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
107
|
+
hb.registerHelper('includes', function (haystack, needle, options) {
|
|
108
|
+
if (_.contains(haystack, needle)) {
|
|
109
|
+
return options.fn(this);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!Helpers0.__initialized) {
|
|
115
|
+
Helpers0(Handlebars);
|
|
116
|
+
Helpers0.__initialized = true;
|
|
117
|
+
}
|
|
118
|
+
var Template = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
|
|
119
|
+
this.compilerInfo = [4,'>= 1.0.0'];
|
|
120
|
+
helpers = this.merge(helpers, Handlebars.helpers); partials = this.merge(partials, Handlebars.partials); data = data || {};
|
|
121
|
+
var buffer = "", stack1, helper, functionType="function", escapeExpression=this.escapeExpression, self=this;
|
|
122
|
+
|
|
123
|
+
function program1(depth0,data) {
|
|
124
|
+
|
|
125
|
+
var buffer = "", stack1, helper;
|
|
126
|
+
buffer += "type=\"";
|
|
127
|
+
if (helper = helpers.type) { stack1 = helper.call(depth0, {hash:{},data:data}); }
|
|
128
|
+
else { helper = (depth0 && depth0.type); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
|
|
129
|
+
buffer += escapeExpression(stack1)
|
|
130
|
+
+ "\" ";
|
|
131
|
+
return buffer;
|
|
121
132
|
}
|
|
122
133
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
134
|
+
buffer += "<div class=\"form-widget ";
|
|
135
|
+
if (helper = helpers.widgetType) { stack1 = helper.call(depth0, {hash:{},data:data}); }
|
|
136
|
+
else { helper = (depth0 && depth0.widgetType); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
|
|
137
|
+
buffer += escapeExpression(stack1)
|
|
138
|
+
+ "\">\n <div class=\"widget-label\">\n ";
|
|
139
|
+
stack1 = self.invokePartial(partials['ui-form-widget-label'], 'ui-form-widget-label', depth0, helpers, partials, data);
|
|
140
|
+
if(stack1 || stack1 === 0) { buffer += stack1; }
|
|
141
|
+
buffer += "\n </div>\n <div class=\"widget-field\">\n <input class=\"widget-input-inline\" ";
|
|
142
|
+
stack1 = helpers['if'].call(depth0, (depth0 && depth0.type), {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
|
|
143
|
+
if(stack1 || stack1 === 0) { buffer += stack1; }
|
|
144
|
+
buffer += "name=\"";
|
|
145
|
+
if (helper = helpers.uri) { stack1 = helper.call(depth0, {hash:{},data:data}); }
|
|
146
|
+
else { helper = (depth0 && depth0.uri); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
|
|
147
|
+
buffer += escapeExpression(stack1)
|
|
148
|
+
+ "\" value=\"";
|
|
149
|
+
if (helper = helpers.value) { stack1 = helper.call(depth0, {hash:{},data:data}); }
|
|
150
|
+
else { helper = (depth0 && depth0.value); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
|
|
151
|
+
buffer += escapeExpression(stack1)
|
|
152
|
+
+ "\" />\n </div>\n</div>\n";
|
|
153
|
+
return buffer;
|
|
154
|
+
});
|
|
155
|
+
function widgetTpl(data, options, asString) {
|
|
156
|
+
var html = Template(data, options);
|
|
157
|
+
return (asString || true) ? html : $(html);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (!Helpers0.__initialized) {
|
|
161
|
+
Helpers0(Handlebars);
|
|
162
|
+
Helpers0.__initialized = true;
|
|
163
|
+
}
|
|
164
|
+
var Template$1 = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
|
|
165
|
+
this.compilerInfo = [4,'>= 1.0.0'];
|
|
166
|
+
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|
167
|
+
var buffer = "", stack1, helper, helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, functionType="function", self=this;
|
|
168
|
+
|
|
169
|
+
function program1(depth0,data) {
|
|
170
|
+
|
|
171
|
+
var buffer = "", helper, options;
|
|
172
|
+
buffer += "\n <abbr title=\""
|
|
173
|
+
+ escapeExpression((helper = helpers.__ || (depth0 && depth0.__),options={hash:{},data:data},helper ? helper.call(depth0, "This field is required", options) : helperMissing.call(depth0, "__", "This field is required", options)))
|
|
174
|
+
+ "\">*</abbr>\n ";
|
|
175
|
+
return buffer;
|
|
126
176
|
}
|
|
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); partials = this.merge(partials, Handlebars.partials); 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 += "type=\"";
|
|
136
|
-
if (helper = helpers.type) { stack1 = helper.call(depth0, {hash:{},data:data}); }
|
|
137
|
-
else { helper = (depth0 && depth0.type); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
|
|
138
|
-
buffer += escapeExpression(stack1)
|
|
139
|
-
+ "\" ";
|
|
140
|
-
return buffer;
|
|
141
|
-
}
|
|
142
177
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
178
|
+
buffer += "<label for=\"";
|
|
179
|
+
if (helper = helpers.uri) { stack1 = helper.call(depth0, {hash:{},data:data}); }
|
|
180
|
+
else { helper = (depth0 && depth0.uri); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
|
|
181
|
+
buffer += escapeExpression(stack1)
|
|
182
|
+
+ "\">\n ";
|
|
183
|
+
if (helper = helpers.label) { stack1 = helper.call(depth0, {hash:{},data:data}); }
|
|
184
|
+
else { helper = (depth0 && depth0.label); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
|
|
185
|
+
buffer += escapeExpression(stack1)
|
|
186
|
+
+ "\n ";
|
|
187
|
+
stack1 = helpers['if'].call(depth0, (depth0 && depth0.required), {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
|
|
188
|
+
if(stack1 || stack1 === 0) { buffer += stack1; }
|
|
189
|
+
buffer += "\n</label>\n";
|
|
190
|
+
return buffer;
|
|
191
|
+
});
|
|
192
|
+
function labelTpl(data, options, asString) {
|
|
193
|
+
var html = Template$1(data, options);
|
|
194
|
+
return (asString || true) ? html : $(html);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* This program is free software; you can redistribute it and/or
|
|
199
|
+
* modify it under the terms of the GNU General Public License
|
|
200
|
+
* as published by the Free Software Foundation; under version 2
|
|
201
|
+
* of the License (non-upgradable).
|
|
202
|
+
*
|
|
203
|
+
* This program is distributed in the hope that it will be useful,
|
|
204
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
205
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
206
|
+
* GNU General Public License for more details.
|
|
207
|
+
*
|
|
208
|
+
* You should have received a copy of the GNU General Public License
|
|
209
|
+
* along with this program; if not, write to the Free Software
|
|
210
|
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
211
|
+
*
|
|
212
|
+
* Copyright (c) 2019 Open Assessment Technologies SA ;
|
|
213
|
+
*/
|
|
214
|
+
/**
|
|
215
|
+
* @typedef {Object} widgetConfig Defines the config entries available to setup a form widget
|
|
216
|
+
* @property {String} widget - The type of widget.
|
|
217
|
+
* It will be used by the main factory to retrieve
|
|
218
|
+
* the implementation from the internal registry.
|
|
219
|
+
* @property {String} widgetType - The internal type of widget
|
|
220
|
+
* @property {String} uri - The identifier of the widget
|
|
221
|
+
* @property {String} [label] - The label of the widget
|
|
222
|
+
* @property {String|String[]} [value] - The value of the widget. Depending on the widget's type,
|
|
223
|
+
* it can be a single or a multiple value
|
|
224
|
+
* @property {widgetRangeValue[]} [range] - Array of values used in multi-elements widgets (like combo or checkbox)
|
|
225
|
+
* @property {Boolean} [required] - Tells if the value is required
|
|
226
|
+
* @property {validationRule|validationRule[]|validator} [validation] - Optional validators to add
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @typedef {Object} widgetRangeValue Defines a value to use in a widget range
|
|
231
|
+
* @property {String} uri - The identifier of the value
|
|
232
|
+
* @property {String} label - The label for the value
|
|
233
|
+
*/
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Some default config
|
|
237
|
+
* @type {widgetConfig}
|
|
238
|
+
*/
|
|
239
|
+
|
|
240
|
+
var defaults = {
|
|
241
|
+
widgetType: 'input-box',
|
|
242
|
+
required: false,
|
|
243
|
+
label: __('Label'),
|
|
244
|
+
value: '',
|
|
245
|
+
range: []
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Gets the provider with respect to the provided config
|
|
249
|
+
* @param {widgetConfig} config
|
|
250
|
+
* @returns {Object}
|
|
251
|
+
* @throws {TypeError} if the config is not valid or if the provider does not exist
|
|
252
|
+
*/
|
|
253
|
+
|
|
254
|
+
function getWidgetProvider(config) {
|
|
255
|
+
if (!_.isPlainObject(config)) {
|
|
256
|
+
throw new TypeError('The config must be an object');
|
|
167
257
|
}
|
|
168
258
|
|
|
169
|
-
if (!
|
|
170
|
-
|
|
171
|
-
Helpers0.__initialized = true;
|
|
259
|
+
if (!_.isString(config.uri) || !config.uri) {
|
|
260
|
+
throw new TypeError('The config must contain an uri');
|
|
172
261
|
}
|
|
173
|
-
var Template$1 = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
|
|
174
|
-
this.compilerInfo = [4,'>= 1.0.0'];
|
|
175
|
-
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
|
176
|
-
var buffer = "", stack1, helper, helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, functionType="function", self=this;
|
|
177
|
-
|
|
178
|
-
function program1(depth0,data) {
|
|
179
|
-
|
|
180
|
-
var buffer = "", helper, options;
|
|
181
|
-
buffer += "\n <abbr title=\""
|
|
182
|
-
+ escapeExpression((helper = helpers.__ || (depth0 && depth0.__),options={hash:{},data:data},helper ? helper.call(depth0, "This field is required", options) : helperMissing.call(depth0, "__", "This field is required", options)))
|
|
183
|
-
+ "\">*</abbr>\n ";
|
|
184
|
-
return buffer;
|
|
185
|
-
}
|
|
186
262
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
else { helper = (depth0 && depth0.uri); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
|
|
190
|
-
buffer += escapeExpression(stack1)
|
|
191
|
-
+ "\">\n ";
|
|
192
|
-
if (helper = helpers.label) { stack1 = helper.call(depth0, {hash:{},data:data}); }
|
|
193
|
-
else { helper = (depth0 && depth0.label); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
|
|
194
|
-
buffer += escapeExpression(stack1)
|
|
195
|
-
+ "\n ";
|
|
196
|
-
stack1 = helpers['if'].call(depth0, (depth0 && depth0.required), {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
|
|
197
|
-
if(stack1 || stack1 === 0) { buffer += stack1; }
|
|
198
|
-
buffer += "\n</label>\n";
|
|
199
|
-
return buffer;
|
|
200
|
-
});
|
|
201
|
-
function labelTpl(data, options, asString) {
|
|
202
|
-
var html = Template$1(data, options);
|
|
203
|
-
return (asString || true) ? html : $(html);
|
|
263
|
+
if (!_.isString(config.widget) || !config.widget) {
|
|
264
|
+
throw new TypeError('The config must declare a type of widget');
|
|
204
265
|
}
|
|
205
266
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
214
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
215
|
-
* GNU General Public License for more details.
|
|
216
|
-
*
|
|
217
|
-
* You should have received a copy of the GNU General Public License
|
|
218
|
-
* along with this program; if not, write to the Free Software
|
|
219
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
220
|
-
*
|
|
221
|
-
* Copyright (c) 2019 Open Assessment Technologies SA ;
|
|
222
|
-
*/
|
|
223
|
-
/**
|
|
224
|
-
* @typedef {Object} widgetConfig Defines the config entries available to setup a form widget
|
|
225
|
-
* @property {String} widget - The type of widget.
|
|
226
|
-
* It will be used by the main factory to retrieve
|
|
227
|
-
* the implementation from the internal registry.
|
|
228
|
-
* @property {String} widgetType - The internal type of widget
|
|
229
|
-
* @property {String} uri - The identifier of the widget
|
|
230
|
-
* @property {String} [label] - The label of the widget
|
|
231
|
-
* @property {String|String[]} [value] - The value of the widget. Depending on the widget's type,
|
|
232
|
-
* it can be a single or a multiple value
|
|
233
|
-
* @property {widgetRangeValue[]} [range] - Array of values used in multi-elements widgets (like combo or checkbox)
|
|
234
|
-
* @property {Boolean} [required] - Tells if the value is required
|
|
235
|
-
* @property {validationRule|validationRule[]|validator} [validation] - Optional validators to add
|
|
236
|
-
*/
|
|
267
|
+
return widgetFactory.getProvider(config.widget);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Makes sure a value is an array
|
|
271
|
+
* @param {*} value
|
|
272
|
+
* @returns {Array}
|
|
273
|
+
*/
|
|
237
274
|
|
|
238
|
-
/**
|
|
239
|
-
* @typedef {Object} widgetRangeValue Defines a value to use in a widget range
|
|
240
|
-
* @property {String} uri - The identifier of the value
|
|
241
|
-
* @property {String} label - The label for the value
|
|
242
|
-
*/
|
|
243
275
|
|
|
276
|
+
function forceArray(value) {
|
|
277
|
+
if (value && !_.isArray(value)) {
|
|
278
|
+
value = [value];
|
|
279
|
+
} else {
|
|
280
|
+
value = value || [];
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return value;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Factory that builds a form element based on its config.
|
|
287
|
+
*
|
|
288
|
+
* * @example
|
|
289
|
+
* const container = $('.my-container', $container);
|
|
290
|
+
*
|
|
291
|
+
* widgetFactory.registerProvider('textinput', widgetTextInputProvider);
|
|
292
|
+
*
|
|
293
|
+
* const config = {
|
|
294
|
+
* widget: 'textinput'
|
|
295
|
+
* uri: 'text',
|
|
296
|
+
* label: 'Text',
|
|
297
|
+
* required: true
|
|
298
|
+
* };
|
|
299
|
+
*
|
|
300
|
+
* const widget = widgetFactory(container, config)
|
|
301
|
+
* .on('change', function(value) {
|
|
302
|
+
* // ...
|
|
303
|
+
* });
|
|
304
|
+
*
|
|
305
|
+
* @param {HTMLElement|String} container
|
|
306
|
+
* @param {widgetConfig} config
|
|
307
|
+
* @param {String} config.widget - The type of widget.
|
|
308
|
+
* It will be used by the main factory to retrieve
|
|
309
|
+
* the implementation from the internal registry.
|
|
310
|
+
* @param {String} config.uri - The identifier of the widget
|
|
311
|
+
* @param {String} [config.label] - The label of the widget
|
|
312
|
+
* @param {String|String[]} [config.value] - The value of the widget. Depending on the widget's type,
|
|
313
|
+
* it can be a single or a multiple value
|
|
314
|
+
* @param {widgetRangeValue[]} [config.range] - Array of values used in multi-elements widgets (like combo or checkbox)
|
|
315
|
+
* @param {Boolean} [config.required] - Tells if the value is required
|
|
316
|
+
* @param {validationRule|validationRule[]|validator} [config.validation] - Optional validators to add
|
|
317
|
+
* @returns {widgetForm}
|
|
318
|
+
* @fires ready - When the component is ready to work
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
function widgetFactory(container, config) {
|
|
323
|
+
var widget;
|
|
324
|
+
var validator;
|
|
325
|
+
var validatorRenderer;
|
|
326
|
+
var provider = getWidgetProvider(config);
|
|
244
327
|
/**
|
|
245
|
-
*
|
|
246
|
-
* @
|
|
328
|
+
* Reflects the invalid state to the component
|
|
329
|
+
* @param {Boolean} invalid
|
|
330
|
+
* @param {String[]} [messages]
|
|
247
331
|
*/
|
|
248
332
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
333
|
+
var setInvalidState = function setInvalidState(invalid, messages) {
|
|
334
|
+
widget.setState('invalid', invalid);
|
|
335
|
+
|
|
336
|
+
if (validatorRenderer) {
|
|
337
|
+
if (invalid) {
|
|
338
|
+
validatorRenderer.display(messages);
|
|
339
|
+
} else {
|
|
340
|
+
validatorRenderer.clear();
|
|
341
|
+
}
|
|
342
|
+
}
|
|
255
343
|
};
|
|
256
344
|
/**
|
|
257
|
-
*
|
|
258
|
-
* @param {
|
|
259
|
-
* @
|
|
260
|
-
* @
|
|
345
|
+
* Delegate a call to the provider, or fallback to the default implementation
|
|
346
|
+
* @param {String} method - The name of the method to call.
|
|
347
|
+
* @param {...} args - Extra parameters
|
|
348
|
+
* @returns {*}
|
|
261
349
|
*/
|
|
262
350
|
|
|
263
|
-
function getWidgetProvider(config) {
|
|
264
|
-
if (!_.isPlainObject(config)) {
|
|
265
|
-
throw new TypeError('The config must be an object');
|
|
266
|
-
}
|
|
267
351
|
|
|
268
|
-
|
|
269
|
-
|
|
352
|
+
var delegate = function delegate(method) {
|
|
353
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
354
|
+
args[_key - 1] = arguments[_key];
|
|
270
355
|
}
|
|
271
356
|
|
|
272
|
-
if (
|
|
273
|
-
|
|
357
|
+
if (_.isFunction(provider[method])) {
|
|
358
|
+
return provider[method].apply(widget, args);
|
|
274
359
|
}
|
|
275
360
|
|
|
276
|
-
return
|
|
277
|
-
}
|
|
361
|
+
return defaultProvider[method].apply(widget, args);
|
|
362
|
+
};
|
|
278
363
|
/**
|
|
279
|
-
*
|
|
280
|
-
* @
|
|
281
|
-
* @
|
|
364
|
+
* Triggers the change event
|
|
365
|
+
* @returns {widgetForm}
|
|
366
|
+
* @fires change
|
|
282
367
|
*/
|
|
283
368
|
|
|
284
369
|
|
|
285
|
-
function
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
370
|
+
var notifyChange = function notifyChange() {
|
|
371
|
+
/**
|
|
372
|
+
* @event change
|
|
373
|
+
* @param {String|String[]} value
|
|
374
|
+
* @param {String} uri
|
|
375
|
+
*/
|
|
376
|
+
widget.trigger('change', widget.getValue(), widget.getUri());
|
|
377
|
+
};
|
|
294
378
|
/**
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
* * @example
|
|
298
|
-
* const container = $('.my-container', $container);
|
|
299
|
-
*
|
|
300
|
-
* widgetFactory.registerProvider('textinput', widgetTextInputProvider);
|
|
301
|
-
*
|
|
302
|
-
* const config = {
|
|
303
|
-
* widget: 'textinput'
|
|
304
|
-
* uri: 'text',
|
|
305
|
-
* label: 'Text',
|
|
306
|
-
* required: true
|
|
307
|
-
* };
|
|
308
|
-
*
|
|
309
|
-
* const widget = widgetFactory(container, config)
|
|
310
|
-
* .on('change', function(value) {
|
|
311
|
-
* // ...
|
|
312
|
-
* });
|
|
313
|
-
*
|
|
314
|
-
* @param {HTMLElement|String} container
|
|
315
|
-
* @param {widgetConfig} config
|
|
316
|
-
* @param {String} config.widget - The type of widget.
|
|
317
|
-
* It will be used by the main factory to retrieve
|
|
318
|
-
* the implementation from the internal registry.
|
|
319
|
-
* @param {String} config.uri - The identifier of the widget
|
|
320
|
-
* @param {String} [config.label] - The label of the widget
|
|
321
|
-
* @param {String|String[]} [config.value] - The value of the widget. Depending on the widget's type,
|
|
322
|
-
* it can be a single or a multiple value
|
|
323
|
-
* @param {widgetRangeValue[]} [config.range] - Array of values used in multi-elements widgets (like combo or checkbox)
|
|
324
|
-
* @param {Boolean} [config.required] - Tells if the value is required
|
|
325
|
-
* @param {validationRule|validationRule[]|validator} [config.validation] - Optional validators to add
|
|
326
|
-
* @returns {widgetForm}
|
|
327
|
-
* @fires ready - When the component is ready to work
|
|
379
|
+
* @typedef {component} widgetForm
|
|
328
380
|
*/
|
|
329
381
|
|
|
330
382
|
|
|
331
|
-
|
|
332
|
-
let widget;
|
|
333
|
-
let validator;
|
|
334
|
-
let validatorRenderer;
|
|
335
|
-
const provider = getWidgetProvider(config);
|
|
383
|
+
var widgetApi = {
|
|
336
384
|
/**
|
|
337
|
-
*
|
|
338
|
-
* @
|
|
339
|
-
* @param {String[]} [messages]
|
|
385
|
+
* Gets the widget's URI
|
|
386
|
+
* @returns {String}
|
|
340
387
|
*/
|
|
388
|
+
getUri: function getUri() {
|
|
389
|
+
return this.getConfig().uri;
|
|
390
|
+
},
|
|
341
391
|
|
|
342
|
-
|
|
343
|
-
|
|
392
|
+
/**
|
|
393
|
+
* Gets the value of the widget
|
|
394
|
+
* @returns {String|String[]}
|
|
395
|
+
*/
|
|
396
|
+
getValue: function getValue() {
|
|
397
|
+
return delegate('getValue');
|
|
398
|
+
},
|
|
344
399
|
|
|
345
|
-
if (validatorRenderer) {
|
|
346
|
-
if (invalid) {
|
|
347
|
-
validatorRenderer.display(messages);
|
|
348
|
-
} else {
|
|
349
|
-
validatorRenderer.clear();
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
400
|
/**
|
|
354
|
-
*
|
|
355
|
-
* @param {String} method - The name of the method to call.
|
|
356
|
-
* @param {...} args - Extra parameters
|
|
401
|
+
* Gets the raw value of the widget
|
|
357
402
|
* @returns {*}
|
|
358
403
|
*/
|
|
404
|
+
getRawValue: function getRawValue() {
|
|
405
|
+
return delegate('getRawValue');
|
|
406
|
+
},
|
|
359
407
|
|
|
360
|
-
|
|
361
|
-
const delegate = function (method) {
|
|
362
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
363
|
-
args[_key - 1] = arguments[_key];
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
if (_.isFunction(provider[method])) {
|
|
367
|
-
return provider[method].apply(widget, args);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
return defaultProvider[method].apply(widget, args);
|
|
371
|
-
};
|
|
372
408
|
/**
|
|
373
|
-
*
|
|
409
|
+
* Sets the value of the widget
|
|
410
|
+
* @param {String|String[]} value
|
|
374
411
|
* @returns {widgetForm}
|
|
375
|
-
* @fires change
|
|
412
|
+
* @fires change after the value has been changed
|
|
376
413
|
*/
|
|
414
|
+
setValue: function setValue(value) {
|
|
415
|
+
this.getConfig().value = value;
|
|
416
|
+
delegate('setValue', value);
|
|
417
|
+
notifyChange();
|
|
418
|
+
return this;
|
|
419
|
+
},
|
|
377
420
|
|
|
378
|
-
|
|
379
|
-
const notifyChange = () => {
|
|
380
|
-
/**
|
|
381
|
-
* @event change
|
|
382
|
-
* @param {String|String[]} value
|
|
383
|
-
* @param {String} uri
|
|
384
|
-
*/
|
|
385
|
-
widget.trigger('change', widget.getValue(), widget.getUri());
|
|
386
|
-
};
|
|
387
421
|
/**
|
|
388
|
-
*
|
|
422
|
+
* Gets access to the validation engine
|
|
423
|
+
* @returns {validator}
|
|
389
424
|
*/
|
|
425
|
+
getValidator: function getValidator() {
|
|
426
|
+
return validator;
|
|
427
|
+
},
|
|
390
428
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
* @returns {String|String[]}
|
|
404
|
-
*/
|
|
405
|
-
getValue() {
|
|
406
|
-
return delegate('getValue');
|
|
407
|
-
},
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Gets the raw value of the widget
|
|
411
|
-
* @returns {*}
|
|
412
|
-
*/
|
|
413
|
-
getRawValue() {
|
|
414
|
-
return delegate('getRawValue');
|
|
415
|
-
},
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* Sets the value of the widget
|
|
419
|
-
* @param {String|String[]} value
|
|
420
|
-
* @returns {widgetForm}
|
|
421
|
-
* @fires change after the value has been changed
|
|
422
|
-
*/
|
|
423
|
-
setValue(value) {
|
|
424
|
-
this.getConfig().value = value;
|
|
425
|
-
delegate('setValue', value);
|
|
426
|
-
notifyChange();
|
|
427
|
-
return this;
|
|
428
|
-
},
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Gets access to the validation engine
|
|
432
|
-
* @returns {validator}
|
|
433
|
-
*/
|
|
434
|
-
getValidator() {
|
|
435
|
-
return validator;
|
|
436
|
-
},
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Sets the validation engine
|
|
440
|
-
* @param {validationRule|validationRule[]|validator} validation
|
|
441
|
-
* @returns {widgetForm}
|
|
442
|
-
*/
|
|
443
|
-
setValidator(validation) {
|
|
444
|
-
if (validation && _.isFunction(validation.validate)) {
|
|
445
|
-
validator = validation;
|
|
446
|
-
} else {
|
|
447
|
-
if (validation && !validation.validations) {
|
|
448
|
-
if (!_.isArray(validation)) {
|
|
449
|
-
validation = [validation];
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
validation = {
|
|
453
|
-
validations: validation
|
|
454
|
-
};
|
|
429
|
+
/**
|
|
430
|
+
* Sets the validation engine
|
|
431
|
+
* @param {validationRule|validationRule[]|validator} validation
|
|
432
|
+
* @returns {widgetForm}
|
|
433
|
+
*/
|
|
434
|
+
setValidator: function setValidator(validation) {
|
|
435
|
+
if (validation && _.isFunction(validation.validate)) {
|
|
436
|
+
validator = validation;
|
|
437
|
+
} else {
|
|
438
|
+
if (validation && !validation.validations) {
|
|
439
|
+
if (!_.isArray(validation)) {
|
|
440
|
+
validation = [validation];
|
|
455
441
|
}
|
|
456
442
|
|
|
457
|
-
|
|
443
|
+
validation = {
|
|
444
|
+
validations: validation
|
|
445
|
+
};
|
|
458
446
|
}
|
|
459
447
|
|
|
460
|
-
|
|
461
|
-
},
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* Resets the widget to the default validators
|
|
465
|
-
* @returns {widgetForm}
|
|
466
|
-
*/
|
|
467
|
-
setDefaultValidators() {
|
|
468
|
-
// restore factory default validators
|
|
469
|
-
this.setValidator(this.getConfig().validator); // then apply provider default validators
|
|
470
|
-
|
|
471
|
-
delegate('setDefaultValidators');
|
|
472
|
-
return this;
|
|
473
|
-
},
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Resets the widget to its default value
|
|
477
|
-
* @returns {widgetForm}
|
|
478
|
-
*/
|
|
479
|
-
reset() {
|
|
480
|
-
delegate('reset');
|
|
481
|
-
setInvalidState(false);
|
|
482
|
-
return this;
|
|
483
|
-
},
|
|
484
|
-
|
|
485
|
-
/**
|
|
486
|
-
* Validates the widget
|
|
487
|
-
* @returns {Promise}
|
|
488
|
-
*/
|
|
489
|
-
validate() {
|
|
490
|
-
return this.getValidator().validate(this.getRawValue()).then(res => {
|
|
491
|
-
setInvalidState(false);
|
|
492
|
-
return res;
|
|
493
|
-
}).catch(err => {
|
|
494
|
-
setInvalidState(true, err);
|
|
495
|
-
return Promise.reject(err);
|
|
496
|
-
});
|
|
497
|
-
},
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Gets access to the actual form element
|
|
501
|
-
* @returns {jQuery|null}
|
|
502
|
-
*/
|
|
503
|
-
getWidgetElement() {
|
|
504
|
-
if (this.is('rendered')) {
|
|
505
|
-
return delegate('getWidgetElement');
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
return null;
|
|
448
|
+
validator = validatorFactory(validation);
|
|
509
449
|
}
|
|
510
450
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
451
|
+
return this;
|
|
452
|
+
},
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Resets the widget to the default validators
|
|
456
|
+
* @returns {widgetForm}
|
|
457
|
+
*/
|
|
458
|
+
setDefaultValidators: function setDefaultValidators() {
|
|
459
|
+
// restore factory default validators
|
|
460
|
+
this.setValidator(this.getConfig().validator); // then apply provider default validators
|
|
514
461
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
this.setState(this.getConfig().widgetType, true); // react to data change
|
|
462
|
+
delegate('setDefaultValidators');
|
|
463
|
+
return this;
|
|
464
|
+
},
|
|
519
465
|
|
|
520
|
-
|
|
521
|
-
|
|
466
|
+
/**
|
|
467
|
+
* Resets the widget to its default value
|
|
468
|
+
* @returns {widgetForm}
|
|
469
|
+
*/
|
|
470
|
+
reset: function reset() {
|
|
471
|
+
delegate('reset');
|
|
472
|
+
setInvalidState(false);
|
|
473
|
+
return this;
|
|
474
|
+
},
|
|
522
475
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
476
|
+
/**
|
|
477
|
+
* Validates the widget
|
|
478
|
+
* @returns {Promise}
|
|
479
|
+
*/
|
|
480
|
+
validate: function validate() {
|
|
481
|
+
return this.getValidator().validate(this.getRawValue()).then(function (res) {
|
|
482
|
+
setInvalidState(false);
|
|
483
|
+
return res;
|
|
484
|
+
}).catch(function (err) {
|
|
485
|
+
setInvalidState(true, err);
|
|
486
|
+
return Promise.reject(err);
|
|
527
487
|
});
|
|
528
|
-
|
|
529
|
-
* @event ready
|
|
530
|
-
*/
|
|
488
|
+
},
|
|
531
489
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}).on('enable', function onWidgetEnable() {
|
|
490
|
+
/**
|
|
491
|
+
* Gets access to the actual form element
|
|
492
|
+
* @returns {jQuery|null}
|
|
493
|
+
*/
|
|
494
|
+
getWidgetElement: function getWidgetElement() {
|
|
538
495
|
if (this.is('rendered')) {
|
|
539
|
-
|
|
496
|
+
return delegate('getWidgetElement');
|
|
540
497
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
498
|
+
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
widget = componentFactory(widgetApi, defaults).setTemplate(provider.template || widgetTpl).on('init', function onWidgetInit() {
|
|
503
|
+
var _this = this;
|
|
504
|
+
|
|
505
|
+
this.setDefaultValidators(); // auto render on init (defer the call to give a chance to the init event to be completed before)
|
|
506
|
+
|
|
507
|
+
_.defer(function () {
|
|
508
|
+
return _this.render(container);
|
|
509
|
+
});
|
|
510
|
+
}).on('render', function onWidgetRender() {
|
|
511
|
+
var _this2 = this;
|
|
512
|
+
|
|
513
|
+
// reflect the type of widget
|
|
514
|
+
this.setState(this.getConfig().widgetType, true); // react to data change
|
|
515
|
+
|
|
516
|
+
this.getWidgetElement().on('change blur', function () {
|
|
517
|
+
var value = _this2.getValue();
|
|
518
|
+
|
|
519
|
+
if (value !== _this2.getConfig().value) {
|
|
520
|
+
_this2.getConfig().value = value;
|
|
521
|
+
notifyChange();
|
|
545
522
|
}
|
|
546
523
|
});
|
|
524
|
+
/**
|
|
525
|
+
* @event ready
|
|
526
|
+
*/
|
|
547
527
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
528
|
+
validatorRenderer = validatorRendererFactory(this.getElement()).spread(this, 'error ready');
|
|
529
|
+
}).on('disable', function onWidgetDisable() {
|
|
530
|
+
if (this.is('rendered')) {
|
|
531
|
+
this.getWidgetElement().prop('disabled', true);
|
|
532
|
+
}
|
|
533
|
+
}).on('enable', function onWidgetEnable() {
|
|
534
|
+
if (this.is('rendered')) {
|
|
535
|
+
this.getWidgetElement().prop('disabled', false);
|
|
551
536
|
}
|
|
537
|
+
}).on('destroy', function onWidgetDestroy() {
|
|
538
|
+
if (validatorRenderer) {
|
|
539
|
+
validatorRenderer.destroy();
|
|
540
|
+
validatorRenderer = null;
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
if (config) {
|
|
545
|
+
// the range must be an array
|
|
546
|
+
config.range = forceArray(config.range);
|
|
547
|
+
}
|
|
552
548
|
|
|
553
|
-
|
|
549
|
+
_.defer(function () {
|
|
550
|
+
return widget.init(provider.init.call(widget, config || {}) || config);
|
|
551
|
+
});
|
|
554
552
|
|
|
555
|
-
|
|
556
|
-
|
|
553
|
+
return widget;
|
|
554
|
+
} // expose a partial that can be used by every form widget to inject the label markup
|
|
557
555
|
|
|
558
556
|
|
|
559
|
-
|
|
557
|
+
Handlebars.registerPartial('ui-form-widget-label', labelTpl); // the widgetFactory is also a providers registry
|
|
560
558
|
|
|
561
|
-
|
|
559
|
+
providerRegistry(widgetFactory);
|
|
562
560
|
|
|
563
|
-
|
|
561
|
+
return widgetFactory;
|
|
564
562
|
|
|
565
563
|
});
|