diff --git a/energy_communities/controllers/website_community_data.py b/energy_communities/controllers/website_community_data.py index 4ed4c6abf21bf23695af5b9664cd48f6cdb7a9e8..05275ae8d60e617f78f0d1e03a0ed64e06149fec 100644 --- a/energy_communities/controllers/website_community_data.py +++ b/energy_communities/controllers/website_community_data.py @@ -30,6 +30,7 @@ _COMMUNITY_DATA__GENERAL_FIELDS = { "ce_constitution_state": _("Constitution state"), "ce_constitution_state_other": _("Which one?"), "ce_legal_form": _("Community legal form"), + "ce_constitution_date": _("Constitution date"), } _COMMUNITY_DATA__FIELDS.update(_COMMUNITY_DATA__GENERAL_FIELDS) _COMMUNITY_DATA__IMAGE_FIELDS = { @@ -328,6 +329,8 @@ class WebsiteCommunityData(http.Controller): _COMMUNITY_DATA__IMAGE_FIELDS[image_field_key] ) ) + + # TODO: Date validation!! if error_msgs: values["error"] = error values["error_msgs"] = error_msgs diff --git a/energy_communities/static/src/js/community-data-website.js b/energy_communities/static/src/js/community-data-website.js new file mode 100644 index 0000000000000000000000000000000000000000..a1312429f589b54011d1c455ddbe79eb5480e536 --- /dev/null +++ b/energy_communities/static/src/js/community-data-website.js @@ -0,0 +1,71 @@ +odoo.define("community_data.oe_community_data", function (require) { + "use strict"; + $(document).ready(function () { + var ajax = require("web.ajax"); + + $(".oe_community_data").each(function () { + var oe_community_data = this; + + var locale = $(".o_website_form_date").data("locale"); + + $.datepicker.regional = { + ca_ES: { + monthNamesShort: [ + "Gen", + "Feb", + "Mar", + "Abr", + "Mai", + "Jun", + "Jul", + "Ago", + "Set", + "Oct", + "Nov", + "Dec", + ], + }, + es_ES: { + monthNamesShort: [ + "Ene", + "Feb", + "Mar", + "Abr", + "May", + "Jun", + "Jul", + "Ago", + "Sept", + "Oct", + "Nov", + "Dic", + ], + }, + }; + + $.datepicker.setDefaults($.datepicker.regional[locale]); + + $(".o_website_form_date_past").datepicker({ + dateFormat: "dd/mm/yy", + changeMonth: true, + changeYear: true, + maxDate: "today", + yearRange: "2010:+0", + }); + //$(oe_cooperator).on("change", "#ordered_parts", function (event) { + // var $share_price = $("#share_price").text(); + // var $link = $(event.currentTarget); + // var quantity = $link[0].value; + // var total_part = quantity * $share_price; + // $("#total_parts").val(total_part); + // return false; + //}); + + //$(oe_cooperator).on("focusout", "input.js_quantity", function () { + // $("a.js_add_cart_json").trigger("click"); + //}); + + //$("#share_product_id").trigger("change"); + }); + }); +}); diff --git a/energy_communities/views/website_community_data_template.xml b/energy_communities/views/website_community_data_template.xml index afe1c867016c852c803af22181e167328f984b6d..d78e4b24aece7d7bace98806c392a796bfcd3b8d 100644 --- a/energy_communities/views/website_community_data_template.xml +++ b/energy_communities/views/website_community_data_template.xml @@ -1,5 +1,19 @@ <?xml version="1.0" encoding="utf-8" ?> <odoo> + + <template + id="assets_frontend" + inherit_id="web.assets_frontend" + name="community_data_website_script" + > + <xpath expr="." position="inside"> + <script + type="text/javascript" + src="/energy_communities/static/src/js/community-data-website.js" + /> + </xpath> + </template> + <template id="community_data_form_fields_template" name="community_data_form_fields_template" @@ -192,6 +206,13 @@ <t t-set="options" t-value="community_legal_form_options" /> </t> </div> + <div class="col-md-12"> + <t t-call="energy_communities.form_field_date_past"> + <t t-set="value" t-value="ce_constitution_date" /> + <t t-set="key" t-value="ce_constitution_date_key" /> + <t t-set="label" t-value="ce_constitution_date_label" /> + </t> + </div> </div> </template> @@ -256,7 +277,7 @@ <template id="community_data_page" name="Communnity data"> <t t-call="website.layout"> <div id="wrap" class="o_portal_wrap"> - <div class="container oe_cooperator"> + <div class="container oe_community_data"> <div class="row justify-content-center"> <div class="col-xs-12 col-sm-10 col-md-8 col-lg-6"> <h1 class="mt-4 text-center">Community data</h1> diff --git a/energy_communities/views/website_formfields_template.xml b/energy_communities/views/website_formfields_template.xml index 1f3253217b1cf4aeee4e07a231c646ef91c50b93..a34abd69395d3d5d744e9afe8f28590da013742d 100644 --- a/energy_communities/views/website_formfields_template.xml +++ b/energy_communities/views/website_formfields_template.xml @@ -197,4 +197,24 @@ <img t-if="value" t-attf-src="#{value}" width="100px" /> </div> </template> + <template id="form_field_date_past" name="form_field_date_past"> + <div + t-attf-name="#{key}_container" + t-attf-class="form-group #{error and key in error and 'has-error' or ''} field-#{key}" + > + <t t-set="date_placeholder" t-if="lang=='ca_ES'">dd/mm/aaaa</t> + <t t-set="date_placeholder" t-if="lang=='es_ES'">dd/mm/aaaa</t> + <t t-set="date_placeholder" t-if="lang=='en_US'">dd/mm/yyyy</t> + <label t-att="{'for': key}"><t t-esc="label" /></label> + <input + class="form-control form-control-sm o_website_form_date_past" + type="text" + t-attf-id="#{key}" + t-attf-name="#{key}" + t-attf-value="#{value or ''}" + t-attf-data-locale="#{lang}" + t-attf-placeholder="#{date_placeholder}" + /> + </div> + </template> </odoo>