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.

77 lines
2.8 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 one...
  35. var def;
  36. if (!this.domainSelector) {
  37. this.domainSelector = new DomainSelector(this, this._domainModel, value, {
  38. readonly: this.mode === "readonly" || this.inDialog,
  39. filters: this.fsFilters,
  40. debugMode: session.debug,
  41. partialUse: this.partialUse || false,
  42. });
  43. def = this.domainSelector.prependTo(this.$el);
  44. } else {
  45. def = this.domainSelector.setDomain(value);
  46. }
  47. // ... then replace the other content (matched records, etc)
  48. return def.then(this._replaceContent.bind(this));
  49. },
  50. /**
  51. * Render the field DOM except for the domain selector part. The full field
  52. * DOM is composed of a DIV which contains the domain selector widget,
  53. * followed by other content. This other content is handled by this method.
  54. *
  55. * @private
  56. */
  57. _replaceContent: function () {
  58. if (this._$content) {
  59. this._$content.remove();
  60. }
  61. this._$content = $(qweb.render("FieldDomain.content", {
  62. hasModel: !!this._domainModel,
  63. isValid: !!this._isValidForModel,
  64. nbRecords: this.record.specialData[this.name].nbRecords || 0,
  65. inDialogEdit: this.inDialog && this.mode === "edit",
  66. partialUse: this.partialUse || false,
  67. }));
  68. this._$content.appendTo(this.$el);
  69. },
  70. });
  71. });