2016-10-09 13:17:00 +08:00
|
|
|
/* jshint esversion: 6 */
|
|
|
|
|
2021-05-07 20:57:15 +08:00
|
|
|
let $select = $(".multi-select");
|
2016-10-09 13:17:00 +08:00
|
|
|
|
2021-11-16 21:17:19 +08:00
|
|
|
$select.on("change-files", (e, files) => {
|
2021-11-16 18:09:55 +08:00
|
|
|
$(".multi-files-value").val(JSON.stringify(files.map((f) => f.name)));
|
|
|
|
if (files.length == 0) {
|
|
|
|
$(".multi-files").html(
|
|
|
|
`<li class="list-group-item text-muted">No files selected</li>`
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$(".multi-files").html(
|
|
|
|
files
|
|
|
|
.map((f) => {
|
2021-11-16 21:17:19 +08:00
|
|
|
const badge = `<span class="badge rounded-pill bg-secondary badge-alignment">
|
|
|
|
${filesize(f.size)}
|
|
|
|
</span>`;
|
2021-11-16 18:09:55 +08:00
|
|
|
return `
|
2021-11-16 21:17:19 +08:00
|
|
|
<li class="list-group-item d-flex align-items-start justify-content-between">
|
|
|
|
<span class="name">${htmlEscape(f.name)}</span>
|
|
|
|
${f.type == "directory" ? `` : badge}
|
|
|
|
</li>
|
|
|
|
`;
|
2021-11-16 18:09:55 +08:00
|
|
|
})
|
|
|
|
.join("")
|
|
|
|
);
|
|
|
|
const hasDirectory = files.reduce(
|
|
|
|
(a, f) => a || f.type == "directory",
|
|
|
|
false
|
|
|
|
);
|
|
|
|
const totalSize = files.map((f) => f.size).reduce((a, b) => a + b);
|
|
|
|
if (hasDirectory) {
|
|
|
|
$(".multi-files-total").val("");
|
|
|
|
} else {
|
|
|
|
$(".multi-files-total").val(filesize(totalSize));
|
|
|
|
}
|
2021-11-16 21:17:19 +08:00
|
|
|
});
|
2016-10-09 13:17:00 +08:00
|
|
|
|
2021-05-07 20:57:15 +08:00
|
|
|
const updateSelected = () => {
|
2021-11-16 18:09:55 +08:00
|
|
|
let $selected = $(".multi-select:checked");
|
|
|
|
let files = [];
|
|
|
|
$selected.each((i, ele) => {
|
|
|
|
files.push({
|
|
|
|
name: $(ele).data("select"),
|
|
|
|
type: $(ele).data("select-type"),
|
|
|
|
size: $(ele).data("select-size"),
|
|
|
|
});
|
|
|
|
});
|
2018-02-15 00:31:29 +08:00
|
|
|
|
2021-11-16 21:17:19 +08:00
|
|
|
$select.trigger("change-files", [files]);
|
2021-11-16 18:09:55 +08:00
|
|
|
};
|
2021-05-07 20:57:15 +08:00
|
|
|
|
|
|
|
$select.on("change", updateSelected);
|
|
|
|
updateSelected();
|