@oat-sa/tao-core-ui 3.20.0 → 3.21.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.
|
@@ -242,7 +242,7 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
|
|
|
242
242
|
$selected.parent('li').addClass('active');
|
|
243
243
|
|
|
244
244
|
//internal event to set the file-selector content
|
|
245
|
-
updateSelectedClass(fullPath,
|
|
245
|
+
updateSelectedClass(fullPath, content.total, content.childrenLimit);
|
|
246
246
|
$container.trigger(`folderselect.${ns}`, [content.label, getPage(content.children), content.path, content]);
|
|
247
247
|
renderPagination();
|
|
248
248
|
}
|
|
@@ -267,9 +267,11 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
|
|
|
267
267
|
// if not all, new file will be loaded with next page
|
|
268
268
|
subTree.children.push(file);
|
|
269
269
|
}
|
|
270
|
-
subTree.total
|
|
271
|
-
selectedClass.
|
|
272
|
-
|
|
270
|
+
subTree.total = Number.isFinite(Number(subTree.total)) ? Number(subTree.total) + 1 : 1;
|
|
271
|
+
if (selectedClass.path === path) {
|
|
272
|
+
selectedClass.total = subTree.total;
|
|
273
|
+
}
|
|
274
|
+
$container.trigger(`folderselect.${ns}`, [subTree.label, getPage(subTree.children), path, subTree]);
|
|
273
275
|
renderPagination();
|
|
274
276
|
}
|
|
275
277
|
}
|
|
@@ -328,7 +330,9 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
|
|
|
328
330
|
return !!item.uri;
|
|
329
331
|
});
|
|
330
332
|
setToPath(tree, path, {
|
|
331
|
-
children: loadedFiles
|
|
333
|
+
children: loadedFiles,
|
|
334
|
+
total: data.total,
|
|
335
|
+
childrenLimit: data.childrenLimit
|
|
332
336
|
});
|
|
333
337
|
content = getByPath(tree, path);
|
|
334
338
|
cb(content);
|
|
@@ -392,7 +396,12 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
|
|
|
392
396
|
if (tree) {
|
|
393
397
|
if (tree.path === path) {
|
|
394
398
|
tree.children = tree.children ? tree.children.concat(data.children) : data.children;
|
|
395
|
-
|
|
399
|
+
if (Object.prototype.hasOwnProperty.call(data, 'total')) {
|
|
400
|
+
tree.total = data.total;
|
|
401
|
+
}
|
|
402
|
+
if (Object.prototype.hasOwnProperty.call(data, 'childrenLimit')) {
|
|
403
|
+
tree.childrenLimit = data.childrenLimit;
|
|
404
|
+
}
|
|
396
405
|
} else if (tree.children) {
|
|
397
406
|
_.forEach(tree.children, function (child) {
|
|
398
407
|
done = setToPath(child, path, data);
|
|
@@ -483,10 +492,12 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
|
|
|
483
492
|
* @param {Number} childrenLimit - page size
|
|
484
493
|
*/
|
|
485
494
|
function updateSelectedClass(path, total, childrenLimit) {
|
|
495
|
+
const normalizedTotal = Number(total);
|
|
496
|
+
const normalizedChildrenLimit = Number(childrenLimit);
|
|
486
497
|
selectedClass = {
|
|
487
498
|
path,
|
|
488
|
-
total,
|
|
489
|
-
childrenLimit,
|
|
499
|
+
total: Number.isFinite(normalizedTotal) && normalizedTotal >= 0 ? normalizedTotal : 0,
|
|
500
|
+
childrenLimit: Number.isFinite(normalizedChildrenLimit) && normalizedChildrenLimit > 0 ? normalizedChildrenLimit : selectedClass.childrenLimit || 10,
|
|
490
501
|
page: 1
|
|
491
502
|
};
|
|
492
503
|
}
|
|
@@ -495,9 +506,14 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
|
|
|
495
506
|
*/
|
|
496
507
|
function renderPagination() {
|
|
497
508
|
const $paginationContainer = $$1('.pagination-bottom', $container);
|
|
509
|
+
const total = Number(selectedClass.total);
|
|
510
|
+
const childrenLimit = Number(selectedClass.childrenLimit);
|
|
498
511
|
$paginationContainer.empty();
|
|
499
|
-
|
|
500
|
-
|
|
512
|
+
if (!Number.isFinite(total) || !Number.isFinite(childrenLimit) || childrenLimit <= 0) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
const totalPages = Math.ceil(total / childrenLimit);
|
|
516
|
+
if (total > 0 && totalPages > 1) {
|
|
501
517
|
paginationComponent({
|
|
502
518
|
mode: 'simple',
|
|
503
519
|
activePage: selectedClass.page,
|
|
@@ -375,19 +375,16 @@ define(['jquery', 'lodash', 'async', 'i18n', 'core/mimetype', 'handlebars', 'lib
|
|
|
375
375
|
function setUpUploader(currentPath) {
|
|
376
376
|
let errors = [];
|
|
377
377
|
let $switcher = $$1('.upload-switcher a', $fileSelector);
|
|
378
|
+
let isUploadMode = false;
|
|
378
379
|
$uploader.on('upload.uploader', function (e, file, result) {
|
|
379
|
-
|
|
380
|
-
if (!path) {
|
|
381
|
-
path = currentPath;
|
|
382
|
-
}
|
|
383
|
-
$container.trigger(`filenew.${ns}`, [result, path]);
|
|
380
|
+
$container.trigger(`filenew.${ns}`, [result, currentPath]);
|
|
384
381
|
});
|
|
385
382
|
$uploader.on('fail.uploader', function (e, file, err) {
|
|
386
383
|
errors.push(__('Unable to upload file %s : %s', file.name, err.message));
|
|
387
384
|
});
|
|
388
385
|
$uploader.on('end.uploader', function () {
|
|
389
386
|
if (errors.length === 0) {
|
|
390
|
-
|
|
387
|
+
setUploadMode(false);
|
|
391
388
|
} else {
|
|
392
389
|
feedback().error(`<ul><li>${errors.join('</li><li>')}</li></ul>`, {
|
|
393
390
|
encodeHtml: false
|
|
@@ -461,8 +458,9 @@ define(['jquery', 'lodash', 'async', 'i18n', 'core/mimetype', 'handlebars', 'lib
|
|
|
461
458
|
uploadUrl: `${options.uploadUrl}?${$$1.param(options.params)}&${options.pathParam}=${currentPath}&relPath=${currentPath}`
|
|
462
459
|
});
|
|
463
460
|
});
|
|
464
|
-
function
|
|
465
|
-
if (
|
|
461
|
+
function setUploadMode(enableUploadMode) {
|
|
462
|
+
if (!enableUploadMode) {
|
|
463
|
+
isUploadMode = false;
|
|
466
464
|
$uploader.hide();
|
|
467
465
|
$fileContainer.show();
|
|
468
466
|
// Note: show() would display as inline, not inline-block!
|
|
@@ -472,6 +470,7 @@ define(['jquery', 'lodash', 'async', 'i18n', 'core/mimetype', 'handlebars', 'lib
|
|
|
472
470
|
$switcher.filter('.listing').hide();
|
|
473
471
|
$browserTitle.text(__('Browse folders:'));
|
|
474
472
|
} else {
|
|
473
|
+
isUploadMode = true;
|
|
475
474
|
$fileContainer.hide();
|
|
476
475
|
$placeholder.hide();
|
|
477
476
|
$uploader.show();
|
|
@@ -487,8 +486,13 @@ define(['jquery', 'lodash', 'async', 'i18n', 'core/mimetype', 'handlebars', 'lib
|
|
|
487
486
|
//switch to upload mode
|
|
488
487
|
$switcher.click(function (e) {
|
|
489
488
|
e.preventDefault();
|
|
490
|
-
|
|
489
|
+
if ($$1(this).hasClass('upload')) {
|
|
490
|
+
setUploadMode(true);
|
|
491
|
+
} else if ($$1(this).hasClass('listing')) {
|
|
492
|
+
setUploadMode(false);
|
|
493
|
+
}
|
|
491
494
|
});
|
|
495
|
+
setUploadMode(isUploadMode);
|
|
492
496
|
}
|
|
493
497
|
function updateFiles(path, files) {
|
|
494
498
|
$fileContainer.empty();
|
package/package.json
CHANGED
|
@@ -107,7 +107,7 @@ export default function (options) {
|
|
|
107
107
|
$selected.parent('li').addClass('active');
|
|
108
108
|
|
|
109
109
|
//internal event to set the file-selector content
|
|
110
|
-
updateSelectedClass(fullPath,
|
|
110
|
+
updateSelectedClass(fullPath, content.total, content.childrenLimit);
|
|
111
111
|
$container.trigger(`folderselect.${ns}`, [
|
|
112
112
|
content.label,
|
|
113
113
|
getPage(content.children),
|
|
@@ -137,9 +137,11 @@ export default function (options) {
|
|
|
137
137
|
// if not all, new file will be loaded with next page
|
|
138
138
|
subTree.children.push(file);
|
|
139
139
|
}
|
|
140
|
-
subTree.total
|
|
141
|
-
selectedClass.
|
|
142
|
-
|
|
140
|
+
subTree.total = Number.isFinite(Number(subTree.total)) ? Number(subTree.total) + 1 : 1;
|
|
141
|
+
if (selectedClass.path === path) {
|
|
142
|
+
selectedClass.total = subTree.total;
|
|
143
|
+
}
|
|
144
|
+
$container.trigger(`folderselect.${ns}`, [subTree.label, getPage(subTree.children), path, subTree]);
|
|
143
145
|
renderPagination();
|
|
144
146
|
}
|
|
145
147
|
}
|
|
@@ -201,7 +203,11 @@ export default function (options) {
|
|
|
201
203
|
const loadedFiles = _.filter(data.children, function (item) {
|
|
202
204
|
return !!item.uri;
|
|
203
205
|
});
|
|
204
|
-
setToPath(tree, path, {
|
|
206
|
+
setToPath(tree, path, {
|
|
207
|
+
children: loadedFiles,
|
|
208
|
+
total: data.total,
|
|
209
|
+
childrenLimit: data.childrenLimit
|
|
210
|
+
});
|
|
205
211
|
content = getByPath(tree, path);
|
|
206
212
|
cb(content);
|
|
207
213
|
});
|
|
@@ -263,7 +269,12 @@ export default function (options) {
|
|
|
263
269
|
if (tree) {
|
|
264
270
|
if (tree.path === path) {
|
|
265
271
|
tree.children = tree.children ? tree.children.concat(data.children) : data.children;
|
|
266
|
-
|
|
272
|
+
if (Object.prototype.hasOwnProperty.call(data, 'total')) {
|
|
273
|
+
tree.total = data.total;
|
|
274
|
+
}
|
|
275
|
+
if (Object.prototype.hasOwnProperty.call(data, 'childrenLimit')) {
|
|
276
|
+
tree.childrenLimit = data.childrenLimit;
|
|
277
|
+
}
|
|
267
278
|
} else if (tree.children) {
|
|
268
279
|
_.forEach(tree.children, function (child) {
|
|
269
280
|
done = setToPath(child, path, data);
|
|
@@ -356,10 +367,16 @@ export default function (options) {
|
|
|
356
367
|
* @param {Number} childrenLimit - page size
|
|
357
368
|
*/
|
|
358
369
|
function updateSelectedClass(path, total, childrenLimit) {
|
|
370
|
+
const normalizedTotal = Number(total);
|
|
371
|
+
const normalizedChildrenLimit = Number(childrenLimit);
|
|
372
|
+
|
|
359
373
|
selectedClass = {
|
|
360
374
|
path,
|
|
361
|
-
total,
|
|
362
|
-
childrenLimit
|
|
375
|
+
total: Number.isFinite(normalizedTotal) && normalizedTotal >= 0 ? normalizedTotal : 0,
|
|
376
|
+
childrenLimit:
|
|
377
|
+
Number.isFinite(normalizedChildrenLimit) && normalizedChildrenLimit > 0
|
|
378
|
+
? normalizedChildrenLimit
|
|
379
|
+
: selectedClass.childrenLimit || 10,
|
|
363
380
|
page: 1
|
|
364
381
|
};
|
|
365
382
|
}
|
|
@@ -368,10 +385,18 @@ export default function (options) {
|
|
|
368
385
|
*/
|
|
369
386
|
function renderPagination() {
|
|
370
387
|
const $paginationContainer = $('.pagination-bottom', $container);
|
|
388
|
+
const total = Number(selectedClass.total);
|
|
389
|
+
const childrenLimit = Number(selectedClass.childrenLimit);
|
|
390
|
+
|
|
371
391
|
$paginationContainer.empty();
|
|
372
|
-
const totalPages = Math.ceil(selectedClass.total / selectedClass.childrenLimit);
|
|
373
392
|
|
|
374
|
-
if (
|
|
393
|
+
if (!Number.isFinite(total) || !Number.isFinite(childrenLimit) || childrenLimit <= 0) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const totalPages = Math.ceil(total / childrenLimit);
|
|
398
|
+
|
|
399
|
+
if (total > 0 && totalPages > 1) {
|
|
375
400
|
paginationComponent({
|
|
376
401
|
mode: 'simple',
|
|
377
402
|
activePage: selectedClass.page,
|
|
@@ -231,14 +231,10 @@ export default function (options) {
|
|
|
231
231
|
function setUpUploader(currentPath) {
|
|
232
232
|
let errors = [];
|
|
233
233
|
let $switcher = $('.upload-switcher a', $fileSelector);
|
|
234
|
+
let isUploadMode = false;
|
|
234
235
|
|
|
235
236
|
$uploader.on('upload.uploader', function (e, file, result) {
|
|
236
|
-
|
|
237
|
-
$(`[data-display="${currentPath}"]`).data('path') || $(`[data-display="/${currentPath}"]`).data('path');
|
|
238
|
-
if (!path) {
|
|
239
|
-
path = currentPath;
|
|
240
|
-
}
|
|
241
|
-
$container.trigger(`filenew.${ns}`, [result, path]);
|
|
237
|
+
$container.trigger(`filenew.${ns}`, [result, currentPath]);
|
|
242
238
|
});
|
|
243
239
|
$uploader.on('fail.uploader', function (e, file, err) {
|
|
244
240
|
errors.push(__('Unable to upload file %s : %s', file.name, err.message));
|
|
@@ -246,7 +242,7 @@ export default function (options) {
|
|
|
246
242
|
|
|
247
243
|
$uploader.on('end.uploader', function () {
|
|
248
244
|
if (errors.length === 0) {
|
|
249
|
-
|
|
245
|
+
setUploadMode(false);
|
|
250
246
|
} else {
|
|
251
247
|
feedback().error(`<ul><li>${errors.join('</li><li>')}</li></ul>`, { encodeHtml: false });
|
|
252
248
|
}
|
|
@@ -333,8 +329,9 @@ export default function (options) {
|
|
|
333
329
|
});
|
|
334
330
|
});
|
|
335
331
|
|
|
336
|
-
function
|
|
337
|
-
if (
|
|
332
|
+
function setUploadMode(enableUploadMode) {
|
|
333
|
+
if (!enableUploadMode) {
|
|
334
|
+
isUploadMode = false;
|
|
338
335
|
$uploader.hide();
|
|
339
336
|
$fileContainer.show();
|
|
340
337
|
// Note: show() would display as inline, not inline-block!
|
|
@@ -342,6 +339,7 @@ export default function (options) {
|
|
|
342
339
|
$switcher.filter('.listing').hide();
|
|
343
340
|
$browserTitle.text(__('Browse folders:'));
|
|
344
341
|
} else {
|
|
342
|
+
isUploadMode = true;
|
|
345
343
|
$fileContainer.hide();
|
|
346
344
|
$placeholder.hide();
|
|
347
345
|
$uploader.show();
|
|
@@ -355,8 +353,14 @@ export default function (options) {
|
|
|
355
353
|
//switch to upload mode
|
|
356
354
|
$switcher.click(function (e) {
|
|
357
355
|
e.preventDefault();
|
|
358
|
-
|
|
356
|
+
if ($(this).hasClass('upload')) {
|
|
357
|
+
setUploadMode(true);
|
|
358
|
+
} else if ($(this).hasClass('listing')) {
|
|
359
|
+
setUploadMode(false);
|
|
360
|
+
}
|
|
359
361
|
});
|
|
362
|
+
|
|
363
|
+
setUploadMode(isUploadMode);
|
|
360
364
|
}
|
|
361
365
|
|
|
362
366
|
function updateFiles(path, files) {
|