From 55090639f103b4c00673a1d1455db377a9b629bb Mon Sep 17 00:00:00 2001 From: Tristan Hill Date: Fri, 2 Jan 2015 14:55:14 +0000 Subject: [PATCH] FIX: clear field when number not set rather than leaving previous value --- base_phone/static/src/js/phone_widget.js | 86 +++++++++++++----------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/base_phone/static/src/js/phone_widget.js b/base_phone/static/src/js/phone_widget.js index 4f18554..07f358d 100644 --- a/base_phone/static/src/js/phone_widget.js +++ b/base_phone/static/src/js/phone_widget.js @@ -21,51 +21,55 @@ openerp.base_phone = function (instance) { var self = this; var phone_num = this.get('value'); //console.log('BASE_PHONE phone_num = %s', phone_num); + var href = '#'; + var href_text = ''; if (phone_num) { - this.$el.find('a.oe_form_uri') - .attr('href', 'tel:' + phone_num) - .text(formatInternational('', phone_num) || ''); + href = 'tel:' + phone_num; + href_text = formatInternational('', phone_num) || ''; } + this.$el.find('a.oe_form_uri').attr('href', href).text(href_text); + var click2dial_text = ''; if (phone_num && !this.options.dial_button_invisible) { - this.$el.find('#click2dial') - .text(phone_num && _t('Dial') || '') - .on('click', function(ev) { - self.do_notify( - _t('Click2dial started'), - _t('Unhook your ringing phone')); - var arg = { - 'phone_number': phone_num, - 'click2dial_model': self.view.dataset.model, - 'click2dial_id': self.view.datarecord.id}; - self.rpc('/base_phone/click2dial', arg).done(function(r) { - //console.log('Click2dial r=%s', JSON.stringify(r)); - if (r === false) { - self.do_warn("Click2dial failed"); - } else if (typeof r === 'object') { - self.do_notify( - _t('Click2dial successfull'), - _t('Number dialed:') + ' ' + r.dialed_number); - if (r.action_model) { - var context = {}; - if (self.view.dataset.model == 'res.partner') { - context = { - 'partner_id': self.view.datarecord.id}; - } - var action = { - name: r.action_name, - type: 'ir.actions.act_window', - res_model: r.action_model, - view_mode: 'form', - views: [[false, 'form']], - target: 'new', - context: context, - }; - instance.client.action_manager.do_action(action); - } + click2dial_text = _t('Dial'); + } + this.$el.find('#click2dial') + .text(click2dial_text) + .on('click', function(ev) { + self.do_notify( + _t('Click2dial started'), + _t('Unhook your ringing phone')); + var arg = { + 'phone_number': phone_num, + 'click2dial_model': self.view.dataset.model, + 'click2dial_id': self.view.datarecord.id}; + self.rpc('/base_phone/click2dial', arg).done(function(r) { + //console.log('Click2dial r=%s', JSON.stringify(r)); + if (r === false) { + self.do_warn("Click2dial failed"); + } else if (typeof r === 'object') { + self.do_notify( + _t('Click2dial successfull'), + _t('Number dialed:') + ' ' + r.dialed_number); + if (r.action_model) { + var context = {}; + if (self.view.dataset.model == 'res.partner') { + context = { + 'partner_id': self.view.datarecord.id}; + } + var action = { + name: r.action_name, + type: 'ir.actions.act_window', + res_model: r.action_model, + view_mode: 'form', + views: [[false, 'form']], + target: 'new', + context: context, + }; + instance.client.action_manager.do_action(action); } - }); + } }); - } + }); } }, on_button_clicked: function() { @@ -113,4 +117,4 @@ openerp.base_phone = function (instance) { return res; }; -} +};