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.

80 lines
2.9 KiB

  1. odoo.define('agreement_legal.domain_widget_ext', function (require) {
  2. 'use strict';
  3. var basic_fields = require('web.basic_fields');
  4. var DomainSelector = require('web.DomainSelector');
  5. var session = require('web.session');
  6. var core = require('web.core');
  7. var qweb = core.qweb;
  8. var _t = core._t;
  9. basic_fields.FieldDomain.include({
  10. /**
  11. * Init
  12. */
  13. init : function () {
  14. this._super.apply(this, arguments);
  15. // Add Additional options
  16. this.partialUse = this.nodeOptions.partial_use || false;
  17. },
  18. //----------------------------------------------------------------------
  19. // Private
  20. //----------------------------------------------------------------------
  21. /**
  22. * @private
  23. * @override _render from AbstractField
  24. * @returns {Deferred}
  25. */
  26. _render: function () {
  27. // If there is no model, only change the non-domain-selector content
  28. if (!this._domainModel) {
  29. this._replaceContent();
  30. return $.when();
  31. }
  32. // Convert char value to array value
  33. var value = this.value || "[]";
  34. // Create the domain selector or change the value of the current
  35. // one...
  36. var def;
  37. if (!this.domainSelector) {
  38. this.domainSelector = new DomainSelector(
  39. this, this._domainModel, value, {
  40. readonly: this.mode === "readonly" || this.inDialog,
  41. filters: this.fsFilters,
  42. debugMode: session.debug,
  43. partialUse: this.partialUse || false,
  44. });
  45. def = this.domainSelector.prependTo(this.$el);
  46. } else {
  47. def = this.domainSelector.setDomain(value);
  48. }
  49. // ... then replace the other content (matched records, etc)
  50. return def.then(this._replaceContent.bind(this));
  51. },
  52. /**
  53. * Render the field DOM except for the domain selector part. The full
  54. * field DOM is composed of a DIV which contains the domain selector
  55. * widget, followed by other content. This other content is handled by
  56. * this method.
  57. *
  58. * @private
  59. */
  60. _replaceContent: function () {
  61. if (this._$content) {
  62. this._$content.remove();
  63. }
  64. this._$content = $(qweb.render("FieldDomain.content", {
  65. hasModel: !!this._domainModel,
  66. isValid: !!this._isValidForModel,
  67. nbRecords: this.record.specialData[this.name].nbRecords || 0,
  68. inDialogEdit: this.inDialog && this.mode === "edit",
  69. partialUse: this.partialUse || false,
  70. }));
  71. this._$content.appendTo(this.$el);
  72. },
  73. });
  74. });