| Conditions | 1 |
| Paths | 2 |
| Total Lines | 79 |
| 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(function(require) { |
||
| 2 | 'use strict'; |
||
| 3 | |||
| 4 | var BaseProductVariantsView; |
||
| 5 | var BaseView = require('oroui/js/app/views/base/view'); |
||
| 6 | var ElementsHelper = require('orofrontend/js/app/elements-helper'); |
||
| 7 | var LoadingMaskView = require('oroui/js/app/views/loading-mask-view'); |
||
| 8 | var $ = require('jquery'); |
||
| 9 | var _ = require('underscore'); |
||
| 10 | |||
| 11 | BaseProductVariantsView = BaseView.extend(_.extend({}, ElementsHelper, { |
||
| 12 | options: { |
||
| 13 | showLoading: true |
||
| 14 | }, |
||
| 15 | |||
| 16 | elements: { |
||
| 17 | variantForm: '[data-name="form__oro-product-product-variant-frontend-variant-field"]', |
||
| 18 | variantFields: ['variantForm', ':input[data-name]'] |
||
| 19 | }, |
||
| 20 | |||
| 21 | elementsEvents: {}, |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @inheritDoc |
||
| 25 | */ |
||
| 26 | constructor: function BaseProductVariantsView() { |
||
| 27 | BaseProductVariantsView.__super__.constructor.apply(this, arguments); |
||
| 28 | }, |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @inheritDoc |
||
| 32 | */ |
||
| 33 | initialize: function(options) { |
||
| 34 | this.options = $.extend(true, {}, this.options, _.pick(options, _.keys(this.options))); |
||
| 35 | BaseProductVariantsView.__super__.initialize.apply(this, arguments); |
||
| 36 | |||
| 37 | this.initModel(options); |
||
| 38 | this.initializeElements(options); |
||
| 39 | }, |
||
| 40 | |||
| 41 | initModel: function(options) { |
||
| 42 | if (options.productModel) { |
||
| 43 | this.model = options.productModel; |
||
| 44 | } |
||
| 45 | }, |
||
| 46 | |||
| 47 | updateProductInfo: function(id) { |
||
| 48 | this.model.set('id', id ? parseInt(id, 10) : 0); |
||
| 49 | }, |
||
| 50 | |||
| 51 | showLoading: function() { |
||
| 52 | if (!this.options.showLoading) { |
||
| 53 | return; |
||
| 54 | } |
||
| 55 | var $container = this.$el.closest('[data-role="layout-subtree-loading-container"]'); |
||
| 56 | if (!$container.length) { |
||
| 57 | $container = this.$el; |
||
| 58 | } |
||
| 59 | this.subview('loadingMask', new LoadingMaskView({ |
||
| 60 | container: $container |
||
| 61 | })); |
||
| 62 | this.subview('loadingMask').show(); |
||
| 63 | }, |
||
| 64 | |||
| 65 | hideLoading: function() { |
||
| 66 | if (!this.options.showLoading) { |
||
| 67 | return; |
||
| 68 | } |
||
| 69 | this.removeSubview('loadingMask'); |
||
| 70 | }, |
||
| 71 | |||
| 72 | dispose: function() { |
||
| 73 | this.disposeElements(); |
||
| 74 | BaseProductVariantsView.__super__.dispose.apply(this, arguments); |
||
| 75 | } |
||
| 76 | })); |
||
| 77 | |||
| 78 | return BaseProductVariantsView; |
||
| 79 | }); |
||
| 80 |