Browse Source

Refactor dial button

pull/180/head
hparfr 6 years ago
parent
commit
c109f32a67
  1. 80
      base_phone/static/src/js/phone_widget.js

80
base_phone/static/src/js/phone_widget.js

@ -8,41 +8,63 @@ odoo.define('base_phone.updatedphone_widget', function (require) {
var core = require('web.core'); var core = require('web.core');
var web_client = require('web.web_client');
var basicFields = require('web.basic_fields');
var InputField = basicFields.InputField;
var originalFieldPhone = basicFields.FieldPhone;
var fieldRegistry = require('web.field_registry');
var QWeb = core.qweb;
var FieldPhone = require('web.basic_fields').FieldPhone;
var _t = core._t; var _t = core._t;
var updatedFieldPhone = originalFieldPhone.extend({
FieldPhone.include({
/* Always enable phone link tel:, not only on small screens */ /* Always enable phone link tel:, not only on small screens */
_canCall: function () { _canCall: function () {
return true; return true;
}, },
showDialButton: function () {
// must be inherited by ipbx specific modules
// and set to true
return false;
},
_renderReadonly: function() { _renderReadonly: function() {
// create a link to trigger action on server
// this link will be after the <a href="tel:">
this._super(); this._super();
if (this.mode == "readonly") {
if (!this.showDialButton()) {
return;
}
var self = this; var self = this;
// create our link
var dial = $('<a href="#" class="dial">📞 Dial</a>');
// add a parent element
// it's not possible to append to $el directly
// because $el don't have any parent yet
var parent = $('<div>');
parent.append([this.$el[0], ' ', dial]);
// replace this.$el by our new container
this.$el = parent;
var phone_num = this.value; var phone_num = this.value;
this.$el.filter('a[href^="tel:"]').off('click');
this.$el.filter('a[href^="tel:"]')
.on('click', function(ev) {
self.do_notify(
dial.click(function(evt) {
self.click2dial(phone_num);
});
},
click2dial: function(phone_num) {
var self = this;
this.do_notify(
_t('Click2dial started'), _t('Click2dial started'),
_t('Unhook your ringing phone'), _t('Unhook your ringing phone'),
false); false);
var arg = {
var params = {
'phone_number': phone_num, 'phone_number': phone_num,
'click2dial_model': self.model,
'click2dial_id': self.res_id};
self._rpc({
'click2dial_model': this.model,
'click2dial_id': this.res_id};
return this._rpc({
route: '/base_phone/click2dial', route: '/base_phone/click2dial',
params: arg,
}).done(function(r) {
params: params,
}).then(function(r) {
console.log('successfull', r);
// TODO: check why it never goes in there // TODO: check why it never goes in there
if (r === false) { if (r === false) {
self.do_warn("Click2dial failed"); self.do_warn("Click2dial failed");
@ -52,11 +74,6 @@ odoo.define('base_phone.updatedphone_widget', function (require) {
_t('Number dialed:') + ' ' + r.dialed_number, _t('Number dialed:') + ' ' + r.dialed_number,
false); false);
if (r.action_model) { if (r.action_model) {
var context = {
'click2dial_model': self.model,
'click2dial_id': self.res_id,
'phone_number': phone_num,
};
var action = { var action = {
name: r.action_name, name: r.action_name,
type: 'ir.actions.act_window', type: 'ir.actions.act_window',
@ -64,20 +81,19 @@ odoo.define('base_phone.updatedphone_widget', function (require) {
view_mode: 'form', view_mode: 'form',
views: [[false, 'form']], views: [[false, 'form']],
target: 'new', target: 'new',
context: context,
context: params,
}; };
this.do_action(action);
return this.do_action(action);
} }
} }
});
}, function (r) {
console.log('on error');
self.do_warn("Click2dial failed");
}); });
} }
}
}); });
fieldRegistry.add('phone', updatedFieldPhone);
return updatedFieldPhone;
return {
'FieldPhone': FieldPhone
};
}); });
Loading…
Cancel
Save