forked from OCA/website
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NEW][8.0] website_snippet_country_dropdown: New base module for coun…
…try dropdown flags.
- Loading branch information
1 parent
437bc28
commit 6cf3127
Showing
12 changed files
with
414 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,73 @@ | ||
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
|
||
=============================== | ||
Snippet's dropdown country code | ||
=============================== | ||
|
||
This module adds a snippet with a dropdown and an input text field, is a base | ||
for be inherited by others modules into an HTML form. | ||
|
||
This can be inserted into form elements. | ||
|
||
Usage | ||
===== | ||
|
||
To extend this template you need to inherit *country_dropdown* template and to | ||
add you personal code. | ||
|
||
The template have three input text: | ||
|
||
#. no_country_field: Field without code country. | ||
#. country_code_field: Field with only country code (read only) | ||
#. complete_field: Field with the previous two joined (hidden) | ||
|
||
The name of the complete field is customizable when user insert the snippet | ||
into a form element with the website editor. | ||
|
||
You can view an example in e-commerce/website_sale_checkout_country_vat. | ||
|
||
.. 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/8.0 | ||
|
||
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 | ||
<https://github.com/OCA/ | ||
website/issues/new?body=module:%20 | ||
website_snippet_country_dropdown%0Aversion:%20 | ||
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Sergio Teruel <[email protected]> | ||
|
||
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 http://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 -*- | ||
# © 2016 Sergio Teruel <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). |
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,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Sergio Teruel <[email protected]> | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
{ | ||
"name": "Website Snippet Country Dropdown Code", | ||
"summary": "Allow to select country in a dropdown", | ||
"version": "8.0.1.0.0", | ||
"category": "Website", | ||
"website": "http://www.tecnativa.com", | ||
"author": "Tecnativa, " | ||
"Odoo Community Association (OCA)", | ||
"license": "LGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"depends": [ | ||
"website", | ||
], | ||
'qweb': ['static/src/xml/*.xml'], | ||
"data": [ | ||
"views/assets.xml", | ||
"views/snippets.xml", | ||
], | ||
} |
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,67 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * website_snippet_country_dropdown | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 8.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2016-06-25 16:18+0000\n" | ||
"PO-Revision-Date: 2016-06-25 18:21+0100\n" | ||
"Last-Translator: Sergio Teruel <[email protected]>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Language: es_ES\n" | ||
"X-Generator: Poedit 1.5.4\n" | ||
|
||
#. module: website_snippet_country_dropdown | ||
#: view:website:website.snippets | ||
msgid "Country Dropdown" | ||
msgstr "Selector de país desplegable" | ||
|
||
#. module: website_snippet_country_dropdown | ||
#. openerp-web | ||
#: code:addons/website_snippet_country_dropdown/static/src/js/website_snippet_country_dropdown.editor.js:17 | ||
#, python-format | ||
msgid "Country Dropdown Options" | ||
msgstr "Opciones del desplegable" | ||
|
||
#. module: website_snippet_country_dropdown | ||
#. openerp-web | ||
#: code:addons/website_snippet_country_dropdown/static/src/js/website_snippet_country_dropdown.editor.js:18 | ||
#, python-format | ||
msgid "Field name value" | ||
msgstr "Nombre del campo" | ||
|
||
#. module: website_snippet_country_dropdown | ||
#. openerp-web | ||
#: code:addons/website_snippet_country_dropdown/static/src/xml/country_dropdown.xml:10 | ||
#, python-format | ||
msgid "Helper!" | ||
msgstr "¡Ayuda!" | ||
|
||
#. module: website_snippet_country_dropdown | ||
#: view:website:website.snippets | ||
msgid "Set input options" | ||
msgstr "Opciones" | ||
|
||
#. module: website_snippet_country_dropdown | ||
#. openerp-web | ||
#: code:addons/website_snippet_country_dropdown/static/src/xml/country_dropdown.xml:12 | ||
#, python-format | ||
msgid "Write de attribute name for the input what will be sent with a form." | ||
msgstr "Escribe el attributo name del campo que será enviado por POST" | ||
|
||
#. module: website_snippet_country_dropdown | ||
#. openerp-web | ||
#: code:addons/website_snippet_country_dropdown/static/src/xml/country_dropdown.xml:13 | ||
#, python-format | ||
msgid "You can modify the label directly with website editor." | ||
msgstr "La etiqueta la puedes modificar directamente en el editor del website" | ||
|
||
#. module: website_snippet_country_dropdown | ||
#: view:website:website_snippet_country_dropdown.dropdown_element_form | ||
msgid "Your Label" | ||
msgstr "Tu etiqueta" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
/* © 2016 Tecnativa, S.L. | ||
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). | ||
*/ | ||
|
||
.scrollable-menu { | ||
height: auto; | ||
max-height: 200px; | ||
overflow-x: hidden; | ||
} | ||
|
||
#country_code_field{ | ||
width: 15%; | ||
} | ||
|
||
#no_country_field{ | ||
width: 85%; | ||
} | ||
|
||
.flag-button{ | ||
width: 15%; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions
50
website_snippet_country_dropdown/static/src/js/website_snippet_country_dropdown.editor.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,50 @@ | ||
/* © 2016 Tecnativa, S.L. | ||
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). | ||
*/ | ||
'use strict'; | ||
|
||
(function ($) { | ||
var website = openerp.website; | ||
var qweb = openerp.qweb; | ||
var _t = openerp._t; | ||
website.add_template_file('/website_snippet_country_dropdown/static/src/xml/country_dropdown.xml'); | ||
|
||
website.snippet.options.website_snippet_country_dropdown = website.snippet.Option.extend({ | ||
on_prompt: function () { | ||
var self = this; | ||
return website.prompt({ | ||
id: "editor_website_snippet_country_dropdown", | ||
window_title: _t("Country Dropdown Options"), | ||
input: _t("Field name value"), | ||
init: function() { | ||
// Render tempate | ||
var $my_form = $('#editor_website_snippet_country_dropdown'); | ||
var $group = this.$dialog.find("div.form-group"); | ||
var $add = $(qweb.render('dropdown_country_helper',{})); | ||
$my_form.append($add); | ||
}, | ||
}).then(function (complete_field_value) { | ||
var $inputField = self.$target.find("#complete_field") | ||
if (complete_field_value){ | ||
$inputField.attr("data-cke-saved-name", complete_field_value); | ||
} else{ | ||
// Write default value | ||
if ($inputField.attr('name') != 'complete_field'){ | ||
$inputField.attr("data-cke-saved-name", 'complete_field'); | ||
}; | ||
}; | ||
}); | ||
}, | ||
drop_and_build_snippet: function() { | ||
var self = this; | ||
this._super(); | ||
this.on_prompt().fail(function () { | ||
self.editor.on_remove(); | ||
}); | ||
}, | ||
start : function () { | ||
this.$el.find(".js_dropdown_fields").on("click", _.bind(this.on_prompt, this)); | ||
this._super(); | ||
}, | ||
}); | ||
})(jQuery); |
40 changes: 40 additions & 0 deletions
40
website_snippet_country_dropdown/static/src/js/website_snippet_country_dropdown.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,40 @@ | ||
/* © 2016 Tecnativa, S.L. | ||
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). | ||
*/ | ||
'use strict'; | ||
(function ($) { | ||
var website = openerp.website, | ||
qweb = openerp.qweb; | ||
|
||
website.snippet.animationRegistry.countryDropdown = website.snippet.Animation.extend({ | ||
selector: ".js_country_dropdown", | ||
start: function () { | ||
this.$flag_selector = this.$('.js_select_country_code'); | ||
this.$img_code = this.$('.js_img_country_code'); | ||
this.$btn_country_code = this.$('.js_btn_country_code'); | ||
this.$country_code = this.$('.js_country_code'); | ||
this.$country_code_field = this.$('.js_country_code_field'); | ||
this.$no_country_field = this.$('.js_no_country_field'); | ||
this.$complete_field_post = this.$('.js_complete_field_post'); | ||
var self = this; | ||
this.$flag_selector.on('click', function(event) { | ||
return self.set_value(event); | ||
}); | ||
this.$no_country_field.change(function(event){ | ||
return self.join_value(self.$country_code_field.val(), this.value); | ||
}); | ||
}, | ||
set_value: function(event){ | ||
this.country_code = event.currentTarget.id; | ||
this.$flag_selector.val(event.currentTarget.id); | ||
this.$img_code.attr("src", "/website/image/res.country/"+ event.currentTarget.dataset.country_id +"/image/30x20"); | ||
this.$btn_country_code.val(event.currentTarget.dataset.country_id); | ||
this.$country_code_field.val(event.currentTarget.id); | ||
this.$country_code.children().text(String(event.currentTarget.id)); | ||
this.join_value(event.currentTarget.id, this.$no_country_field.val()); | ||
}, | ||
join_value: function(country_code, value){ | ||
this.$complete_field_post.val(country_code.concat(value)); | ||
} | ||
}); | ||
})(jQuery); |
20 changes: 20 additions & 0 deletions
20
website_snippet_country_dropdown/static/src/xml/country_dropdown.xml
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- © 2016 Sergio Teruel <[email protected]> | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). --> | ||
<templates id="website_snippet_country_dropdown_templates" xml:space="preserve"> | ||
|
||
<t t-name="dropdown_country_helper"> | ||
<div class="row mt8"> | ||
<div class="col-sm-9 col-sm-offset-3"> | ||
<div class="alert alert-info"> | ||
<strong>Helper!</strong> | ||
<ul> | ||
<li><span>Write de attribute name for the input what will be sent with a form.</span></li> | ||
<li><span>You can modify the label directly with website editor.</span></li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</t> | ||
|
||
</templates> |
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,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- © 2016 Sergio Teruel <[email protected]> | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). --> | ||
<openerp> | ||
<data> | ||
|
||
<template id="assets_frontend" | ||
inherit_id="website.assets_frontend" | ||
name="Website Country Dropdown"> | ||
|
||
<xpath expr="." position="inside"> | ||
<script type="text/javascript" | ||
src="/website_snippet_country_dropdown/static/src/js/website_snippet_country_dropdown.js"/> | ||
<link rel="stylesheet" href="/website_snippet_country_dropdown/static/src/css/style.css"/> | ||
</xpath> | ||
|
||
</template> | ||
|
||
<template id="assets_editor" inherit_id="website.assets_editor"> | ||
<xpath expr="."> | ||
<script type="text/javascript" | ||
src="/website_snippet_country_dropdown/static/src/js/website_snippet_country_dropdown.editor.js"/> | ||
</xpath> | ||
</template> | ||
|
||
|
||
</data> | ||
</openerp> |
Oops, something went wrong.