We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 1 |
Paths | 1 |
Total Lines | 78 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | define( |
||
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(); |
||
|
|||
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'); |
||
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 | }); |