[IMP] web_refresher: Work as component of control panel

pull/2366/head
Alexandre D. Díaz 2022-07-15 20:29:40 +02:00 committed by Carlos Roca
parent 2ecabeac08
commit c027ded193
8 changed files with 108 additions and 28 deletions

View File

@ -51,6 +51,7 @@ Authors
~~~~~~~
* Compassion Switzerland
* Tecnativa
Contributors
~~~~~~~~~~~~
@ -59,6 +60,7 @@ Contributors
* `Tecnativa <https://www.tecnativa.com>`__:
* João Marques
* Alexandre D. Díaz
* Thanakrit Pintana
* `Factorlibre <https://www.factorlibre.com>`__:

View File

@ -1,11 +1,17 @@
{
"name": "Web Refresher",
"version": "16.0.1.0.0",
"author": "Compassion Switzerland, Odoo Community Association (OCA)",
"author": "Compassion Switzerland, Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/web",
"depends": ["web"],
"installable": True,
"auto_install": False,
"assets": {"web.assets_backend": ["web_refresher/static/src/xml/pager_button.xml"]},
"assets": {
"web.assets_backend": [
"web_refresher/static/src/scss/refresher.scss",
"web_refresher/static/src/js/refresher.js",
"web_refresher/static/src/xml/refresher.xml",
],
},
}

View File

@ -2,6 +2,7 @@
* `Tecnativa <https://www.tecnativa.com>`__:
* João Marques
* Alexandre D. Díaz
* Thanakrit Pintana
* `Factorlibre <https://www.factorlibre.com>`__:

View File

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Web Refresher</title>
<style type="text/css">
@ -396,6 +396,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<h2><a class="toc-backref" href="#id3">Authors</a></h2>
<ul class="simple">
<li>Compassion Switzerland</li>
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
@ -404,6 +405,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<li>Samuel Fringeli</li>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>João Marques</li>
<li>Alexandre D. Díaz</li>
</ul>
</li>
<li>Thanakrit Pintana</li>

View File

@ -0,0 +1,42 @@
/* Copyright 2022 Tecnativa - Alexandre D. Díaz
* License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
odoo.define("refresher.Refresher", function (require) {
"use strict";
const ControlPanel = require("web.ControlPanel");
const {Component, hooks} = owl;
const {useRef} = hooks;
class Refresher extends Component {
_doRefresh() {
// Note: here we use the pager props, see xml
const {limit, currentMinimum} = this.props;
this.trigger("pager-changed", {currentMinimum, limit});
}
}
Refresher.template = "web_refresher.Button";
// Patch control panel to initialize refresher component
ControlPanel.components = Object.assign({}, ControlPanel.components, {
Refresher,
});
ControlPanel.patch("web_refresher.ControlPanel", (T) => {
class ControlPanelRefresher extends T {
constructor() {
super(...arguments);
if ("cp_content" in this.props) {
const content = this.props.cp_content || {};
if ("$refresher" in content) {
this.additionalContent.refresher = content.$refresher;
}
}
this.contentRefs.refresher = useRef("refresher");
}
}
return ControlPanelRefresher;
});
return Refresher;
});

View File

@ -0,0 +1,7 @@
.oe_cp_refresher {
margin: auto 0 auto auto;
padding-left: 5px;
text-align: right;
user-select: none;
flex-grow: 1;
}

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2021 Tecnativa - João Marques
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<template>
<t
t-name="web_refresher.Pager"
t-inherit="web.Pager"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//span[hasclass('o_pager_counter')]" position="before">
<span class="btn-group" aria-atomic="true">
<button
type="button"
class="fa fa-refresh btn btn-secondary o_pager_refresh"
aria-label="Refresh"
title="Refresh"
tabindex="-1"
t-on-click.stop="() => this.navigate(0)"
style="margin-right: 5px;"
/>
</span>
</xpath>
</t>
</template>

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2022 Tecnativa - Alexandre Díaz
License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<template>
<t
t-name="web_refresher.ControlPanel"
t-inherit="web.ControlPanel"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//div[hasclass('o_cp_pager')]" position="before">
<div class="oe_cp_refresher" role="search" t-ref="refresher">
<Refresher t-props="props.pager" />
</div>
</xpath>
</t>
<t
t-name="web_refresher.ControlPanelX2Many"
t-inherit="web.ControlPanelX2Many"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//div[hasclass('o_cp_pager')]" position="before">
<div class="oe_cp_refresher" role="search" t-ref="refresher">
<Refresher t-props="props.pager" />
</div>
</xpath>
</t>
<t t-name="web_refresher.Button" owl="1">
<nav class="oe_refresher" aria-label="Pager">
<span aria-atomic="true">
<button
class="fa fa-refresh btn btn-icon oe_pager_refresh"
aria-label="Refresh"
t-on-click="_doRefresh"
title="Refresh"
tabindex="-1"
/>
</span>
</nav>
</t>
</template>