Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
4 Antworten
8701 Ansichten

Hello,


I created a custom kanban view and I want to hide the control panel (header) from this view onl.


What would be the best way to do this ?


Thanks !

Avatar
Verwerfen
Beste Antwort

Hi,


By using patching method, we can modify the control panel in Odoo. For that, use the following code:

/** @odoo-module */


import { ControlPanel } from "@web/search/control_panel/control_panel";

import { patch } from "@web/core/utils/patch";

import { useRef, onPatched, onMounted, useState } from "@odoo/owl";


patch(ControlPanel.prototype,{

    setup() {

        super.setup();

        onMounted(() => {

            #you can specify the condition for which view you need to remove the control panel

            if (this.env.searchModel.vew == 'form') {

                this.root.el.style.setProperty("display", "none", "important");

            }

        });

    },

});



Hope it helps.

Avatar
Verwerfen
Beste Antwort

The structure of withControlPanel is wrong,

You should write like this : 

var KanbanViewWithoutControlPanel = KanbanView.extend({

withControlPanel: false

});


You can find the structure of related parameters from this path :

/odoo/addons/web/static/src/js/views/abstract_view.js

Avatar
Verwerfen
Autor Beste Antwort

Ravi,

Thank you for your answser and pointing out the correct documentation.

Unfortunately it does not work : the control panel is still there. Here's what I'm doing 

odoo.define('my.KanbanViewWithoutControlPanel', function (require) {
"use strict";

var viewRegistry = require('web.view_registry')
var KanbanView = require('web.KanbanView')

var KanbanViewWithoutControlPanel = KanbanView.extend({
config: _.extend({}, KanbanView.prototype.config, {
withControlPanel: false,
}),
});

viewRegistry.add('kanban_without_control_panel', KanbanViewWithoutControlPanel)
});


And in my view

<kanban js_class="kanban_without_control_panel">...

There is no error. The js file is correctly loaded.


I modified the JS to print out the current view in the console .



        init: function (viewInfo, params) {
this._super.apply(this, arguments);
console.log(this)
},


The output shows that the view is called, but the control panel is still enabled:


arch: {}
attrs: {}
create: "false"
js_class: "kanban_homepage"
...
withControlPanel: true
withSearchPanel: true


So ma temporary solution (wrong ?) is to set this 2 variables in the init method.


Regards

Avatar
Verwerfen

Hi

is it solved?

Beste Antwort



extend kanban view using "js_class" attribute (https://www.odoo.com/documentation/13.0/reference/javascript_cheatsheet.html#customizing-an-existing-view)

override  withControlPanel to false

var KanbanViewWithoutControlPanel = kanbanView.extend({
config: _.extend({}, kanbanView.prototype.config, {
        // determines if a control panel should be instantiated
        withControlPanel: false,
        // determines if a search panel could be instantiated
        // withSearchPanel: false,
    }),
});

viewRegistry.add('kanban_without_control_panel', KanbanViewWithoutControlPanel);
<kanban js_class="kanban_without_control_panel">
Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
0
Dez. 16
4032
0
März 15
6848
1
März 15
18743
0
Nov. 24
645
1
Dez. 23
7565