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.3 KiB

  1. /* © 2014-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  2. © 2015-2016 Juris Malinens (port to v9)
  3. License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
  4. odoo.define('asterisk_click2dial.click2dial', function (require) {
  5. "use strict";
  6. var UserMenu = require('web.UserMenu');
  7. var WebClient = require('web.WebClient');
  8. var web_client = require('web.web_client');
  9. var Widget = require('web.Widget');
  10. var core = require('web.core');
  11. var _t = core._t;
  12. var click2dial = {};
  13. click2dial.OpenCaller = Widget.extend({
  14. template: 'asterisk_click2dial.OpenCaller',
  15. start: function () {
  16. this.$('#asterisk-open-caller').on(
  17. 'click', this.on_open_caller);
  18. this._super();
  19. },
  20. on_open_caller: function (event) {
  21. event.stopPropagation();
  22. var self = this;
  23. self.rpc('/asterisk_click2dial/get_record_from_my_channel', {}).done(function(r) {
  24. // console.log('RESULT RPC r='+r);
  25. // console.log('RESULT RPC type r='+typeof r);
  26. // console.log('RESULT RPC isNaN r='+isNaN(r));
  27. if (r === false) {
  28. self.do_warn(
  29. _t('Failure'),
  30. _t('Problem in the connection to Asterisk'),
  31. false);
  32. }
  33. else if (typeof r == 'string' && isNaN(r)) {
  34. self.do_warn(
  35. r,
  36. _t('The calling number is not a phone number!'),
  37. false);
  38. }
  39. else if (typeof r == 'string') {
  40. var action = {
  41. name: _t('Number Not Found'),
  42. type: 'ir.actions.act_window',
  43. res_model: 'number.not.found',
  44. view_mode: 'form',
  45. views: [[false, 'form']],
  46. target: 'new',
  47. context: {'default_calling_number': r},
  48. };
  49. web_client.action_manager.do_action(action);
  50. }
  51. else if (typeof r == 'object' && r.length == 3) {
  52. self.do_notify( // Not working
  53. _t('Success'),
  54. _t('Moving to %s ID %d', r[0], r[1]),
  55. false);
  56. var action = {
  57. type: 'ir.actions.act_window',
  58. res_model: r[0],
  59. res_id: r[1],
  60. view_mode: 'form,tree',
  61. views: [[false, 'form']],
  62. /* If you want to make it work with the 'web' module
  63. of Odoo Enterprise edition, you have to change the line
  64. target: 'current',
  65. to:
  66. target: 'new',
  67. If you want to use target: 'current', with web/enterprise,
  68. you have to reload the Web page just after */
  69. target: 'current',
  70. context: {},
  71. };
  72. web_client.action_manager.do_action(action);
  73. }
  74. });
  75. },
  76. });
  77. /* TODO port to v10: update_promise doesn't existe in
  78. odoo10/addons/web/static/src/js/widgets/user_menu.js
  79. UserMenu.include({
  80. do_update: function(){
  81. this._super.apply(this, arguments);
  82. this.update_promise.then(function() {
  83. var asterisk_button = new click2dial.OpenCaller();
  84. // attach the phone logo/button to the systray
  85. asterisk_button.appendTo($('.oe_systray'));
  86. });
  87. },
  88. }); */
  89. });