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.

116 lines
5.0 KiB

  1. /* Base phone module for OpenERP
  2. Copyright (C) 2013-2014 Alexis de Lattre <alexis@via.ecp.fr>
  3. The licence is in the file __openerp__.py */
  4. openerp.base_phone = function (instance) {
  5. var _t = instance.web._t;
  6. instance.base_phone.FieldPhone = instance.web.form.FieldChar.extend({
  7. template: 'FieldPhone',
  8. initialize_content: function() {
  9. this._super();
  10. var $button = this.$el.find('button');
  11. $button.click(this.on_button_clicked);
  12. this.setupFocus($button);
  13. },
  14. render_value: function() {
  15. if (!this.get('effective_readonly')) {
  16. this._super();
  17. } else {
  18. var self = this;
  19. var phone_num = this.get('value');
  20. //console.log('BASE_PHONE phone_num = %s', phone_num);
  21. if (phone_num) {
  22. this.$el.find('a.oe_form_uri')
  23. .attr('href', 'tel:' + phone_num)
  24. .text(formatInternational('', phone_num) || '');
  25. }
  26. if (phone_num && !this.options.dial_button_invisible) {
  27. this.$el.find('#click2dial')
  28. .text(phone_num && _t('Dial') || '')
  29. .on('click', function(ev) {
  30. self.do_notify(
  31. _t('Click2dial started'),
  32. _t('Unhook your ringing phone'));
  33. var arg = {
  34. 'phone_number': phone_num,
  35. 'click2dial_model': self.view.dataset.model,
  36. 'click2dial_id': self.view.datarecord.id};
  37. self.rpc('/base_phone/click2dial', arg).done(function(r) {
  38. //console.log('Click2dial r=%s', JSON.stringify(r));
  39. if (r === false) {
  40. self.do_warn("Click2dial failed");
  41. } else if (typeof r === 'object') {
  42. self.do_notify(
  43. _t('Click2dial successfull'),
  44. _t('Number dialed:') + ' ' + r.dialed_number);
  45. if (r.action_model) {
  46. var context = {};
  47. if (self.view.dataset.model == 'res.partner') {
  48. context = {
  49. 'partner_id': self.view.datarecord.id};
  50. }
  51. var action = {
  52. name: r.action_name,
  53. type: 'ir.actions.act_window',
  54. res_model: r.action_model,
  55. view_mode: 'form',
  56. views: [[false, 'form']],
  57. target: 'new',
  58. context: context,
  59. };
  60. instance.client.action_manager.do_action(action);
  61. }
  62. }
  63. });
  64. });
  65. }
  66. }
  67. },
  68. on_button_clicked: function() {
  69. location.href = 'tel:' + this.get('value');
  70. }
  71. });
  72. instance.web.form.widgets.add('phone', 'instance.base_phone.FieldPhone');
  73. instance.base_phone.FieldFax = instance.web.form.FieldChar.extend({
  74. template: 'FieldFax',
  75. initialize_content: function() {
  76. this._super();
  77. var $button = this.$el.find('button');
  78. $button.click(this.on_button_clicked);
  79. this.setupFocus($button);
  80. },
  81. render_value: function() {
  82. if (!this.get('effective_readonly')) {
  83. this._super();
  84. } else {
  85. var fax_num = this.get('value');
  86. if (fax_num) {
  87. this.$el.find('a.oe_form_uri')
  88. .attr('href', 'fax:' + fax_num)
  89. .text(formatInternational('', fax_num) || '');
  90. }
  91. }
  92. },
  93. on_button_clicked: function() {
  94. location.href = 'fax:' + this.get('value');
  95. }
  96. });
  97. instance.web.form.widgets.add('fax', 'instance.base_phone.FieldFax');
  98. /* ability to add widget="phone" in TREE view */
  99. var _super_list_char_format_ = instance.web.list.Char.prototype._format;
  100. instance.web.list.Char.prototype._format = function(row_data, options) {
  101. res = _super_list_char_format_.call(this, row_data, options);
  102. var value = row_data[this.id].value;
  103. if (value && this.widget === 'phone') {
  104. return formatInternational('', value);
  105. }
  106. return res;
  107. };
  108. }