Skip to Content
Menu
This question has been flagged
1 Reply
3516 Views

How to make a Shortcut for Tab(Notebook) here I have 5 notebook I need to control this on button ie. When I click button 3 3rd tab need to open, How to did this...

Avatar
Discard
Best Answer

Using a shortcut the extension could be done like this in a js file:

odoo.define('web.aek_shortcuts', function (require) {

"use strict";

var core = require('web.core');

var FormView = require('web.FormView');

var common = require('web.form_common');

var _t = core._t;

var QWeb = core.qweb;

var ctrl_count = 0;

$.ctrl_bind = function(key, namespace, callback, args) {

var ev = 'keydown.'+namespace;

$(document).on(ev, function(e) {

if(!args) args=[]; // IE barks when args is null

console.log(e.keyCode)

if((e.keyCode == key.charCodeAt(0) || e.keyCode == key) && e.ctrlKey) {

callback.apply(this, args);

return false;

}

});

};

$.ctrl_unbind = function(name) {

var ev = 'keydown.'+name;

$(document).off(ev);

};

FormView.include({

init: function(parent, dataset, view_id, options) {

this._super.apply(this, arguments);

this.rendering_engine.handle_common_properties = function($new_element, $node, InvisibilityChanger) {

var str_modifiers = $node.attr("modifiers") || "{}";

var modifiers = JSON.parse(str_modifiers);

var ic = null;

if (modifiers.invisible !== undefined) {

var InvisibilityChangerCls = InvisibilityChanger || common.InvisibilityChanger;

ic = new InvisibilityChangerCls(this.view, this.view, modifiers.invisible, $new_element);

}

$new_element.addClass($node.attr("class") || "");

$new_element.attr('style', $node.attr('style'));

if($node[0].tagName == 'PAGE'){

if($node.attr('context')){

var context = JSON.parse($node.attr('context'));

if(context.shortcut != undefined){

ctrl_count++;

this.ctrl_count = ctrl_count;

$.ctrl_bind(context.shortcut, this.ctrl_count, function() {

$new_element[0].children[0].click();//could be used execute_action() too

});

}

}

}

return {invisibility_changer: ic,};

};

},

destroy: function() {

$.ctrl_unbind(this.ctrl_count);

this._super.apply(this, arguments);

},

});

});

With that code installed you could define your notebook page like this:

<notebook>

<page string="Tab 1" context='{"shortcut": "Y"}'>

...

</page>

</notebook>


Avatar
Discard
Related Posts Replies Views Activity
0
Mar 15
4079
1
Oct 24
109
7
Dec 21
9365
0
Sep 21
608
1
Mar 15
4218