Conditions | 1 |
Paths | 1 |
Total Lines | 58 |
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 | /** @lends LateRegistrationView */ |
||
2 | define(function(require) { |
||
3 | 'use strict'; |
||
4 | |||
5 | var LateRegistrationView; |
||
6 | var $ = require('jquery'); |
||
7 | var _ = require('underscore'); |
||
8 | var BaseComponent = require('oroui/js/app/views/base/view'); |
||
9 | |||
10 | LateRegistrationView = BaseComponent.extend({ |
||
11 | |||
12 | /** |
||
13 | * @property {jQuery} |
||
14 | */ |
||
15 | $el: null, |
||
16 | |||
17 | options: { |
||
18 | selectors: { |
||
19 | switcher: null, |
||
20 | fieldsContainer: null |
||
21 | } |
||
22 | }, |
||
23 | |||
24 | /** |
||
25 | * @inheritDoc |
||
26 | */ |
||
27 | constructor: function LateRegistrationView() { |
||
28 | LateRegistrationView.__super__.constructor.apply(this, arguments); |
||
29 | }, |
||
30 | |||
31 | /** |
||
32 | * @inheritDoc |
||
33 | */ |
||
34 | initialize: function(options) { |
||
35 | this.options = $.extend(true, {}, this.options, options); |
||
36 | |||
37 | this.$switcher = this.$el.find(this.options.selectors.switcher); |
||
38 | this.$fieldsContainer = this.$el.find(this.options.selectors.fieldsContainer); |
||
39 | this.$switcher.on('change', _.bind(this.onOptionChange, this)); |
||
40 | this.onOptionChange(); |
||
41 | }, |
||
42 | |||
43 | onOptionChange: function() { |
||
44 | var inputs = this.$fieldsContainer.find('input'); |
||
45 | var validationDisabled = false; |
||
46 | if ($(this.$switcher).is(':checked')) { |
||
47 | $(this.$fieldsContainer).show(); |
||
48 | } else { |
||
49 | $(this.$fieldsContainer).hide(); |
||
50 | validationDisabled = true; |
||
51 | } |
||
52 | _.each(inputs, function(input) { |
||
53 | $(input).prop('disabled', validationDisabled).inputWidget('refresh'); |
||
54 | }); |
||
55 | } |
||
56 | }); |
||
57 | |||
58 | return LateRegistrationView; |
||
59 | }); |
||
60 |