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.

73 lines
2.3 KiB

  1. /* © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  2. License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
  3. odoo.define('asterisk_click2dial.OpenCaller', function (require) {
  4. "use strict";
  5. var _t = core._t;
  6. var Widget = require('web.Widget');
  7. var OpenCaller = Widget.extend({
  8. template: 'asterisk_click2dial.OpenCaller',
  9. start: function () {
  10. this.$('#asterisk-open-caller').on(
  11. 'click', this.on_open_caller);
  12. this._super();
  13. },
  14. on_open_caller: function (event) {
  15. event.stopPropagation();
  16. var self = this;
  17. self.rpc('/asterisk_click2dial/get_record_from_my_channel', {}).done(function(r) {
  18. // console.log('RESULT RPC r='+r);
  19. // console.log('RESULT RPC type r='+typeof r);
  20. if (r === false) {
  21. self.do_notify(
  22. _t('Failure'),
  23. _t('Problem in the connection to Asterisk'));
  24. }
  25. else if (typeof r == 'string') {
  26. var action = {
  27. name: _t('Number Not Found'),
  28. type: 'ir.actions.act_window',
  29. res_model: 'number.not.found',
  30. view_mode: 'form',
  31. views: [[false, 'form']],
  32. target: 'new',
  33. context: {'default_calling_number': r},
  34. };
  35. instance.client.action_manager.do_action(action);
  36. }
  37. else if (typeof r == 'object' && r.length == 3) {
  38. self.do_notify( // Not working
  39. _t('Success'),
  40. _t('Moving to %s ID %d', r[0], r[1]));
  41. var action = {
  42. type: 'ir.actions.act_window',
  43. res_model: r[0],
  44. res_id: r[1],
  45. view_mode: 'form,tree',
  46. views: [[false, 'form']],
  47. target: 'current',
  48. context: {},
  49. };
  50. instance.client.action_manager.do_action(action);
  51. }
  52. });
  53. },
  54. });
  55. instance.web.UserMenu.include({
  56. do_update: function(){
  57. this._super.apply(this, arguments);
  58. this.update_promise.then(function() {
  59. var asterisk_button = new instance.web.OpenCaller();
  60. asterisk_button.appendTo(instance.webclient.$el.find('.oe_systray'));
  61. });
  62. },
  63. });
  64. });