1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-25 07:37:46 +02:00
keeweb/app/scripts/views/storage-file-list-view.js

63 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-09-15 23:41:00 +02:00
import { View } from 'view-engine/view';
2019-09-15 14:16:32 +02:00
import { UrlFormat } from 'util/formatting/url-format';
2019-09-15 23:41:00 +02:00
import template from 'templates/storage-file-list.hbs';
2017-11-26 17:26:58 +01:00
2019-09-15 23:41:00 +02:00
class StorageFileListView extends View {
template = template;
2017-11-26 17:26:58 +01:00
2019-09-15 23:41:00 +02:00
events = {
2017-11-26 17:26:58 +01:00
'click .open-list__file': 'fileClick',
'click .open-list__check-wrap': 'showAllCheckClick'
2019-09-15 23:41:00 +02:00
};
2017-11-26 17:26:58 +01:00
2019-09-15 23:41:00 +02:00
constructor(model) {
super(model);
2017-11-26 17:26:58 +01:00
this.allStorageFiles = {};
this.showHiddenFiles = !!this.model.showHiddenFiles;
2019-09-15 23:41:00 +02:00
}
2017-11-26 17:26:58 +01:00
render() {
let files = this.model.files.map(file => {
this.allStorageFiles[file.path] = file;
return {
path: file.path,
2017-12-04 19:30:55 +01:00
name: file.name.replace(/\.kdbx$/i, ''),
2019-09-15 08:11:11 +02:00
kdbx: UrlFormat.isKdbx(file.name),
2017-11-26 17:26:58 +01:00
dir: file.dir
};
});
2017-12-04 19:30:55 +01:00
const visibleFiles = files.filter(f => !f.dir && f.kdbx);
const canShowHiddenFiles = visibleFiles.length && files.length > visibleFiles.length;
2017-11-26 17:26:58 +01:00
if (!this.showHiddenFiles) {
2017-11-26 21:43:36 +01:00
if (visibleFiles.length > 0) {
files = visibleFiles;
} else {
this.showHiddenFiles = true;
}
2017-11-26 17:26:58 +01:00
}
const density = files.length > 14 ? 3 : files.length > 7 ? 2 : 1;
2019-09-15 23:41:00 +02:00
super.render({
2017-11-26 17:26:58 +01:00
files,
density,
showHiddenFiles: this.showHiddenFiles,
2019-08-18 10:17:09 +02:00
canShowHiddenFiles
2017-11-26 17:26:58 +01:00
});
2019-09-15 23:41:00 +02:00
}
2017-11-26 17:26:58 +01:00
fileClick(e) {
2019-08-16 23:05:39 +02:00
const result = $(e.target)
.closest('.open-list__file')
.data('path');
2017-11-26 17:26:58 +01:00
const file = this.allStorageFiles[result];
2019-09-15 23:41:00 +02:00
this.emit('selected', file);
}
2017-11-26 17:26:58 +01:00
showAllCheckClick(e) {
e.stopPropagation();
this.showHiddenFiles = !this.showHiddenFiles;
this.render();
}
2019-09-15 23:41:00 +02:00
}
2017-11-26 17:26:58 +01:00
2019-09-15 14:16:32 +02:00
export { StorageFileListView };