You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.0 KiB

  1. /* Copyright 2015 Sylvain Calador <sylvain.calador@akretion.com>
  2. Copyright 2015 Javi Melendez <javi.melendez@algios.com>
  3. Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
  4. * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
  5. odoo.define('web_environment_ribbon.ribbon', function(require) {
  6. "use strict";
  7. var $ = require('$');
  8. var Model = require('web.Model');
  9. var core = require('web.core');
  10. var model = new Model('ir.config_parameter');
  11. // Code from: http://jsfiddle.net/WK_of_Angmar/xgA5C/
  12. function validStrColour(strToTest) {
  13. if (strToTest === "") { return false; }
  14. if (strToTest === "inherit") { return true; }
  15. if (strToTest === "transparent") { return true; }
  16. var image = document.createElement("img");
  17. image.style.color = "rgb(0, 0, 0)";
  18. image.style.color = strToTest;
  19. if (image.style.color !== "rgb(0, 0, 0)") { return true; }
  20. image.style.color = "rgb(255, 255, 255)";
  21. image.style.color = strToTest;
  22. return image.style.color !== "rgb(255, 255, 255)";
  23. }
  24. core.bus.on('web_client_ready', null, function () {
  25. var ribbon = $('<div class="test-ribbon"/>');
  26. $('body').append(ribbon);
  27. ribbon.hide();
  28. model.call('get_param', ['ribbon.name']).then(
  29. function (name) {
  30. if (name && name != 'False') {
  31. ribbon.html(name);
  32. ribbon.show();
  33. }
  34. }
  35. );
  36. // Get ribbon color from system parameters
  37. model.call('get_param', ['ribbon.color']).then(
  38. function (strColor) {
  39. if (strColor && validStrColour(strColor)) {
  40. ribbon.css('color', strColor);
  41. }
  42. }
  43. );
  44. // Get ribbon background color from system parameters
  45. model.call('get_param', ['ribbon.background.color']).then(
  46. function (strBackgroundColor) {
  47. if (strBackgroundColor && validStrColour(strBackgroundColor)) {
  48. ribbon.css('background-color', strBackgroundColor);
  49. }
  50. }
  51. );
  52. });
  53. }); // odoo.define