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.

104 lines
4.2 KiB

  1. /* Base phone module for Odoo
  2. Copyright (C) 2013-2018 Akretion France
  3. @author: Alexis de Lattre <alexis.delattre@akretion.com>
  4. License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
  5. odoo.define('base_phone.updatedphone_widget', function (require) {
  6. "use strict";
  7. var core = require('web.core');
  8. var web_client = require('web.web_client');
  9. var basicFields = require('web.basic_fields');
  10. var InputField = basicFields.InputField;
  11. var originalFieldPhone = basicFields.FieldPhone;
  12. var fieldRegistry = require('web.field_registry');
  13. var QWeb = core.qweb;
  14. var _t = core._t;
  15. var updatedFieldPhone = originalFieldPhone.extend({
  16. /* init: function () {
  17. this._super.apply(this, arguments);
  18. }, */
  19. _renderReadonly: function() {
  20. this._super();
  21. if (this.mode == "readonly") {
  22. var self = this;
  23. var phone_num = this.value;
  24. /* if(phone_num) {
  25. phone_num = phone_num.replace(/ /g, '').replace(/-/g, '');
  26. } */
  27. /* var click2dial_text = '';
  28. if (phone_num && !this.options.dial_button_invisible) {
  29. click2dial_text = _t('Dial');
  30. }
  31. this.$el.filter('#click2dial').off('click');
  32. this.$el.filter('#click2dial')
  33. .text(click2dial_text)
  34. .attr('href', '#')
  35. } */
  36. this.$el.filter('a[href^="tel:"]').off('click');
  37. this.$el.filter('a[href^="tel:"]')
  38. .on('click', function(ev) {
  39. self.do_notify(
  40. _t('Click2dial started'),
  41. _t('Unhook your ringing phone'),
  42. false);
  43. var arg = {
  44. 'phone_number': phone_num,
  45. 'click2dial_model': self.model,
  46. 'click2dial_id': self.res_id};
  47. self._rpc({
  48. route: '/base_phone/click2dial',
  49. params: arg,
  50. }).done(function(r) {
  51. // TODO: check why it never goes in there
  52. if (r === false) {
  53. self.do_warn("Click2dial failed");
  54. } else if (typeof r === 'object') {
  55. self.do_notify(
  56. _t('Click2dial successfull'),
  57. _t('Number dialed:') + ' ' + r.dialed_number,
  58. false);
  59. if (r.action_model) {
  60. var context = {
  61. 'click2dial_model': self.model,
  62. 'click2dial_id': self.res_id,
  63. 'phone_number': phone_num,
  64. };
  65. var action = {
  66. name: r.action_name,
  67. type: 'ir.actions.act_window',
  68. res_model: r.action_model,
  69. view_mode: 'form',
  70. views: [[false, 'form']],
  71. target: 'new',
  72. context: context,
  73. };
  74. this.do_action(action);
  75. }
  76. }
  77. });
  78. });
  79. }
  80. }
  81. });
  82. // To avoid conflicts, we check that widgets do not exist before using
  83. /*
  84. if(!core.form_widget_registry.get('fax')){
  85. core.form_widget_registry.add('fax', FieldFax);
  86. }
  87. if(!core.form_widget_registry.get('phone')){
  88. core.form_widget_registry.add('phone', FieldPhone);
  89. }
  90. */
  91. fieldRegistry.add('phone', updatedFieldPhone);
  92. return updatedFieldPhone;
  93. });