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.

98 lines
3.1 KiB

  1. /* Copyright 2014-2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  2. Copyright 2015-2018 Juris Malinens (port to v9)
  3. License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
  4. odoo.define('asterisk_click2dial.systray.OpenCaller', function (require) {
  5. "use strict";
  6. var core = require('web.core');
  7. var SystrayMenu = require('web.SystrayMenu');
  8. var Widget = require('web.Widget');
  9. var _t = core._t;
  10. var FieldPhone = require('base_phone.updatedphone_widget').FieldPhone;
  11. FieldPhone.include({
  12. showDialButton: function () {
  13. return true;
  14. }
  15. });
  16. var OpenCallerMenu = Widget.extend({
  17. name: 'open_caller',
  18. template: 'asterisk_click2dial.systray.OpenCaller',
  19. events: {
  20. 'click': 'on_open_caller',
  21. },
  22. on_open_caller: function (event) {
  23. event.stopPropagation();
  24. var self = this;
  25. var context = this.getSession().user_context;
  26. self._rpc({
  27. route: '/asterisk_click2dial/get_record_from_my_channel',
  28. params: {local_context: context, },
  29. }).then(function(r) {
  30. // console.log('RESULT RPC r='+r);
  31. // console.log('RESULT RPC type r='+typeof r);
  32. // console.log('RESULT RPC isNaN r='+isNaN(r));
  33. if (r === false) {
  34. self.do_warn(
  35. _t('IPBX error'),
  36. _t('Calling party number not retreived from IPBX or IPBX unreachable by Odoo'),
  37. false);
  38. }
  39. else if (typeof r == 'string' && isNaN(r)) {
  40. self.do_warn(
  41. r,
  42. _t('The calling number is not a phone number!'),
  43. false);
  44. }
  45. else if (typeof r == 'string') {
  46. var action = {
  47. name: _t('Number Not Found'),
  48. type: 'ir.actions.act_window',
  49. res_model: 'number.not.found',
  50. view_mode: 'form',
  51. views: [[false, 'form']],
  52. target: 'new',
  53. context: {'default_calling_number': r},
  54. };
  55. self.do_action(action);
  56. }
  57. else if (typeof r == 'object' && r.length == 3) {
  58. self.do_notify(
  59. _.str.sprintf(_t("On the phone with '%s'"), r[2]),
  60. _.str.sprintf(_t("Moving to form view of '%s' (%s ID %d)"), r[2], r[0], r[1]),
  61. false);
  62. var action = {
  63. type: 'ir.actions.act_window',
  64. res_model: r[0],
  65. res_id: r[1],
  66. view_mode: 'form,tree',
  67. views: [[false, 'form']],
  68. /* If you want to make it work with the 'web' module
  69. of Odoo Enterprise edition, you have to change the line
  70. target: 'current',
  71. to:
  72. target: 'new',
  73. If you want to use target: 'current', with web/enterprise,
  74. you have to reload the Web page just after */
  75. target: 'current',
  76. context: {},
  77. };
  78. self.do_action(action);
  79. }
  80. });
  81. },
  82. });
  83. SystrayMenu.Items.push(OpenCallerMenu);
  84. return OpenCallerMenu;
  85. });