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.

86 lines
3.5 KiB

  1. odoo.define('oca.HelpOnline', function (require) {
  2. "use strict";
  3. var core = require('web.core');
  4. var QWeb = core.qweb;
  5. var _t = core._t;
  6. var ViewManager = require('web.ViewManager');
  7. var ControlPanel = require('web.ControlPanel');
  8. var Dialog = require('web.Dialog');
  9. ControlPanel.include({
  10. start: function(){
  11. this._super.apply(this, arguments);
  12. this._toggle_visibility(true);
  13. this.nodes = _.extend(
  14. this.nodes,
  15. {$help_online_buttons: this.$('.o_help_online_buttons')});
  16. this._toggle_visibility(false);
  17. },
  18. });
  19. ViewManager.include({
  20. /**
  21. * This function render the help button with the informations received
  22. * from the call to the method build_url from the help_online controller
  23. */
  24. render_help_button: function(url_info){
  25. var $helpButton = $(QWeb.render("HelpOnline.Button", {'view_manager':this, 'url_info': url_info}));
  26. $helpButton.tooltip();
  27. if (url_info.exists === false) {
  28. $helpButton.on('click', function (event) {
  29. var evt = event;
  30. evt.preventDefault();
  31. Dialog.confirm(
  32. self,
  33. _t('Page does not exist. Do you want to create?'),
  34. {confirm_callback: function() {
  35. var form = $("<form></form>");
  36. form.attr({
  37. id : "formform",
  38. // The location given in the link itself
  39. action : evt.target.href,
  40. method : "GET",
  41. // Open in new window/tab
  42. target : evt.target.target
  43. });
  44. $("body").append(form);
  45. $("#formform").submit();
  46. $("#formform").remove();
  47. return false;
  48. }
  49. });
  50. });
  51. }
  52. return $helpButton;
  53. },
  54. /**
  55. * This function render the help buttons container on the view.
  56. * It should be called after start() by render_view_control_elements.
  57. * @param {control_elements} the list of control elements to display into the ControlPanel
  58. */
  59. render_help_buttons: function(control_elements){
  60. if (! control_elements.$help_online_buttons){
  61. control_elements.$help_online_buttons = $('<div/>');
  62. }
  63. var self = this;
  64. this._rpc({route: '/help_online/build_url', params: {model: this.dataset.model, view_type: this.active_view.type}}).then(function(result) {
  65. if (result && ! _.isEmpty(result)) {
  66. var $helpButton = self.render_help_button(result);
  67. control_elements.$help_online_buttons = $helpButton;
  68. // update the control panel with the new help button
  69. self.update_control_panel({cp_content: _.extend({}, self.searchview_elements, control_elements)}, {clear: false});
  70. }
  71. });
  72. },
  73. render_view_control_elements: function() {
  74. var control_elements = this._super.apply(this, arguments);
  75. this.render_help_buttons(control_elements);
  76. return control_elements;
  77. },
  78. });
  79. });