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.

124 lines
5.4 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. var href = '#';
  22. var href_text = '';
  23. if (phone_num) {
  24. href = 'tel:' + phone_num;
  25. href_text = formatInternational('', phone_num) || '';
  26. }
  27. if (href_text) {
  28. this.$el.find('a.oe_form_uri').attr('href', href).text(href_text);
  29. this.$el.find('span.oe_form_char_content').text('');
  30. } else {
  31. this.$el.find('a.oe_form_uri').attr('href', '').text('');
  32. this.$el.find('span.oe_form_char_content').text(phone_num || '');
  33. }
  34. var click2dial_text = '';
  35. if (href_text && !this.options.dial_button_invisible) {
  36. click2dial_text = _t('Dial');
  37. }
  38. this.$el.find('#click2dial').off('click');
  39. this.$el.find('#click2dial')
  40. .text(click2dial_text)
  41. .on('click', function(ev) {
  42. self.do_notify(
  43. _t('Click2dial started'),
  44. _t('Unhook your ringing phone'));
  45. var arg = {
  46. 'phone_number': phone_num,
  47. 'click2dial_model': self.view.dataset.model,
  48. 'click2dial_id': self.view.datarecord.id};
  49. self.rpc('/base_phone/click2dial', arg).done(function(r) {
  50. //console.log('Click2dial r=%s', JSON.stringify(r));
  51. if (r === false) {
  52. self.do_warn("Click2dial failed");
  53. } else if (typeof r === 'object') {
  54. self.do_notify(
  55. _t('Click2dial successfull'),
  56. _t('Number dialed:') + ' ' + r.dialed_number);
  57. if (r.action_model) {
  58. var context = {
  59. 'click2dial_model': self.view.dataset.model,
  60. 'click2dial_id': self.view.datarecord.id,
  61. 'phone_number': phone_num,
  62. };
  63. var action = {
  64. name: r.action_name,
  65. type: 'ir.actions.act_window',
  66. res_model: r.action_model,
  67. view_mode: 'form',
  68. views: [[false, 'form']],
  69. target: 'new',
  70. context: context,
  71. };
  72. instance.client.action_manager.do_action(action);
  73. }
  74. }
  75. });
  76. });
  77. }
  78. },
  79. on_button_clicked: function() {
  80. location.href = 'tel:' + this.get('value');
  81. }
  82. });
  83. instance.web.form.widgets.add('phone', 'instance.base_phone.FieldPhone');
  84. instance.base_phone.FieldFax = instance.web.form.FieldChar.extend({
  85. template: 'FieldFax',
  86. initialize_content: function() {
  87. this._super();
  88. var $button = this.$el.find('button');
  89. $button.click(this.on_button_clicked);
  90. this.setupFocus($button);
  91. },
  92. render_value: function() {
  93. if (!this.get('effective_readonly')) {
  94. this._super();
  95. } else {
  96. var fax_num = this.get('value');
  97. //console.log('BASE_PHONE fax_num = %s', fax_num);
  98. var href = '#';
  99. var href_text = '';
  100. if (fax_num) {
  101. href = 'fax:' + fax_num;
  102. href_text = formatInternational('', fax_num) || '';
  103. }
  104. if (href_text) {
  105. this.$el.find('a.oe_form_uri').attr('href', href).text(href_text);
  106. this.$el.find('span.oe_form_char_content').text('');
  107. } else {
  108. this.$el.find('a.oe_form_uri').attr('href', '').text('');
  109. this.$el.find('span.oe_form_char_content').text(fax_num || '');
  110. }
  111. }
  112. },
  113. on_button_clicked: function() {
  114. location.href = 'fax:' + this.get('value');
  115. }
  116. });
  117. instance.web.form.widgets.add('fax', 'instance.base_phone.FieldFax');
  118. };