2
0
mirror of https://github.com/frappe/books.git synced 2024-12-25 20:11:15 +00:00
books/client/view/controls/file.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-03-30 16:56:30 +00:00
const frappe = require('frappejs');
2018-03-29 18:51:24 +00:00
const BaseControl = require('./base');
class FileControl extends BaseControl {
make() {
super.make();
2018-03-30 16:56:30 +00:00
this.fileButton = frappe.ui.create('button', {
className: 'btn btn-outline-secondary btn-block',
inside: this.getInputParent(),
2018-04-02 17:07:56 +00:00
type: 'button',
2018-03-30 16:56:30 +00:00
textContent: 'Choose a file...',
onclick: () => {
this.input.click();
}
});
2018-03-29 18:51:24 +00:00
this.input.setAttribute('type', 'file');
2018-03-30 16:56:30 +00:00
if (this.directory) {
this.input.setAttribute('webkitdirectory', '');
}
if (this.allowMultiple) {
this.input.setAttribute('multiple', '');
}
}
async handleChange() {
await super.handleChange();
this.setDocValue();
}
getInputValue() {
return this.input.files;
}
setInputValue(files) {
let label;
if (!files || files.length === 0) {
label = 'Choose a file...'
} else if (files.length === 1) {
label = files[0].name;
} else {
label = `${files.length} files selected`;
}
this.fileButton.textContent = label;
this.input.files = files;
2018-03-29 18:51:24 +00:00
}
};
module.exports = FileControl;