2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 11:29:03 +00:00

Add control Autocomplete

This commit is contained in:
Faris Ansari 2018-03-30 22:26:30 +05:30
parent 62718a55db
commit 89736618e6
7 changed files with 77 additions and 4 deletions

View File

@ -429,7 +429,8 @@ module.exports = class Database extends Observable {
initTypeMap() { initTypeMap() {
this.typeMap = { this.typeMap = {
'Currency': 'real' 'Autocomplete': 'text'
, 'Currency': 'real'
, 'Int': 'integer' , 'Int': 'integer'
, 'Float': 'real' , 'Float': 'real'
, 'Percent': 'real' , 'Percent': 'real'

View File

@ -116,7 +116,8 @@ module.exports = class HTTPClient extends Observable {
initTypeMap() { initTypeMap() {
this.typeMap = { this.typeMap = {
'Currency': true 'Autocomplete': true
, 'Currency': true
, 'Int': true , 'Int': true
, 'Float': true , 'Float': true
, 'Percent': true , 'Percent': true

View File

@ -178,7 +178,8 @@ module.exports = class mysqlDatabase extends Database{
init_typeMap() { init_typeMap() {
this.typeMap = { this.typeMap = {
'Currency': 'real' 'Autocomplete': 'VARCHAR(140)'
, 'Currency': 'real'
, 'Int': 'INT' , 'Int': 'INT'
, 'Float': 'decimal(18,6)' , 'Float': 'decimal(18,6)'
, 'Percent': 'real' , 'Percent': 'real'

View File

@ -215,7 +215,8 @@ module.exports = class sqliteDatabase extends Database {
initTypeMap() { initTypeMap() {
this.typeMap = { this.typeMap = {
'Currency': 'real' 'Autocomplete': 'text'
, 'Currency': 'real'
, 'Int': 'integer' , 'Int': 'integer'
, 'Float': 'real' , 'Float': 'real'
, 'Percent': 'real' , 'Percent': 'real'

View File

@ -0,0 +1,25 @@
const BaseControl = require('./base');
const Awesomplete = require('awesomplete');
class AutocompleteControl extends BaseControl {
make() {
super.make();
this.input.setAttribute('type', 'text');
this.setupAwesomplete();
}
setupAwesomplete() {
this.awesomplete = new Awesomplete(this.input, {
minChars: 0,
maxItems: 99
});
// rebuild the list on input
this.input.addEventListener('input', async (event) => {
let list = await this.getList();
this.awesomplete.list = list;
});
}
};
module.exports = AutocompleteControl;

View File

@ -1,9 +1,51 @@
const frappe = require('frappejs');
const BaseControl = require('./base'); const BaseControl = require('./base');
class FileControl extends BaseControl { class FileControl extends BaseControl {
make() { make() {
super.make(); super.make();
this.fileButton = frappe.ui.create('button', {
className: 'btn btn-outline-secondary btn-block',
inside: this.getInputParent(),
textContent: 'Choose a file...',
onclick: () => {
this.input.click();
}
});
this.input.setAttribute('type', 'file'); this.input.setAttribute('type', 'file');
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;
} }
}; };

View File

@ -1,4 +1,5 @@
const controlClasses = { const controlClasses = {
Autocomplete: require('./autocomplete'),
Check: require('./check'), Check: require('./check'),
Code: require('./code'), Code: require('./code'),
Data: require('./data'), Data: require('./data'),
@ -6,6 +7,7 @@ const controlClasses = {
DynamicLink: require('./dynamicLink'), DynamicLink: require('./dynamicLink'),
Currency: require('./currency'), Currency: require('./currency'),
Float: require('./float'), Float: require('./float'),
File: require('./file'),
Int: require('./int'), Int: require('./int'),
Link: require('./link'), Link: require('./link'),
Password: require('./password'), Password: require('./password'),