<commit_before>/* Base phone module for Odoo
   Copyright (C) 2013-2016 <NAME> <<EMAIL>>
   The licence is in the file __openerp__.py */

odoo.define('base_phone.phone_widget', function (require) {
    "use strict";

    var core = require('web.core');
    var formwidgets = require('web.form_widgets');
    var web_client = require('web.web_client');
    var _t = core._t;

    var FieldFax = formwidgets.FieldEmail.extend({
        template: 'FieldFax',
        prefix: 'fax',
        initialize_content: function() {
            this._super();
            var $button = this.$el.find('button');
            $button.click(this.on_button_clicked);
            this.setupFocus($button);
        },
        render_value: function() {
            this._super();
            if (this.get("effective_readonly") && this.clickable) {
                var phone_num = this.get('value');
                if(phone_num) {
                    phone_num = phone_num.replace(/ /g, '').replace(/-/g, '');
                    this.$el.attr('href', this.prefix + ':' + phone_num);
                }
            }
        },
        on_button_clicked: function() {
            location.href = this.prefix + ':' + this.get('value');
        }
    });

    var FieldPhone = FieldFax.extend({
        template: 'FieldPhone',
        prefix: 'tel',
        render_value: function() {
            this._super();
            if (this.get("effective_readonly") && this.clickable) {
                var self = this;
                var phone_num = this.get('value');
                if(phone_num) {
                    phone_num = phone_num.replace(/ /g, '').replace(/-/g, '');
                }
                var click2dial_text = '';
                if (phone_num && !this.options.dial_button_invisible) {
                    click2dial_text = _t('Dial');
                }
                this.$el.filter('#click2dial')
                    .text(click2dial_text)
                    .attr('href', '#')
                    .on('click', function(ev) {
                        self.do_notify(
                                _t('Click2dial started'),
                                _t('Unhook your ringing phone'),
                                false);
                        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,
                                        false);
                                if (r.action_model) {
                                    var context = {
                                        'click2dial_model': self.view.dataset.model,
                                        'click2dial_id': self.view.datarecord.id,
                                        'phone_number': phone_num,<commit_msg>[Odoo 10] Fix for #20<commit_after>/* Base phone module for Odoo
   Copyright (C) 2013-2016 <NAME> <<EMAIL>>
   The licence is in the file __openerp__.py */

odoo.define('base_phone.phone_widget', function (require) {
    "use strict";

    var core = require('web.core');
    var formwidgets = require('web.form_widgets');
    var web_client = require('web.web_client');
    var _t = core._t;

    var FieldFax = formwidgets.FieldEmail.extend({
        template: 'FieldFax',
        prefix: 'fax',
        initialize_content: function() {
            this._super();
            var $button = this.$el.find('button');
            $button.click(this.on_button_clicked);
            this.setupFocus($button);
        },
        render_value: function() {
            this._super();
            if (this.get("effective_readonly") && this.clickable) {
                var phone_num = this.get('value');
                if(phone_num) {
                    phone_num = phone_num.replace(/ /g, '').replace(/-/g, '');
                    this.$el.attr('href', this.prefix + ':' + phone_num);
                }
            }
        },
        on_button_clicked: function() {
            location.href = this.prefix + ':' + this.get('value');
        }
    });

    var FieldPhone = FieldFax.extend({
        template: 'FieldPhone',
        prefix: 'tel',
        render_value: function() {
            this._super();
            if (this.get("effective_readonly") && this.clickable) {
                var self = this;
                var phone_num = this.get('value');
                if(phone_num) {
                    phone_num = phone_num.replace(/ /g, '').replace(/-/g, '');
                }
                var click2dial_text = '';
                if (phone_num && !this.options.dial_button_invisible) {
                    click2dial_text = _t('Dial');
                }
                this.$el.filter('#click2dial').off('click');
                this.$el.filter('#click2dial')
                    .text(click2dial_text)
                    .attr('href', '#')
                    .on('click', function(ev) {
                        self.do_notify(
                                _t('Click2dial started'),
                                _t('Unhook your ringing phone'),
                                false);
                        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,
                                        false);
                                if (r.action_model) {
                                    var context = {
                                        'click2dial_model': self.view.dataset.model,
                                        'click2dial_id': self.view.datarecord.id,
                                        'phone_number': phone_num,
{'fraction_non_alphanumeric': 0.12516316171138506, 'fraction_numerical': 0.006816533720087019, 'mean_word_length': 1.1760807825812558, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1546599', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1720, 'n_words': 316}