2018-01-23 12:26:40 +00:00
|
|
|
const frappe = require('frappejs');
|
|
|
|
const BaseControl = require('./base');
|
|
|
|
const Awesomplete = require('awesomplete');
|
|
|
|
|
|
|
|
class LinkControl extends BaseControl {
|
|
|
|
make() {
|
|
|
|
super.make();
|
2018-01-23 12:31:09 +00:00
|
|
|
this.input.setAttribute('type', 'text');
|
|
|
|
this.awesomplete = new Awesomplete(this.input, {
|
|
|
|
autoFirst: true,
|
|
|
|
minChars: 0,
|
|
|
|
maxItems: 99
|
|
|
|
});
|
2018-01-23 12:26:40 +00:00
|
|
|
|
2018-01-23 12:31:09 +00:00
|
|
|
// rebuild the list on input
|
|
|
|
this.input.addEventListener('input', async (event) => {
|
2018-02-08 09:38:47 +00:00
|
|
|
this.awesomplete.list = await this.getList(this.input.value);
|
2018-01-23 12:31:09 +00:00
|
|
|
});
|
2018-01-23 12:26:40 +00:00
|
|
|
}
|
2018-01-23 12:48:27 +00:00
|
|
|
|
2018-02-08 09:38:47 +00:00
|
|
|
async getList(query) {
|
2018-02-08 06:46:38 +00:00
|
|
|
return (await frappe.db.getAll({
|
2018-01-31 12:56:21 +00:00
|
|
|
doctype: this.target,
|
2018-02-08 09:38:47 +00:00
|
|
|
filters: this.getFilters(query),
|
2018-01-23 12:48:27 +00:00
|
|
|
limit: 50
|
|
|
|
})).map(d => d.name);
|
|
|
|
}
|
|
|
|
|
2018-02-08 09:38:47 +00:00
|
|
|
getFilters(query) {
|
2018-01-23 12:48:27 +00:00
|
|
|
return { keywords: ["like", query] }
|
|
|
|
}
|
2018-01-23 12:26:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = LinkControl;
|