Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( d3ad00...acd091 )
by Pierre
04:27
created

client_select.js ➔ define   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 78

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 4
dl 0
loc 78
rs 8.9019
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A client_select.js ➔ ... ➔ ItemView.extend._toggleContactInfo 0 18 4
A client_select.js ➔ ... ➔ ItemView.extend.clientChange 0 5 1
A client_select.js ➔ ... ➔ ItemView.extend.onRender 0 5 2
B client_select.js ➔ ... ➔ ItemView.extend.clientSelect 0 30 3
A client_select.js ➔ ... ➔ ItemView.extend.initialize 0 5 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
define(
2
    ['jquery', 'core/view', 'lodash', 'routing'],
3
    function($, ItemView, _, Routing) {
4
        "use strict";
5
6
        return ItemView.extend({
7
            clientForm: null,
8
            ui: {
9
                'clientChange': '#client-select-change',
10
                'clientSelect': '#client-select'
11
            },
12
            events: {
13
                'click @ui.clientChange': 'clientChange',
14
                'change @ui.clientSelect': 'clientSelect'
15
            },
16
            initialize: function() {
17
                this.template = _.bind(function() {
18
                    return this.getOption('clientForm');
19
                }, this);
20
            },
21
            onRender: function() {
22
                if (!this.model.isEmpty()) {
23
                    this.$('#client-select').hide();
24
                }
25
            },
26
            clientChange: function(event) {
27
                event.preventDefault();
28
29
                this._toggleContactInfo();
30
            },
31
            clientSelect: function(event) {
32
                let val = $(event.target).val();
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
33
                if (parseInt(val, 10) === parseInt(this.model.id, 10)) {
34
                    this._toggleContactInfo();
35
                    return;
36
                }
37
38
                if (_.isEmpty(val)) {
39
                    return;
40
                }
41
42
                this.showLoader();
43
44
                $.getJSON(
45
                    Routing.generate('_xhr_clients_info', {id: val, type: this.getOption('type')}),
46
                    _.bind(function(data) {
47
                        this.$('#client-select-container').html(data.content);
48
                        this._toggleContactInfo(true);
49
50
                        if (this.options.hideLoader) {
51
                            this.hideLoader();
52
                        }
53
54
                        if (data.currency) {
55
                            data.client = val;
56
                            this.trigger('currency:update', data);
57
                        }
58
                    }, this)
59
                );
60
            },
61
            _toggleContactInfo: function(show) {
62
                let clientSelect = this.$('#client-select');
0 ignored issues
show
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
63
                clientSelect.toggle();
64
65
                if (clientSelect.is(':visible')) {
66
                    clientSelect.find('select').select2().select2('val', 0);
67
                }
68
69
                if (!_.isUndefined(show)) {
70
                    if (true === show) {
71
                        this.$('#client-select-container').show();
72
                    } else {
73
                        this.$('#client-select-container').hide();
74
                    }
75
                } else {
76
                    this.$('#client-select-container').toggle();
77
                }
78
            }
79
        });
80
    });