Last active
March 7, 2018 13:56
-
-
Save KangOl/8913699a426ee98895ce92907918725a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name odoo-debug-switch | |
// @namespace odoo.com | |
// @version 0.1 | |
// @description Add a debug mode switch button in header | |
// @author @KangOl | |
// @updateURL https://gist.github.com/KangOl/8913699a426ee98895ce92907918725a/raw/odoo-debug-switch.user.js | |
// @match https://*.odoo.com/web | |
// @match https://*.odoo.com/web?* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
if (!odoo) return; | |
odoo.define('userscript.debugswitch', function(require) { | |
var core = require('web.core'); | |
var Widget = require('web.Widget'); | |
var SystrayMenu = require('web.SystrayMenu'); | |
if (core.debug) { return; } | |
var DebugSwitcher = Widget.extend({ | |
template: "WebClient.DebugManager", | |
events: { | |
"click a[data-action]": "perform_callback" | |
}, | |
start: function() { | |
this.$('span:first').css('color', 'pink'); | |
var $dd = this.$('.o_debug_dropdown'); | |
$dd.append('<li><a href="#" data-action="activate">Activate Debug Mode</a><li><li><a href="#" data-action="split_assets">Activate Assets Debugging</a></li>'); | |
return this._super(); | |
}, | |
perform_callback: function (evt) { | |
evt.preventDefault(); | |
var params = $(evt.target).data(); | |
var callback = params.action; | |
if (callback && this[callback]) { | |
// Perform the callback corresponding to the option | |
this[callback](params, evt); | |
} else { | |
console.warn("No handler for ", callback); | |
} | |
}, | |
activate: function() { | |
window.location = $.param.querystring(window.location.href, 'debug'); | |
}, | |
split_assets: function() { | |
window.location = $.param.querystring(window.location.href, 'debug=assets'); | |
}, | |
0:0 | |
}); | |
SystrayMenu.Items.push(DebugSwitcher); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment