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.

165 lines
6.6 KiB

  1. /* Copyright 2016 Ildar Nasyrov <https://it-projects.info/team/iledarn>
  2. # Copyright 2016 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
  3. # Copyright 2016 Pavel Romanchenko
  4. # Copyright 2018 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
  5. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). */
  6. odoo.define("mail_move_message.relocate", function(require) {
  7. "use strict";
  8. var bus = require("bus.bus").bus;
  9. var chat_manager = require("mail_base.base").chat_manager;
  10. var thread = require("mail.ChatThread");
  11. var chatter = require("mail.Chatter");
  12. var rpc = require("web.rpc");
  13. var Basicmodel = require("web.BasicModel");
  14. var view_dialogs = require("web.view_dialogs");
  15. var field_utils_format = require("web.field_utils").format;
  16. var BasicRenderer = require("web.BasicRenderer");
  17. var core = require("web.core");
  18. var form_widget = require("web.FormRenderer");
  19. var session = require("web.Session");
  20. var FormController = require("web.FormController");
  21. var FormView = require("web.FormView");
  22. var FormRenderer = require("web.FormRenderer");
  23. var dialogs = require("web.view_dialogs");
  24. var Dialog = require("web.Dialog");
  25. var relational_fields = require("web.relational_fields");
  26. var Widget = require("web.Widget");
  27. var _t = core._t;
  28. thread.include({
  29. init: function() {
  30. this._super.apply(this, arguments);
  31. // Add click reaction in the events of the thread object
  32. this.events["click .oe_move"] = function(event) {
  33. var message_id = $(event.currentTarget).data("message-id");
  34. this.trigger("move_message", message_id);
  35. };
  36. },
  37. on_move_message: function(message_id) {
  38. var action = {
  39. name: _t("Relocate Message"),
  40. type: "ir.actions.act_window",
  41. res_model: "mail_move_message.wizard",
  42. view_mode: "form",
  43. view_type: "form",
  44. views: [[false, "form"]],
  45. target: "new",
  46. context: {default_message_id: message_id},
  47. };
  48. this.do_action(action, {
  49. on_close: function() {},
  50. });
  51. },
  52. });
  53. chatter.include({
  54. start: function() {
  55. var result = this._super.apply(this, arguments);
  56. // For show wizard in the form
  57. if (this.fields.thread && this.fields.thread.thread) {
  58. var thread = this.fields.thread.thread;
  59. thread.on("move_message", this, thread.on_move_message);
  60. }
  61. return $.when(result).done(function() {});
  62. },
  63. });
  64. var ChatAction = core.action_registry.get("mail.chat.instant_messaging");
  65. ChatAction.include({
  66. start: function() {
  67. var result = this._super.apply(this, arguments);
  68. // For show wizard in the channels
  69. this.thread.on("move_message", this, this.thread.on_move_message);
  70. return $.when(result).done(function() {});
  71. },
  72. });
  73. // Override methods of chat manager
  74. var chat_manager_super_make_message = chat_manager.make_message;
  75. chat_manager.make_message = function(data) {
  76. var msg = chat_manager_super_make_message(data);
  77. // Mark msg as moved after reload
  78. msg.is_moved = data.is_moved || false;
  79. return msg;
  80. };
  81. var chat_manager_super_on_notification = chat_manager.on_notification;
  82. chat_manager.on_notification = function(notifications) {
  83. chat_manager_super_on_notification(notifications);
  84. var self = this;
  85. _.each(notifications, function(notification) {
  86. var model = notification[0][1];
  87. var message_id = notification[1].id;
  88. var message = chat_manager.get_message(message_id);
  89. if (model === "mail_move_message" && message) {
  90. message.res_id = notification[1].res_id;
  91. message.model = notification[1].model;
  92. message.record_name = notification[1].record_name;
  93. // Mark message as moved after move
  94. message.is_moved = notification[1].is_moved;
  95. // Update cache and accordingly message in the thread
  96. self.add_to_cache(message, []);
  97. // Call thread.on_update_message(message)
  98. chat_manager.bus.trigger("update_message", message);
  99. } else if (model === "mail_move_message.delete_message") {
  100. _.each(message.channel_ids, function(ch) {
  101. self.remove_message_from_channel(ch, message);
  102. });
  103. chat_manager.bus.trigger("update_message", message);
  104. }
  105. });
  106. };
  107. Basicmodel.include({
  108. applyDefaultValues: function(recordID, values, options) {
  109. delete values.model;
  110. return this._super(recordID, values, options);
  111. },
  112. });
  113. FormController.include({
  114. _onButtonClicked: function(event) {
  115. if (
  116. event.data.attrs.special === "quick_create" &&
  117. event.data.attrs.field === "partner_id"
  118. ) {
  119. var self = this;
  120. var field_data = event.data.record.data;
  121. this.on_saved = function(record, bool) {
  122. var values = [
  123. {
  124. id: record.res_id,
  125. display_name: record.data.display_name,
  126. },
  127. ];
  128. };
  129. var wid = self.initialState.fieldsInfo.form.partner_id.Widget;
  130. var relField = new relational_fields.FieldMany2One(
  131. wid,
  132. "partner_id",
  133. self.initialState,
  134. {
  135. mode: "edit",
  136. viewType: "form",
  137. }
  138. );
  139. relField.getParent = function() {
  140. // Necessary for correct _trigger_up implementation in mixins.js
  141. return self;
  142. };
  143. var wizard_popup = relField._searchCreatePopup("form", false, {
  144. message_name_from:
  145. field_data.message_name_from &&
  146. field_data.message_name_from.split("@")[0],
  147. message_email_from: field_data.message_email_from,
  148. message_id: field_data.res_id,
  149. mail_move_message: 1,
  150. });
  151. } else {
  152. this._super.apply(this, arguments);
  153. }
  154. },
  155. });
  156. });