-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] Create new module website_field_autocomplete
- Loading branch information
Showing
7 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
============================ | ||
Website Field - AutoComplete | ||
============================ | ||
|
||
Adds an AutoComplete field for use in Odoo Website. | ||
|
||
This module is somewhat difficult to use on its own in an effort to not require | ||
any dependencies other than website. | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to add an input field matching the below format: | ||
|
||
<input type="text" | ||
class="s_website_autocomplete" | ||
data-queryField="name" | ||
data-displayField="name" | ||
data-limit="5" | ||
data-domain='[["website_published", "=", true]]' | ||
data-model="product.template" | ||
/> | ||
|
||
|
||
+-------------------+--------------------------------------------+------------+----------+ | ||
| Attribute | Description | Default | Required | | ||
+===================+============================================+============+==========+ | ||
| data-model | Model name to query | | True | | ||
+-------------------+--------------------------------------------+------------+----------+ | ||
| data-queryField | Field to query when searching | name | False | | ||
+-------------------+--------------------------------------------+------------+----------+ | ||
| data-displayField | Field to display (defaults to queryField) | queryField | False | | ||
+-------------------+--------------------------------------------+------------+----------+ | ||
| data-limit | Limit results to this many | 10 | False | | ||
+-------------------+--------------------------------------------+------------+----------+ | ||
| data-domain | Additional domain for query | [] | False | | ||
+-------------------+--------------------------------------------+------------+----------+ | ||
|
||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/186/9.0 | ||
|
||
|
||
Known Issues / Road Map | ||
======================= | ||
|
||
* Use of Model/jsonRPC requires a user session. | ||
|
||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/OCA/website/issues>`_. In case of trouble, please | ||
check there if your issue has already been reported. If you spotted it first, | ||
help us smashing it by providing a detailed and welcomed feedback. | ||
|
||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Dave Lasley <dave@laslabs.com> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
To contribute to this module, please visit https://odoo-community.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 LasLabs Inc. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2016 LasLabs Inc. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "Website Field - AutoComplete", | ||
"summary": 'Provides an autocomplete field for Website on any model', | ||
"version": "9.0.1.0.0", | ||
"category": "Website", | ||
"website": "https://laslabs.com/", | ||
"author": "LasLabs", | ||
"license": "AGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"depends": [ | ||
"website", | ||
], | ||
"data": [ | ||
'views/assets.xml', | ||
], | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions
57
website_field_autocomplete/static/src/js/field_autocomplete.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* Copyright 2016 LasLabs Inc. | ||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
*/ | ||
|
||
odoo.define('website_field_autocomplete.field_autocomplete', function(require){ | ||
"use strict"; | ||
|
||
var snippet_animation = require('web_editor.snippets.animation'); | ||
var Model = require('web.Model'); | ||
|
||
snippet_animation.registry.field_autocomplete = snippet_animation.Class.extend({ | ||
|
||
selector: '.s_website_autocomplete', | ||
|
||
start: function() { | ||
|
||
let self = this; | ||
|
||
this.$target.autocomplete({ | ||
source: function(request, response) { | ||
// Must use var, let yields undefined | ||
var QueryModel = new Model(self.$target.data('model')); | ||
let queryField = self.$target.data('queryField'); | ||
if (!queryField) { | ||
queryField = 'name'; | ||
} | ||
let displayField = self.$target.data('displayField'); | ||
if (!displayField) { | ||
displayField = queryField; | ||
} | ||
let limit = self.$target.data('limit'); | ||
if (!limit) { | ||
limit = 10; | ||
} | ||
let domain = [[queryField, 'ilike', request.term]]; | ||
let add_domain = self.$target.data('domain'); | ||
if (add_domain) { | ||
domain = domain.concat(add_domain); | ||
} | ||
QueryModel.call('search_read', [domain, [displayField]], {limit: limit}) | ||
.then(function(records) { | ||
let data = records.reduce(function(a, b) { | ||
a.push(b[displayField]); | ||
return a; | ||
}, []); | ||
response(data); | ||
}); | ||
} | ||
}); | ||
|
||
}, | ||
|
||
}); | ||
|
||
return {field_autocomplete: snippet_animation.registry.field_autocomplete}; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<!-- | ||
Copyright 2016 LasLabs Inc. | ||
@license AGPL-3 or later (http://www.gnu.org/licenses/agpl.html). | ||
--> | ||
|
||
<odoo> | ||
<template id="assets_recaptcha" name="website_form_recaptcha Assets" inherit_id="website.assets_frontend"> | ||
<xpath expr="." position="inside"> | ||
<script src="/website_field_autocomplete/static/src/js/field_autocomplete.js" /> | ||
</xpath> | ||
</template> | ||
</odoo> |