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.

92 lines
3.1 KiB

  1. /**********************************************************************************
  2. *
  3. * Copyright (C) 2017 MuK IT GmbH
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. **********************************************************************************/
  19. odoo.define('muk_web_utils.ModuleBoolean', function (require) {
  20. "use strict";
  21. var core = require('web.core');
  22. var fields = require('web.basic_fields');
  23. var registry = require('web.field_registry');
  24. var framework = require('web.framework');
  25. var Dialog = require('web.Dialog');
  26. var AbstractField = require('web.AbstractField');
  27. var _t = core._t;
  28. var QWeb = core.qweb;
  29. var ModuleBoolean = fields.FieldBoolean.extend({
  30. supportedFieldTypes: [],
  31. events: _.extend({}, AbstractField.prototype.events, {
  32. 'click input': '_onInputClicked',
  33. }),
  34. renderWithLabel: function ($label) {
  35. this.$label = $label;
  36. this._render();
  37. },
  38. _openDialog: function () {
  39. var buttons = [{
  40. text: _t("Download"),
  41. classes: 'btn-primary',
  42. close: true,
  43. click: this._confirmRedirect.bind(this),
  44. }, {
  45. text: _t("Cancel"),
  46. close: true,
  47. }];
  48. return new Dialog(this, {
  49. size: 'medium',
  50. buttons: buttons,
  51. $content: $('<div>', {
  52. html: $(QWeb.render('muk_web_utils.MissingModuleDialog')),
  53. }),
  54. title: _t("Missing Module"),
  55. }).open();
  56. },
  57. _confirmRedirect: function () {
  58. if(this.nodeOptions.url) {
  59. framework.redirect(this.nodeOptions.url);
  60. } else {
  61. var module = this.name.replace("module_", "");
  62. framework.redirect("https://apps.odoo.com/apps/modules/browse?search=" + module);
  63. }
  64. },
  65. _render: function () {
  66. this._super.apply(this, arguments);
  67. var $element = this.$label || this.$el;
  68. $element.append('&nbsp;').append($("<span>", {
  69. 'text': _t("Store"),
  70. 'class': "badge badge-primary oe_inline mk_module_label"
  71. }));
  72. },
  73. _onInputClicked: function (event) {
  74. if ($(event.currentTarget).prop("checked")) {
  75. var dialog = this._openDialog();
  76. dialog.on('closed', this, this._resetValue.bind(this));
  77. }
  78. },
  79. _resetValue: function () {
  80. this.$input.prop("checked", false).change();
  81. },
  82. });
  83. registry.add('module_boolean', ModuleBoolean);
  84. return ModuleBoolean;
  85. });