@oat-sa/tao-core-ui 1.63.1 → 1.64.0

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.
Files changed (101) hide show
  1. package/dist/actionbar.js +2 -109
  2. package/dist/animable/absorbable/absorbable.js +2 -109
  3. package/dist/animable/pulsable/pulsable.js +2 -109
  4. package/dist/badge/badge.js +2 -109
  5. package/dist/breadcrumbs.js +2 -109
  6. package/dist/bulkActionPopup.js +2 -108
  7. package/dist/button.js +2 -110
  8. package/dist/cascadingComboBox.js +2 -108
  9. package/dist/class/selector.js +2 -108
  10. package/dist/component/windowed.js +2 -108
  11. package/dist/component.js +2 -109
  12. package/dist/contextualPopup.js +2 -109
  13. package/dist/dashboard.js +2 -108
  14. package/dist/datalist.js +2 -108
  15. package/dist/datatable.js +3 -108
  16. package/dist/dateRange/dateRange.js +2 -108
  17. package/dist/datetime/picker.js +2 -108
  18. package/dist/deleter.js +2 -108
  19. package/dist/destination/selector.js +2 -108
  20. package/dist/dialog/confirmDelete.js +2 -108
  21. package/dist/dialog.js +2 -108
  22. package/dist/documentViewer/providers/pdfViewer/fallback/viewer.js +2 -110
  23. package/dist/documentViewer/providers/pdfViewer/pdfjs/findBar.js +2 -109
  24. package/dist/documentViewer/providers/pdfViewer/pdfjs/pageView.js +2 -110
  25. package/dist/documentViewer/providers/pdfViewer/pdfjs/searchEngine.js +2 -109
  26. package/dist/documentViewer/providers/pdfViewer/pdfjs/viewer.js +2 -109
  27. package/dist/documentViewer/providers/pdfViewer.js +2 -109
  28. package/dist/documentViewer.js +2 -109
  29. package/dist/dropdown.js +2 -109
  30. package/dist/dynamicComponent.js +2 -109
  31. package/dist/feedback.js +2 -109
  32. package/dist/figure/FigureStateActive.js +2 -108
  33. package/dist/filter.js +2 -108
  34. package/dist/form/dropdownForm.js +2 -108
  35. package/dist/form/form.js +2 -109
  36. package/dist/form/validator/renderer.js +2 -109
  37. package/dist/form/widget/providers/checkBox.js +2 -108
  38. package/dist/form/widget/providers/comboBox.js +2 -110
  39. package/dist/form/widget/providers/hidden.js +2 -110
  40. package/dist/form/widget/providers/hiddenBox.js +2 -108
  41. package/dist/form/widget/providers/radioBox.js +2 -110
  42. package/dist/form/widget/providers/textArea.js +2 -110
  43. package/dist/form/widget/widget.js +2 -108
  44. package/dist/generis/form/form.js +2 -108
  45. package/dist/generis/validator/validator.js +2 -109
  46. package/dist/generis/widget/checkBox/checkBox.js +2 -108
  47. package/dist/generis/widget/comboBox/comboBox.js +2 -109
  48. package/dist/generis/widget/hiddenBox/hiddenBox.js +2 -109
  49. package/dist/generis/widget/textBox/textBox.js +2 -109
  50. package/dist/generis/widget/widget.js +2 -108
  51. package/dist/groupedComboBox.js +2 -108
  52. package/dist/itemButtonList.js +2 -110
  53. package/dist/listbox.js +2 -108
  54. package/dist/loadingButton/loadingButton.js +2 -109
  55. package/dist/lock.js +2 -108
  56. package/dist/login/login.js +2 -108
  57. package/dist/maths/calculator/basicCalculator.js +2 -109
  58. package/dist/maths/calculator/core/board.js +2 -108
  59. package/dist/maths/calculator/core/expression.js +2 -109
  60. package/dist/maths/calculator/core/labels.js +2 -109
  61. package/dist/maths/calculator/plugins/keyboard/templateKeyboard/templateKeyboard.js +2 -109
  62. package/dist/maths/calculator/plugins/screen/simpleScreen/simpleScreen.js +2 -109
  63. package/dist/maths/calculator/scientificCalculator.js +2 -108
  64. package/dist/mediaEditor/mediaEditorComponent.js +2 -109
  65. package/dist/mediaEditor/plugins/mediaAlignment/mediaAlignmentComponent.js +2 -109
  66. package/dist/mediaEditor/plugins/mediaDimension/mediaDimensionComponent.js +2 -109
  67. package/dist/mediaplayer/players/html5.js +2 -110
  68. package/dist/mediaplayer/players/youtube.js +2 -110
  69. package/dist/mediaplayer.js +2 -109
  70. package/dist/mediasizer.js +2 -109
  71. package/dist/pageSizeSelector.js +2 -109
  72. package/dist/pagination/providers/pages.js +2 -109
  73. package/dist/pagination/providers/simple.js +2 -110
  74. package/dist/propertySelector/propertySelector.js +2 -110
  75. package/dist/report.js +2 -109
  76. package/dist/resource/filters.js +2 -108
  77. package/dist/resource/list.js +29 -119
  78. package/dist/resource/selector.js +2 -108
  79. package/dist/resource/tree.js +29 -119
  80. package/dist/resourcemgr/fileBrowser.js +478 -585
  81. package/dist/resourcemgr/fileSelector.js +2 -108
  82. package/dist/resourcemgr.js +2 -109
  83. package/dist/searchModal/advancedSearch.js +2 -109
  84. package/dist/searchModal.js +16 -107
  85. package/dist/switch/switch.js +2 -108
  86. package/dist/tabs.js +2 -109
  87. package/dist/taskQueue/status.js +2 -108
  88. package/dist/taskQueue/table.js +2 -108
  89. package/dist/taskQueueButton/taskable.js +2 -108
  90. package/dist/taskQueueButton/treeButton.js +2 -109
  91. package/dist/tooltip.js +2 -109
  92. package/dist/tristateCheckboxGroup.js +2 -108
  93. package/dist/uploader.js +2 -108
  94. package/package.json +2 -2
  95. package/scss/.DS_Store +0 -0
  96. package/scss/ckeditor/.DS_Store +0 -0
  97. package/scss/ckeditor/skins/.DS_Store +0 -0
  98. package/scss/ckeditor/skins/tao/.DS_Store +0 -0
  99. package/scss/ckeditor/skins/tao/scss/.DS_Store +0 -0
  100. package/scss/font/.DS_Store +0 -0
  101. package/scss/inc/.DS_Store +0 -0
