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

62 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-11-26 17:26:58 +01:00
const Backbone = require('backbone');
const UrlUtil = require('../util/url-util');
const StorageFileListView = Backbone.View.extend({
template: require('templates/storage-file-list.hbs'),
events: {
'click .open-list__file': 'fileClick',
'click .open-list__check-wrap': 'showAllCheckClick'
},
initialize() {
this.allStorageFiles = {};
this.showHiddenFiles = !!this.model.showHiddenFiles;
},
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, ''),
2017-11-26 17:26:58 +01:00
kdbx: UrlUtil.isKdbx(file.name),
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;
this.renderTemplate({
files,
density,
showHiddenFiles: this.showHiddenFiles,
2017-12-04 19:30:55 +01:00
canShowHiddenFiles: canShowHiddenFiles
2017-11-26 17:26:58 +01:00
});
return this;
},
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];
this.trigger('selected', file);
},
showAllCheckClick(e) {
e.stopPropagation();
this.showHiddenFiles = !this.showHiddenFiles;
this.render();
}
});
module.exports = StorageFileListView;