Skip to content

Commit

Permalink
[MIG] website_search_header: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kobros-tech authored and dnplkndll committed Nov 28, 2024
1 parent 61ec6a3 commit 3536bac
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 91 deletions.
1 change: 1 addition & 0 deletions website_search_header/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Contributors
------------

- ForgeFlow <https://www.forgeflow.com>
- Kencove <https://www.kencove.com/>

Maintainers
-----------
Expand Down
6 changes: 2 additions & 4 deletions website_search_header/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@
{
"name": "Website Search in Header",
"category": "Website",
"version": "16.0.1.1.0",
"version": "17.0.1.1.0",
"author": "ForgeFlow, Ooops, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/website",
"license": "LGPL-3",
"depends": [
"website",
"web",
],
"data": [
"views/templates.xml",
],
"assets": {
"web.assets_frontend": [
"website_search_header.assets_frontend": [
"website_search_header/static/src/js/website.js",
"website_search_header/static/src/scss/website_search_header.scss",
],
},
"installable": True,
Expand Down
1 change: 1 addition & 0 deletions website_search_header/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- ForgeFlow \<<https://www.forgeflow.com>\>
- Kencove \<<https://www.kencove.com/>\>
1 change: 1 addition & 0 deletions website_search_header/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>ForgeFlow &lt;<a class="reference external" href="https://www.forgeflow.com">https://www.forgeflow.com</a>&gt;</li>
<li>Kencove &lt;<a class="reference external" href="https://www.kencove.com/">https://www.kencove.com/</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
103 changes: 42 additions & 61 deletions website_search_header/static/src/js/website.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,43 @@
odoo.define("website_search_header.search_header", function (require) {
(function () {
"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").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");
} else {
$(".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");
$("input.oe_search_box").focus();
}
},

_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 + "&amp;order=name+asc";
},
});
});
function mobileSearch() {
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;
}

function desktopSearch() {
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");
$("input.oe_search_box").focus();
} 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");
}
}

function searchHeader() {
var screenWidth =
window.innerWidth ||
document.documentElement.clientWidth ||
document.body.clientWidth;
if (screenWidth < 992) {
mobileSearch();
} else {
desktopSearch();
}
}

window.searchHeader = searchHeader;
})();
37 changes: 11 additions & 26 deletions website_search_header/views/templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@
aria-label="Search"
t-attf-class="btn oe_search_button btn-primary"
title="Search"
t-attf-onclick="searchHeader()"
>
<i class="oi oi-close" />
</button>
</div>

<t t-call-assets="website_search_header.assets_frontend" t-js="true" />
</template>

<template id="template_header_default" inherit_id="website.template_header_default">
<template
id="template_header_default"
inherit_id="website.template_header_hamburger"
>
<xpath expr="//t[@t-call='website.navbar_toggler']" position="after">
<t t-call="website_search_header.header_search_link">
<t t-set="_item_class" t-value="'nav-item'" />
Expand Down Expand Up @@ -79,16 +85,7 @@
</xpath>
</template>

<template id="template_header_slogan" inherit_id="website.template_header_slogan">
<xpath expr="//t[@t-call='website.navbar_toggler']" position="after">
<t t-call="website_search_header.header_search_link">
<t t-set="_item_class" t-value="'nav-item'" />
<t t-set="_link_class" t-value="'nav-link'" />
</t>
</xpath>
</template>

<template id="template_header_contact" inherit_id="website.template_header_contact">
<template id="template_header_slogan" inherit_id="website.template_header_sidebar">
<xpath expr="//t[@t-call='website.navbar_toggler']" position="after">
<t t-call="website_search_header.header_search_link">
<t t-set="_item_class" t-value="'nav-item'" />
Expand All @@ -108,7 +105,7 @@

<template
id="template_header_centered_logo"
inherit_id="website.template_header_centered_logo"
inherit_id="website.template_header_hamburger"
>
<xpath expr="//t[@t-call='website.navbar_toggler']" position="after">
<t t-call="website_search_header.header_search_link">
Expand All @@ -118,7 +115,7 @@
</xpath>
</template>

<template id="template_header_image" inherit_id="website.template_header_image">
<template id="template_header_image" inherit_id="website.template_header_hamburger">
<xpath expr="//t[@t-call='website.navbar_toggler']" position="after">
<t t-call="website_search_header.header_search_link">
<t t-set="_item_class" t-value="'nav-item'" />
Expand All @@ -129,19 +126,7 @@

<template
id="template_header_hamburger_full"
inherit_id="website.template_header_hamburger_full"
>
<xpath expr="//t[@t-call='website.navbar_toggler']" position="after">
<t t-call="website_search_header.header_search_link">
<t t-set="_item_class" t-value="'nav-item'" />
<t t-set="_link_class" t-value="'nav-link'" />
</t>
</xpath>
</template>

<template
id="template_header_magazine"
inherit_id="website.template_header_magazine"
inherit_id="website.template_header_hamburger"
>
<xpath expr="//t[@t-call='website.navbar_toggler']" position="after">
<t t-call="website_search_header.header_search_link">
Expand Down

0 comments on commit 3536bac

Please sign in to comment.