@@ -1,608 +1,501 @@
1
- define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'i18n', 'lib/dompurify/purify'], function ($$1, _, request, paginationComponent, Handlebars, __, DOMPurify) { 'use strict';
1
+ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/handlebars/helpers'], function ($$1, _, request, paginationComponent, Handlebars, Helpers0) { 'use strict';
2
2
 
3
- $$1 = $$1 && Object.prototype.hasOwnProperty.call($$1, 'default') ? $$1['default'] : $$1;
4
- _ = _ && Object.prototype.hasOwnProperty.call(_, 'default') ? _['default'] : _;
5
- request = request && Object.prototype.hasOwnProperty.call(request, 'default') ? request['default'] : request;
6
- paginationComponent = paginationComponent && Object.prototype.hasOwnProperty.call(paginationComponent, 'default') ? paginationComponent['default'] : paginationComponent;
7
- Handlebars = Handlebars && Object.prototype.hasOwnProperty.call(Handlebars, 'default') ? Handlebars['default'] : Handlebars;
8
- __ = __ && Object.prototype.hasOwnProperty.call(__, 'default') ? __['default'] : __;
9
- DOMPurify = DOMPurify && Object.prototype.hasOwnProperty.call(DOMPurify, 'default') ? DOMPurify['default'] : DOMPurify;
3
+ $$1 = $$1 && Object.prototype.hasOwnProperty.call($$1, 'default') ? $$1['default'] : $$1;
4
+ _ = _ && Object.prototype.hasOwnProperty.call(_, 'default') ? _['default'] : _;
5
+ request = request && Object.prototype.hasOwnProperty.call(request, 'default') ? request['default'] : request;
6
+ paginationComponent = paginationComponent && Object.prototype.hasOwnProperty.call(paginationComponent, 'default') ? paginationComponent['default'] : paginationComponent;
7
+ Handlebars = Handlebars && Object.prototype.hasOwnProperty.call(Handlebars, 'default') ? Handlebars['default'] : Handlebars;
8
+ Helpers0 = Helpers0 && Object.prototype.hasOwnProperty.call(Helpers0, 'default') ? Helpers0['default'] : Helpers0;
10
9
 
11
- /**
12
- * This program is free software; you can redistribute it and/or
13
- * modify it under the terms of the GNU General Public License
14
- * as published by the Free Software Foundation; under version 2
15
- * of the License (non-upgradable).
16
- *
17
- * This program is distributed in the hope that it will be useful,
18
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
- * GNU General Public License for more details.
21
- *
22
- * You should have received a copy of the GNU General Public License
23
- * along with this program; if not, write to the Free Software
24
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
- *
26
- * Copyright (c) 2013-2019 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
27
- *
28
- *
29
- */
30
- function Helpers0 (hb) {
31
- //register a i18n helper
32
- hb.registerHelper('__', function (key) {
33
- return __(key);
34
- });
10
+ if (!Helpers0.__initialized) {
11
+ Helpers0(Handlebars);
12
+ Helpers0.__initialized = true;
13
+ }
14
+ var Template = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
15
+ this.compilerInfo = [4,'>= 1.0.0'];
16
+ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
17
+ var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;
35
18
 
36
- /**
37
- * Register dompurify helper
38
- *
39
- * https://github.com/cure53/DOMPurify
40
- * with config SAFE_FOR_TEMPLATES: true
41
- * to make output safe for template systems
42
- */
43
- hb.registerHelper('dompurify', function (context) {
44
- return DOMPurify.sanitize(context);
45
- });
19
+ function program1(depth0,data) {
20
+
21
+ var buffer = "", stack1, helper;
22
+ buffer += "\n <li class=\"root\">\n <a\n class=\"root-folder active\"\n href=\"#\"\n data-path=\"";
23
+ if (helper = helpers.path) { stack1 = helper.call(depth0, {hash:{},data:data}); }
24
+ else { helper = (depth0 && depth0.path); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
25
+ buffer += escapeExpression(stack1)
26
+ + "\"\n data-display=\"";
27
+ if (helper = helpers.relPath) { stack1 = helper.call(depth0, {hash:{},data:data}); }
28
+ else { helper = (depth0 && depth0.relPath); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
29
+ buffer += escapeExpression(stack1)
30
+ + "\"\n data-children-limit=\"";
31
+ if (helper = helpers.childrenLimit) { stack1 = helper.call(depth0, {hash:{},data:data}); }
32
+ else { helper = (depth0 && depth0.childrenLimit); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
33
+ buffer += escapeExpression(stack1)
34
+ + "\">\n ";
35
+ if (helper = helpers.label) { stack1 = helper.call(depth0, {hash:{},data:data}); }
36
+ else { helper = (depth0 && depth0.label); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
37
+ buffer += escapeExpression(stack1)
38
+ + "\n </a>\n <ul></ul>\n </li>\n";
39
+ return buffer;
40
+ }
46
41
 
47
- /**
48
- * Register join helper
49
- *
50
- * Example :
51
- * var values = {a:v1, b:v2, c:v3};
52
- * Using {{{join attributes '=' ' ' '"'}}} will return : a="v1" b="v2" c="v3"
53
- * Using {{{join values null ' or ' '*'}}} will return : *v1* or *v2* or *v3*
54
- */
55
- hb.registerHelper('join', function (arr, keyValueGlue, fragmentGlue, wrapper) {
56
- var fragments = [];
57
- keyValueGlue = typeof keyValueGlue === 'string' ? keyValueGlue : undefined;
58
- fragmentGlue = typeof fragmentGlue === 'string' ? fragmentGlue : ' ';
59
- wrapper = typeof wrapper === 'string' ? wrapper : '"';
60
- _.forIn(arr, function (value, key) {
61
- var fragment = '';
62
- if (value !== null || value !== undefined) {
63
- if (typeof value === 'boolean') {
64
- value = value ? 'true' : 'false';
65
- } else if (typeof value === 'object') {
66
- value = _.values(value).join(' ');
67
- }
68
- } else {
69
- value = '';
70
- }
71
- if (keyValueGlue !== undefined) {
72
- fragment += key + keyValueGlue;
73
- }
74
- fragment += wrapper + value + wrapper;
75
- fragments.push(fragment);
76
- });
77
- return fragments.join(fragmentGlue);
78
- });
42
+ stack1 = helpers['if'].call(depth0, ((stack1 = (depth0 && depth0.permissions)),stack1 == null || stack1 === false ? stack1 : stack1.read), {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
43
+ if(stack1 || stack1 === 0) { buffer += stack1; }
44
+ buffer += "\n";
45
+ return buffer;
46
+ });
47
+ function rootFolderTpl(data, options, asString) {
48
+ var html = Template(data, options);
49
+ return (asString || true) ? html : $(html);
50
+ }
79
51
 
80
- //register a classic "for loop" helper
81
- //it also adds a local variable "i" as the index in each iteration loop
82
- hb.registerHelper('for', function (startIndex, stopIndex, increment, options) {
83
- var ret = '';
84
- startIndex = parseInt(startIndex);
85
- stopIndex = parseInt(stopIndex);
86
- increment = parseInt(increment);
87
- for (var i = startIndex; i < stopIndex; i += increment) {
88
- ret += options.fn(_.extend({}, this, {
89
- i: i
90
- }));
91
- }
92
- return ret;
93
- });
94
- hb.registerHelper('equal', function (var1, var2, options) {
95
- if (var1 == var2) {
96
- return options.fn(this);
97
- } else {
98
- return options.inverse(this);
99
- }
100
- });
52
+ if (!Helpers0.__initialized) {
53
+ Helpers0(Handlebars);
54
+ Helpers0.__initialized = true;
55
+ }
56
+ var Template$1 = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
57
+ this.compilerInfo = [4,'>= 1.0.0'];
58
+ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
59
+ var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;
101
60
 
102
- // register a "get property" helper
103
- // it gets the named property from the provided context
104
- hb.registerHelper('property', function (name, context) {
105
- return context[name] || '';
106
- });
61
+ function program1(depth0,data) {
62
+
63
+ var buffer = "", stack1, helper;
64
+ buffer += "\n <li>\n <a\n data-path=\"";
65
+ if (helper = helpers.path) { stack1 = helper.call(depth0, {hash:{},data:data}); }
66
+ else { helper = (depth0 && depth0.path); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
67
+ buffer += escapeExpression(stack1)
68
+ + "\"\n data-display=\"";
69
+ if (helper = helpers.relPath) { stack1 = helper.call(depth0, {hash:{},data:data}); }
70
+ else { helper = (depth0 && depth0.relPath); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
71
+ buffer += escapeExpression(stack1)
72
+ + "\"\n data-children-limit=\"";
73
+ if (helper = helpers.childrenLimit) { stack1 = helper.call(depth0, {hash:{},data:data}); }
74
+ else { helper = (depth0 && depth0.childrenLimit); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
75
+ buffer += escapeExpression(stack1)
76
+ + "\"\n href=\"#\">\n ";
77
+ if (helper = helpers.label) { stack1 = helper.call(depth0, {hash:{},data:data}); }
78
+ else { helper = (depth0 && depth0.label); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
79
+ buffer += escapeExpression(stack1)
80
+ + "\n </a>\n </li>\n";
81
+ return buffer;
82
+ }
107
83
 
108
- // register an 'includes' helper
109
- // it checks if value is in array
110
- hb.registerHelper('includes', function (haystack, needle, options) {
111
- if (_.contains(haystack, needle)) {
112
- return options.fn(this);
113
- }
114
- });
115
- }
84
+ stack1 = helpers['if'].call(depth0, ((stack1 = (depth0 && depth0.permissions)),stack1 == null || stack1 === false ? stack1 : stack1.read), {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
85
+ if(stack1 || stack1 === 0) { buffer += stack1; }
86
+ buffer += "\n";
87
+ return buffer;
88
+ });
89
+ function folderTpl(data, options, asString) {
90
+ var html = Template$1(data, options);
91
+ return (asString || true) ? html : $(html);
92
+ }
116
93
 
117
- if (!Helpers0.__initialized) {
118
- Helpers0(Handlebars);
119
- Helpers0.__initialized = true;
120
- }
121
- var Template = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
122
- this.compilerInfo = [4,'>= 1.0.0'];
123
- helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
124
- var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;
94
+ /**
95
+ * Update the permissions in HTML Tree
96
+ * @param {Object} item - the tree item
97
+ * @return {Object} - item with permissions
98
+ */
99
+ function updatePermissions(item) {
100
+ const isAssets = (item.uri || item.path || '').includes('mediamanager');
101
+ let permissions = {
102
+ read: true,
103
+ write: true,
104
+ preview: true,
105
+ download: true,
106
+ upload: true,
107
+ delete: true
108
+ };
109
+ if (item.permissions) {
110
+ if (!item.permissions.includes('READ')) {
111
+ permissions.read = false;
112
+ }
113
+ if (!item.permissions.includes('WRITE')) {
114
+ permissions.write = false;
115
+ }
116
+ // Atomic permissions for Assets
117
+ if (isAssets) {
118
+ if (!item.permissions.includes('PREVIEW')) {
119
+ permissions.preview = false;
120
+ }
121
+ if (!item.permissions.includes('DOWNLOAD')) {
122
+ permissions.download = false;
123
+ }
124
+ if (!item.permissions.includes('UPLOAD')) {
125
+ permissions.upload = false;
126
+ }
127
+ if (!item.permissions.includes('DELETE')) {
128
+ permissions.delete = false;
129
+ }
130
+ // Generic permissions for item gallery media
131
+ } else {
132
+ if (!permissions.read) {
133
+ permissions.preview = false;
134
+ permissions.download = false;
135
+ }
136
+ if (!permissions.write) {
137
+ permissions.delete = false;
138
+ permissions.upload = false;
139
+ }
140
+ }
141
+ }
142
+ item.permissions = permissions;
143
+ return item;
144
+ }
125
145
 
126
- function program1(depth0,data) {
127
-
128
- var buffer = "", stack1, helper;
129
- buffer += "\n <li class=\"root\">\n <a\n class=\"root-folder active\"\n href=\"#\"\n data-path=\"";
130
- if (helper = helpers.path) { stack1 = helper.call(depth0, {hash:{},data:data}); }
131
- else { helper = (depth0 && depth0.path); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
132
- buffer += escapeExpression(stack1)
133
- + "\"\n data-display=\"";
134
- if (helper = helpers.relPath) { stack1 = helper.call(depth0, {hash:{},data:data}); }
135
- else { helper = (depth0 && depth0.relPath); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
136
- buffer += escapeExpression(stack1)
137
- + "\"\n data-children-limit=\"";
138
- if (helper = helpers.childrenLimit) { stack1 = helper.call(depth0, {hash:{},data:data}); }
139
- else { helper = (depth0 && depth0.childrenLimit); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
140
- buffer += escapeExpression(stack1)
141
- + "\">\n ";
142
- if (helper = helpers.label) { stack1 = helper.call(depth0, {hash:{},data:data}); }
143
- else { helper = (depth0 && depth0.label); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
144
- buffer += escapeExpression(stack1)
145
- + "\n </a>\n <ul></ul>\n </li>\n";
146
- return buffer;
147
- }
146
+ /**
147
+ * This program is free software; you can redistribute it and/or
148
+ * modify it under the terms of the GNU General Public License
149
+ * as published by the Free Software Foundation; under version 2
150
+ * of the License (non-upgradable).
151
+ *
152
+ * This program is distributed in the hope that it will be useful,
153
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
154
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
155
+ * GNU General Public License for more details.
156
+ *
157
+ * You should have received a copy of the GNU General Public License
158
+ * along with this program; if not, write to the Free Software
159
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
160
+ *
161
+ * Copyright (c) 2018-2020 (original work) Open Assessment Technologies SA;
162
+ */
163
+ const ns = 'resourcemgr';
164
+ function fileBrowser (options) {
165
+ const root = options.root || 'local';
166
+ const rootPath = options.path || '/';
167
+ const $container = options.$target;
168
+ const $fileBrowser = $$1('.file-browser .file-browser-wrapper', $container);
169
+ const $divContainer = $$1(`.${root}`, $fileBrowser);
170
+ const $folderContainer = $$1('.folders', $divContainer);
171
+ const fileTree = {};
172
+ // for pagination
173
+ let selectedClass = {
174
+ path: rootPath,
175
+ childrenLimit: 10,
176
+ total: 0,
177
+ page: 1
178
+ };
148
179
 
149
- stack1 = helpers['if'].call(depth0, ((stack1 = (depth0 && depth0.permissions)),stack1 == null || stack1 === false ? stack1 : stack1.read), {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
150
- if(stack1 || stack1 === 0) { buffer += stack1; }
151
- buffer += "\n";
152
- return buffer;
153
- });
154
- function rootFolderTpl(data, options, asString) {
155
- var html = Template(data, options);
156
- return (asString || true) ? html : $(html);
157
- }
180
+ //load the content of the ROOT
181
+ getFolderContent(fileTree, rootPath, function (content) {
182
+ //create the tree node for the ROOT folder by default once the initial content loaded
183
+ $folderContainer.append(rootFolderTpl(content));
184
+ const $rootNode = $$1('.root-folder', $folderContainer);
185
+ //create an inner list and append found elements
186
+ const $innerList = $$1('.root ul', $folderContainer);
187
+ if (content.children) {
188
+ $rootNode.addClass('opened');
189
+ }
190
+ updateFolders(content, $innerList);
191
+ if (content.permissions.read && !options.hasAlreadySelected) {
192
+ $$1('.file-browser').find('li.active').removeClass('active');
193
+ updateSelectedClass(content.path, content.total, content.childrenLimit);
194
+ $container.trigger('folderselect.'.concat(ns), [content.label, getPage(content.children), content.path, content]);
195
+ renderPagination();
196
+ if (root !== 'local') {
197
+ options.hasAlreadySelected = true;
198
+ }
199
+ }
200
+ });
158
201
 
159
- if (!Helpers0.__initialized) {
160
- Helpers0(Handlebars);
161
- Helpers0.__initialized = true;
162
- }
163
- var Template$1 = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
164
- this.compilerInfo = [4,'>= 1.0.0'];
165
- helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
166
- var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this;
202
+ // by clicking on the tree (using a live binding because content is not complete yet)
203
+ $divContainer.off('click', '.folders a').on('click', '.folders a', function (e) {
204
+ e.preventDefault();
205
+ const $selected = $$1(this);
206
+ const $folders = $$1('.folders li', $fileBrowser);
207
+ const fullPath = $selected.data('path');
208
+ const subTree = getByPath(fileTree, fullPath);
167
209
 
168
- function program1(depth0,data) {
169
-
170
- var buffer = "", stack1, helper;
171
- buffer += "\n <li>\n <a\n data-path=\"";
172
- if (helper = helpers.path) { stack1 = helper.call(depth0, {hash:{},data:data}); }
173
- else { helper = (depth0 && depth0.path); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
174
- buffer += escapeExpression(stack1)
175
- + "\"\n data-display=\"";
176
- if (helper = helpers.relPath) { stack1 = helper.call(depth0, {hash:{},data:data}); }
177
- else { helper = (depth0 && depth0.relPath); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
178
- buffer += escapeExpression(stack1)
179
- + "\"\n data-children-limit=\"";
180
- if (helper = helpers.childrenLimit) { stack1 = helper.call(depth0, {hash:{},data:data}); }
181
- else { helper = (depth0 && depth0.childrenLimit); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
182
- buffer += escapeExpression(stack1)
183
- + "\"\n href=\"#\">\n ";
184
- if (helper = helpers.label) { stack1 = helper.call(depth0, {hash:{},data:data}); }
185
- else { helper = (depth0 && depth0.label); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
186
- buffer += escapeExpression(stack1)
187
- + "\n </a>\n </li>\n";
188
- return buffer;
189
- }
210
+ //get the folder content
211
+ getFolderContent(subTree, fullPath, function (content) {
212
+ if (content) {
213
+ //either create the inner list of the content is new or just show it
214
+ let $innerList = $selected.siblings('ul');
215
+ if (!$innerList.length && content.children && _.find(content.children, 'path') && !content.empty) {
216
+ $innerList = $$1('<ul></ul>').insertAfter($selected);
217
+ updateFolders(content, $innerList);
218
+ $selected.addClass('opened');
219
+ } else if ($innerList.length) {
220
+ if ($innerList.css('display') === 'none') {
221
+ $innerList.show();
222
+ $selected.addClass('opened');
223
+ } else if ($selected.parent('li').hasClass('active')) {
224
+ $innerList.hide();
225
+ $selected.removeClass('opened');
226
+ }
227
+ }
190
228
 
191
- stack1 = helpers['if'].call(depth0, ((stack1 = (depth0 && depth0.permissions)),stack1 == null || stack1 === false ? stack1 : stack1.read), {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
192
- if(stack1 || stack1 === 0) { buffer += stack1; }
193
- buffer += "\n";
194
- return buffer;
195
- });
196
- function folderTpl(data, options, asString) {
197
- var html = Template$1(data, options);
198
- return (asString || true) ? html : $(html);
199
- }
229
+ //toggle active element
230
+ $folders.removeClass('active');
231
+ $selected.parent('li').addClass('active');
200
232
 
201
- /**
202
- * Update the permissions in HTML Tree
203
- * @param {Object} item - the tree item
204
- * @return {Object} - item with permissions
205
- */
206
- function updatePermissions(item) {
207
- const isAssets = (item.uri || item.path || '').includes('mediamanager');
208
- let permissions = {
209
- read: true,
210
- write: true,
211
- preview: true,
212
- download: true,
213
- upload: true,
214
- delete: true
215
- };
216
- if (item.permissions) {
217
- if (!item.permissions.includes('READ')) {
218
- permissions.read = false;
219
- }
220
- if (!item.permissions.includes('WRITE')) {
221
- permissions.write = false;
222
- }
223
- // Atomic permissions for Assets
224
- if (isAssets) {
225
- if (!item.permissions.includes('PREVIEW')) {
226
- permissions.preview = false;
227
- }
228
- if (!item.permissions.includes('DOWNLOAD')) {
229
- permissions.download = false;
230
- }
231
- if (!item.permissions.includes('UPLOAD')) {
232
- permissions.upload = false;
233
- }
234
- if (!item.permissions.includes('DELETE')) {
235
- permissions.delete = false;
236
- }
237
- // Generic permissions for item gallery media
238
- } else {
239
- if (!permissions.read) {
240
- permissions.preview = false;
241
- permissions.download = false;
242
- }
243
- if (!permissions.write) {
244
- permissions.delete = false;
245
- permissions.upload = false;
246
- }
247
- }
248
- }
249
- item.permissions = permissions;
250
- return item;
251
- }
233
+ //internal event to set the file-selector content
234
+ updateSelectedClass(fullPath, subTree.total, $selected.data('children-limit'));
235
+ $container.trigger(`folderselect.${ns}`, [content.label, getPage(content.children), content.path, content]);
236
+ renderPagination();
237
+ }
238
+ });
239
+ });
240
+ $container.on(`filenew.${ns}`, function (e, file, path) {
241
+ const subTree = getByPath(fileTree, path);
242
+ if (subTree) {
243
+ if (!subTree.children) {
244
+ subTree.children = [];
245
+ }
246
+ if (root !== 'local' || !_.find(subTree.children, {
247
+ name: file.name
248
+ })) {
249
+ updatePermissions(file);
250
+ if (subTree.children.length === subTree.total) {
251
+ // all children loaded new file can be pushed to the end of tree
252
+ // if not all, new file will be loaded with next page
253
+ subTree.children.push(file);
254
+ }
255
+ subTree.total++;
256
+ selectedClass.total++;
257
+ $container.trigger(`folderselect.${ns}`, [subTree.label, getPage(subTree.children), path]);
258
+ renderPagination();
259
+ }
260
+ }
261
+ });
262
+ $container.on(`filedelete.${ns}`, function (e, path) {
263
+ if (removeFromPath(fileTree, path)) {
264
+ selectedClass.total--;
265
+ loadPage();
266
+ }
267
+ });
268
+ /**
269
+ * Get files for page
270
+ * @param {Array} children
271
+ * @returns {Array} files for this page
272
+ */
273
+ function getPage(children) {
274
+ const files = _.filter(children, function (item) {
275
+ return !!item.uri;
276
+ });
277
+ if (selectedClass.childrenLimit) {
278
+ return files.slice((selectedClass.page - 1) * selectedClass.childrenLimit, selectedClass.page * selectedClass.childrenLimit);
279
+ }
280
+ return files;
281
+ }
282
+ /**
283
+ * Get the content of a folder, either in the model or load it
284
+ * @param {Object} tree - the tree model
285
+ * @param {String} path - the folder path (relative to the root)
286
+ * @param {Function} cb - called back with the content in 1st parameter
287
+ */
288
+ function getFolderContent(tree, path, cb) {
289
+ let content = getByPath(tree, path);
290
+ if (!content || !content.children && !content.empty) {
291
+ loadContent(path).then(function (data) {
292
+ if (!tree.path) {
293
+ tree = _.merge(tree, data);
294
+ } else if (data.children) {
295
+ if (!_.find(data.children, 'path')) {
296
+ // no subfolders inside folder
297
+ tree.empty = true;
298
+ }
299
+ setToPath(tree, path, data);
300
+ } else {
301
+ tree.empty = true;
302
+ }
303
+ cb(data);
304
+ });
305
+ } else if (content.children) {
306
+ const files = _.filter(content.children, function (item) {
307
+ return !!item.uri;
308
+ });
309
+ // if files less then total and need toload this page
310
+ if (files.length < selectedClass.total && files.length < selectedClass.page * selectedClass.childrenLimit) {
311
+ loadContent(path).then(function (data) {
312
+ const loadedFiles = _.filter(data.children, function (item) {
313
+ return !!item.uri;
314
+ });
315
+ setToPath(tree, path, {
316
+ children: loadedFiles
317
+ });
318
+ content = getByPath(tree, path);
319
+ cb(content);
320
+ });
321
+ } else {
322
+ cb(content);
323
+ }
324
+ } else {
325
+ cb(content);
326
+ }
327
+ }
252
328
 
253
- /**
254
- * This program is free software; you can redistribute it and/or
255
- * modify it under the terms of the GNU General Public License
256
- * as published by the Free Software Foundation; under version 2
257
- * of the License (non-upgradable).
258
- *
259
- * This program is distributed in the hope that it will be useful,
260
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
261
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
262
- * GNU General Public License for more details.
263
- *
264
- * You should have received a copy of the GNU General Public License
265
- * along with this program; if not, write to the Free Software
266
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
267
- *
268
- * Copyright (c) 2018-2020 (original work) Open Assessment Technologies SA;
269
- */
270
- const ns = 'resourcemgr';
271
- function fileBrowser (options) {
272
- const root = options.root || 'local';
273
- const rootPath = options.path || '/';
274
- const $container = options.$target;
275
- const $fileBrowser = $$1('.file-browser .file-browser-wrapper', $container);
276
- const $divContainer = $$1(`.${root}`, $fileBrowser);
277
- const $folderContainer = $$1('.folders', $divContainer);
278
- const fileTree = {};
279
- // for pagination
280
- let selectedClass = {
281
- path: rootPath,
282
- childrenLimit: 10,
283
- total: 0,
284
- page: 1
285
- };
329
+ /**
330
+ * Get a subTree from a path
331
+ * @param {Object} tree - the tree model
332
+ * @param {String} path - the path (relative to the root)
333
+ * @returns {Object} the subtree that matches the path
334
+ */
335
+ function getByPath(tree, path) {
336
+ let match;
337
+ if (tree) {
338
+ if (tree.path && tree.path.indexOf(path) === 0) {
339
+ match = tree;
340
+ } else if (tree.children) {
341
+ _.forEach(tree.children, function (child) {
342
+ match = getByPath(child, path);
343
+ if (match) {
344
+ return false;
345
+ }
346
+ });
347
+ }
348
+ }
349
+ return match;
350
+ }
286
351
 
287
- //load the content of the ROOT
288
- getFolderContent(fileTree, rootPath, function (content) {
289
- //create the tree node for the ROOT folder by default once the initial content loaded
290
- $folderContainer.append(rootFolderTpl(content));
291
- const $rootNode = $$1('.root-folder', $folderContainer);
292
- //create an inner list and append found elements
293
- const $innerList = $$1('.root ul', $folderContainer);
294
- if (content.children) {
295
- $rootNode.addClass('opened');
296
- }
297
- updateFolders(content, $innerList);
298
- if (content.permissions.read && !options.hasAlreadySelected) {
299
- $$1('.file-browser').find('li.active').removeClass('active');
300
- updateSelectedClass(content.path, content.total, content.childrenLimit);
301
- $container.trigger('folderselect.'.concat(ns), [content.label, getPage(content.children), content.path, content]);
302
- renderPagination();
303
- if (root !== 'local') {
304
- options.hasAlreadySelected = true;
305
- }
306
- }
307
- });
352
+ /**
353
+ * Merge data into at into the subtree
354
+ * @param {Object} tree - the tree model
355
+ * @param {String} path - the path (relative to the root)
356
+ * @param {Object} data - the sbutree to merge at path level
357
+ * @returns {Boolean} true if done
358
+ */
359
+ function setToPath(tree, path, data) {
360
+ let done = false;
361
+ if (tree) {
362
+ if (tree.path === path) {
363
+ tree.children = tree.children ? tree.children.concat(data.children) : data.children;
364
+ tree.total = data.total;
365
+ } else if (tree.children) {
366
+ _.forEach(tree.children, function (child) {
367
+ done = setToPath(child, path, data);
368
+ if (done) {
369
+ return false;
370
+ }
371
+ });
372
+ }
373
+ }
374
+ return done;
375
+ }
376
+ /**
377
+ * Remove file from tree
378
+ * @param {Object} tree - the tree model
379
+ * @param {String} path - the path (relative to the root)
380
+ * @returns {boolean} is file removed
381
+ */
382
+ function removeFromPath(tree, path) {
383
+ let done = false;
384
+ let removed = [];
385
+ if (tree && tree.children) {
386
+ removed = _.remove(tree.children, function (child) {
387
+ return child.path === path || child.name && tree.path + child.name === path || child.uri === path;
388
+ });
389
+ done = removed.length > 0;
390
+ tree.total--;
391
+ if (!done) {
392
+ _.forEach(tree.children, function (child) {
393
+ done = removeFromPath(child, path);
394
+ if (done) {
395
+ return false;
396
+ }
397
+ });
398
+ }
399
+ }
400
+ return done;
401
+ }
308
402
 
309
- // by clicking on the tree (using a live binding because content is not complete yet)
310
- $divContainer.off('click', '.folders a').on('click', '.folders a', function (e) {
311
- e.preventDefault();
312
- const $selected = $$1(this);
313
- const $folders = $$1('.folders li', $fileBrowser);
314
- const fullPath = $selected.data('path');
315
- const subTree = getByPath(fileTree, fullPath);
403
+ /**
404
+ * Get the content of a folder
405
+ * @param {String} path - the folder path
406
+ * @returns {jQuery.Deferred} the defferred object to run done/complete/fail
407
+ */
408
+ function loadContent(path) {
409
+ const parameters = {};
410
+ parameters[options.pathParam] = path;
411
+ return request({
412
+ url: options.browseUrl,
413
+ method: 'GET',
414
+ dataType: 'json',
415
+ data: _.merge(parameters, options.params, {
416
+ childrenOffset: (selectedClass.page - 1) * selectedClass.childrenLimit
417
+ }),
418
+ noToken: true
419
+ }).then(response => response.data).then(response => {
420
+ response = updatePermissions(response);
421
+ if (response.children && response.children.length > 0) {
422
+ response.children.map(responseChildren => updatePermissions(responseChildren));
423
+ }
424
+ return response;
425
+ });
426
+ }
316
427
 
317
- //get the folder content
318
- getFolderContent(subTree, fullPath, function (content) {
319
- if (content) {
320
- //either create the inner list of the content is new or just show it
321
- let $innerList = $selected.siblings('ul');
322
- if (!$innerList.length && content.children && _.find(content.children, 'path') && !content.empty) {
323
- $innerList = $$1('<ul></ul>').insertAfter($selected);
324
- updateFolders(content, $innerList);
325
- $selected.addClass('opened');
326
- } else if ($innerList.length) {
327
- if ($innerList.css('display') === 'none') {
328
- $innerList.show();
329
- $selected.addClass('opened');
330
- } else if ($selected.parent('li').hasClass('active')) {
331
- $innerList.hide();
332
- $selected.removeClass('opened');
333
- }
334
- }
428
+ /**
429
+ * Update the HTML Tree
430
+ * @param {Object} data - the tree data
431
+ * @param {jQueryElement} $parent - the parent node to append the data
432
+ * @param {Boolean} [recurse] - internal recursive condition
433
+ */
434
+ function updateFolders(data, $parent, recurse) {
435
+ if (recurse && data && data.path) {
436
+ if (typeof data.relPath === 'undefined') {
437
+ data.relPath = data.path;
438
+ }
439
+ $parent.append(folderTpl(data));
440
+ }
441
+ if (data && data.children && _.isArray(data.children) && !data.empty) {
442
+ _.forEach(data.children, function (child) {
443
+ updateFolders(child, $parent, true);
444
+ });
445
+ }
446
+ }
335
447
 
336
- //toggle active element
337
- $folders.removeClass('active');
338
- $selected.parent('li').addClass('active');
448
+ /**
449
+ * Update the selectedClass
450
+ * @param {String} path - the folder path
451
+ * @param {Number} total - files in class
452
+ * @param {Number} childrenLimit - page size
453
+ */
454
+ function updateSelectedClass(path, total, childrenLimit) {
455
+ selectedClass = {
456
+ path,
457
+ total,
458
+ childrenLimit,
459
+ page: 1
460
+ };
461
+ }
462
+ /**
463
+ * Render pagination
464
+ */
465
+ function renderPagination() {
466
+ const $paginationContainer = $$1('.pagination-bottom', $container);
467
+ $paginationContainer.empty();
468
+ const totalPages = Math.ceil(selectedClass.total / selectedClass.childrenLimit);
469
+ if (selectedClass.total && totalPages > 1) {
470
+ paginationComponent({
471
+ mode: 'simple',
472
+ activePage: selectedClass.page,
473
+ totalPages
474
+ }).on('prev', function () {
475
+ selectedClass.page--;
476
+ loadPage();
477
+ }).on('next', function () {
478
+ selectedClass.page++;
479
+ loadPage();
480
+ }).render($paginationContainer);
481
+ }
482
+ }
483
+ /**
484
+ * Load page
485
+ */
486
+ function loadPage() {
487
+ const subTree = getByPath(fileTree, selectedClass.path);
339
488
 
340
- //internal event to set the file-selector content
341
- updateSelectedClass(fullPath, subTree.total, $selected.data('children-limit'));
342
- $container.trigger(`folderselect.${ns}`, [content.label, getPage(content.children), content.path, content]);
343
- renderPagination();
344
- }
345
- });
346
- });
347
- $container.on(`filenew.${ns}`, function (e, file, path) {
348
- const subTree = getByPath(fileTree, path);
349
- if (subTree) {
350
- if (!subTree.children) {
351
- subTree.children = [];
352
- }
353
- if (root !== 'local' || !_.find(subTree.children, {
354
- name: file.name
355
- })) {
356
- updatePermissions(file);
357
- if (subTree.children.length === subTree.total) {
358
- // all children loaded new file can be pushed to the end of tree
359
- // if not all, new file will be loaded with next page
360
- subTree.children.push(file);
361
- }
362
- subTree.total++;
363
- selectedClass.total++;
364
- $container.trigger(`folderselect.${ns}`, [subTree.label, getPage(subTree.children), path]);
365
- renderPagination();
366
- }
367
- }
368
- });
369
- $container.on(`filedelete.${ns}`, function (e, path) {
370
- if (removeFromPath(fileTree, path)) {
371
- selectedClass.total--;
372
- loadPage();
373
- }
374
- });
375
- /**
376
- * Get files for page
377
- * @param {Array} children
378
- * @returns {Array} files for this page
379
- */
380
- function getPage(children) {
381
- const files = _.filter(children, function (item) {
382
- return !!item.uri;
383
- });
384
- if (selectedClass.childrenLimit) {
385
- return files.slice((selectedClass.page - 1) * selectedClass.childrenLimit, selectedClass.page * selectedClass.childrenLimit);
386
- }
387
- return files;
388
- }
389
- /**
390
- * Get the content of a folder, either in the model or load it
391
- * @param {Object} tree - the tree model
392
- * @param {String} path - the folder path (relative to the root)
393
- * @param {Function} cb - called back with the content in 1st parameter
394
- */
395
- function getFolderContent(tree, path, cb) {
396
- let content = getByPath(tree, path);
397
- if (!content || !content.children && !content.empty) {
398
- loadContent(path).then(function (data) {
399
- if (!tree.path) {
400
- tree = _.merge(tree, data);
401
- } else if (data.children) {
402
- if (!_.find(data.children, 'path')) {
403
- // no subfolders inside folder
404
- tree.empty = true;
405
- }
406
- setToPath(tree, path, data);
407
- } else {
408
- tree.empty = true;
409
- }
410
- cb(data);
411
- });
412
- } else if (content.children) {
413
- const files = _.filter(content.children, function (item) {
414
- return !!item.uri;
415
- });
416
- // if files less then total and need toload this page
417
- if (files.length < selectedClass.total && files.length < selectedClass.page * selectedClass.childrenLimit) {
418
- loadContent(path).then(function (data) {
419
- const loadedFiles = _.filter(data.children, function (item) {
420
- return !!item.uri;
421
- });
422
- setToPath(tree, path, {
423
- children: loadedFiles
424
- });
425
- content = getByPath(tree, path);
426
- cb(content);
427
- });
428
- } else {
429
- cb(content);
430
- }
431
- } else {
432
- cb(content);
433
- }
434
- }
489
+ //get the folder content
490
+ getFolderContent(subTree, selectedClass.path, function (content) {
491
+ if (content) {
492
+ //internal event to set the file-selector content
493
+ $container.trigger(`folderselect.${ns}`, [content.label, getPage(content.children), content.path]);
494
+ }
495
+ });
496
+ }
497
+ }
435
498
 
436
- /**
437
- * Get a subTree from a path
438
- * @param {Object} tree - the tree model
439
- * @param {String} path - the path (relative to the root)
440
- * @returns {Object} the subtree that matches the path
441
- */
442
- function getByPath(tree, path) {
443
- let match;
444
- if (tree) {
445
- if (tree.path && tree.path.indexOf(path) === 0) {
446
- match = tree;
447
- } else if (tree.children) {
448
- _.forEach(tree.children, function (child) {
449
- match = getByPath(child, path);
450
- if (match) {
451
- return false;
452
- }
453
- });
454
- }
455
- }
456
- return match;
457
- }
458
-
459
- /**
460
- * Merge data into at into the subtree
461
- * @param {Object} tree - the tree model
462
- * @param {String} path - the path (relative to the root)
463
- * @param {Object} data - the sbutree to merge at path level
464
- * @returns {Boolean} true if done
465
- */
466
- function setToPath(tree, path, data) {
467
- let done = false;
468
- if (tree) {
469
- if (tree.path === path) {
470
- tree.children = tree.children ? tree.children.concat(data.children) : data.children;
471
- tree.total = data.total;
472
- } else if (tree.children) {
473
- _.forEach(tree.children, function (child) {
474
- done = setToPath(child, path, data);
475
- if (done) {
476
- return false;
477
- }
478
- });
479
- }
480
- }
481
- return done;
482
- }
483
- /**
484
- * Remove file from tree
485
- * @param {Object} tree - the tree model
486
- * @param {String} path - the path (relative to the root)
487
- * @returns {boolean} is file removed
488
- */
489
- function removeFromPath(tree, path) {
490
- let done = false;
491
- let removed = [];
492
- if (tree && tree.children) {
493
- removed = _.remove(tree.children, function (child) {
494
- return child.path === path || child.name && tree.path + child.name === path || child.uri === path;
495
- });
496
- done = removed.length > 0;
497
- tree.total--;
498
- if (!done) {
499
- _.forEach(tree.children, function (child) {
500
- done = removeFromPath(child, path);
501
- if (done) {
502
- return false;
503
- }
504
- });
505
- }
506
- }
507
- return done;
508
- }
509
-
510
- /**
511
- * Get the content of a folder
512
- * @param {String} path - the folder path
513
- * @returns {jQuery.Deferred} the defferred object to run done/complete/fail
514
- */
515
- function loadContent(path) {
516
- const parameters = {};
517
- parameters[options.pathParam] = path;
518
- return request({
519
- url: options.browseUrl,
520
- method: 'GET',
521
- dataType: 'json',
522
- data: _.merge(parameters, options.params, {
523
- childrenOffset: (selectedClass.page - 1) * selectedClass.childrenLimit
524
- }),
525
- noToken: true
526
- }).then(response => response.data).then(response => {
527
- response = updatePermissions(response);
528
- if (response.children && response.children.length > 0) {
529
- response.children.map(responseChildren => updatePermissions(responseChildren));
530
- }
531
- return response;
532
- });
533
- }
534
-
535
- /**
536
- * Update the HTML Tree
537
- * @param {Object} data - the tree data
538
- * @param {jQueryElement} $parent - the parent node to append the data
539
- * @param {Boolean} [recurse] - internal recursive condition
540
- */
541
- function updateFolders(data, $parent, recurse) {
542
- if (recurse && data && data.path) {
543
- if (typeof data.relPath === 'undefined') {
544
- data.relPath = data.path;
545
- }
546
- $parent.append(folderTpl(data));
547
- }
548
- if (data && data.children && _.isArray(data.children) && !data.empty) {
549
- _.forEach(data.children, function (child) {
550
- updateFolders(child, $parent, true);
551
- });
552
- }
553
- }
554
-
555
- /**
556
- * Update the selectedClass
557
- * @param {String} path - the folder path
558
- * @param {Number} total - files in class
559
- * @param {Number} childrenLimit - page size
560
- */
561
- function updateSelectedClass(path, total, childrenLimit) {
562
- selectedClass = {
563
- path,
564
- total,
565
- childrenLimit,
566
- page: 1
567
- };
568
- }
569
- /**
570
- * Render pagination
571
- */
572
- function renderPagination() {
573
- const $paginationContainer = $$1('.pagination-bottom', $container);
574
- $paginationContainer.empty();
575
- const totalPages = Math.ceil(selectedClass.total / selectedClass.childrenLimit);
576
- if (selectedClass.total && totalPages > 1) {
577
- paginationComponent({
578
- mode: 'simple',
579
- activePage: selectedClass.page,
580
- totalPages
581
- }).on('prev', function () {
582
- selectedClass.page--;
583
- loadPage();
584
- }).on('next', function () {
585
- selectedClass.page++;
586
- loadPage();
587
- }).render($paginationContainer);
588
- }
589
- }
590
- /**
591
- * Load page
592
- */
593
- function loadPage() {
594
- const subTree = getByPath(fileTree, selectedClass.path);
595
-
596
- //get the folder content
597
- getFolderContent(subTree, selectedClass.path, function (content) {
598
- if (content) {
599
- //internal event to set the file-selector content
600
- $container.trigger(`folderselect.${ns}`, [content.label, getPage(content.children), content.path]);
601
- }
602
- });
603
- }
604
- }
605
-
606
- return fileBrowser;
499
+ return fileBrowser;
607
500
 
608
501
  });