From 12b38d557b9ff25cabc10e6de9adf3bacd106b11 Mon Sep 17 00:00:00 2001 From: Elmer Garcia Yavi Date: Tue, 9 Jan 2024 10:42:24 +0100 Subject: [PATCH] [MODIFY] website_search_header: Improve scalability in js code --- website_search_header/README.rst | 76 ++++++++++++++- website_search_header/__manifest__.py | 3 +- website_search_header/readme/CONTRIBUTORS.rst | 1 + website_search_header/readme/USAGE.rst | 1 + .../static/description/index.html | 50 +++++----- .../static/src/js/website.js | 61 ++++++++++++ website_search_header/views/templates.xml | 96 +++---------------- 7 files changed, 176 insertions(+), 112 deletions(-) create mode 100644 website_search_header/readme/USAGE.rst create mode 100644 website_search_header/static/src/js/website.js diff --git a/website_search_header/README.rst b/website_search_header/README.rst index 31c374045a..0b0ef03b18 100644 --- a/website_search_header/README.rst +++ b/website_search_header/README.rst @@ -1,3 +1,73 @@ -====================== -Website Search Header -====================== +======================== +Website Search in Header +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d16cfb3e2bf08f7b6803f08d17d302e2ee86b04c1e4296db2ea051d1cb3dec43 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github + :target: https://github.com/OCA/website/tree/16.0/website_search_header + :alt: OCA/website +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/website-16-0/website-16-0-website_search_header + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/website&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a search bar in the header of your website. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +On desktop, the user will be able to show and hide the search input in the website header. While on mobile our searchbox will behave by default. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow +* Ooops + +Contributors +~~~~~~~~~~~~ + +* Jordi Ballester +* Elmer GarcĂ­a + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/website `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_search_header/__manifest__.py b/website_search_header/__manifest__.py index 664e259216..8d4cb5c0fd 100644 --- a/website_search_header/__manifest__.py +++ b/website_search_header/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Website Search in Header", "category": "Website", - "version": "16.0.1.0.0", + "version": "16.0.1.1.0", "author": "ForgeFlow, Ooops, Odoo Community Association (OCA)", "website": "https://github.com/OCA/website", "license": "LGPL-3", @@ -17,6 +17,7 @@ ], "assets": { "web.assets_frontend": [ + "website_search_header/static/src/js/website.js", "website_search_header/static/src/scss/website_search_header.scss", ], }, diff --git a/website_search_header/readme/CONTRIBUTORS.rst b/website_search_header/readme/CONTRIBUTORS.rst index 94748cbb0c..7b25f3c80f 100644 --- a/website_search_header/readme/CONTRIBUTORS.rst +++ b/website_search_header/readme/CONTRIBUTORS.rst @@ -1 +1,2 @@ + * ForgeFlow diff --git a/website_search_header/readme/USAGE.rst b/website_search_header/readme/USAGE.rst new file mode 100644 index 0000000000..202d13188f --- /dev/null +++ b/website_search_header/readme/USAGE.rst @@ -0,0 +1 @@ +On desktop, the user will be able to show and hide the search input in the website header. While on mobile our searchbox will behave by default. diff --git a/website_search_header/static/description/index.html b/website_search_header/static/description/index.html index 3696395e5d..67d665feeb 100644 --- a/website_search_header/static/description/index.html +++ b/website_search_header/static/description/index.html @@ -1,20 +1,20 @@ - + - -Website Login Required + +Website Search in Header -
-

Website Login Required

+
+

Website Search in Header

-

Beta License: LGPL-3 OCA/website Translate me on Weblate Try me on Runbot

+

Beta License: LGPL-3 OCA/website Translate me on Weblate Try me on Runboat

This module allows to restrict access to specific website pages to logged users.

Table of contents

-

Usage

+

Usage

Website > Configuration > Authorization required URLs: select a website and enter a relative path, eg: /shop

When public user will try to access mywebsite.com/shop or any of its child pages, they will be requested to login.

-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub 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.

+If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

    -
  • Advitus MB
  • +
  • ForgeFlow
  • Ooops
-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association

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.

-

This module is part of the OCA/website project on GitHub.

+

This module is part of the OCA/website project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/website_search_header/static/src/js/website.js b/website_search_header/static/src/js/website.js new file mode 100644 index 0000000000..76b6c44aee --- /dev/null +++ b/website_search_header/static/src/js/website.js @@ -0,0 +1,61 @@ +odoo.define("website_search_header.search_header", function (require) { + "use strict"; + + const publicWidget = require("web.public.widget"); + + publicWidget.registry.SearchHeader = publicWidget.Widget.extend({ + selector: "#div_search_button", + + events: { + "click #search_btn_toggle_search": "_onClickSearchBtn", + }, + + start: function () { + const def = this._super.apply(this, arguments); + this.$boxInput = this.$el.find(".o_search_header"); + return def; + }, + + mobileSearch: function () { + if (!this.$boxInput.hasClass("d-none")) { + this.$boxInput.addClass("d-none"); + } + var searchQuery = document.querySelector("input[name='search']").value; + var encodedQuery = encodeURIComponent(searchQuery); + var searchURL = this._getSearchUrl(encodedQuery); + window.location.href = searchURL; + }, + + desktopSearch: function () { + if ($(".o_search_header").hasClass("d-lg-none")) { + $(".o_search_header").removeClass("d-lg-none"); + $("#search_btn_toggle_search i").removeClass("oi-search"); + $("#search_btn_toggle_search i").addClass("oi-close"); + $("#div_search_header").removeClass("ms-lg-0"); + $("#div_search_button").removeClass("ms-lg-2"); + } else { + $(".o_search_header").addClass("d-lg-none"); + $("#search_btn_toggle_search i").removeClass("oi-close"); + $("#search_btn_toggle_search i").addClass("oi-search"); + $("#div_search_header").addClass("ms-lg-0"); + $("#div_search_button").addClass("ms-lg-2"); + } + }, + + _onClickSearchBtn: function () { + var screenWidth = + window.innerWidth || + document.documentElement.clientWidth || + document.body.clientWidth; + if (screenWidth < 992) { + this.mobileSearch(); + } else { + this.desktopSearch(); + } + }, + + _getSearchUrl: function (encodedQuery) { + return "/website/search?search=" + encodedQuery + "&order=name+asc"; + }, + }); +}); diff --git a/website_search_header/views/templates.xml b/website_search_header/views/templates.xml index 467ff85b3d..a18293accb 100644 --- a/website_search_header/views/templates.xml +++ b/website_search_header/views/templates.xml @@ -30,61 +30,19 @@
-
-