| Conditions | 1 |
| Paths | 2 |
| Total Lines | 80 |
| 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 ShoppingListCreateWidget; |
||
| 5 | var routing = require('routing'); |
||
| 6 | var DialogWidget = require('oro/dialog-widget'); |
||
| 7 | var _ = require('underscore'); |
||
| 8 | var ShoppingListCollectionService = require('oroshoppinglist/js/shoppinglist-collection-service'); |
||
| 9 | |||
| 10 | ShoppingListCreateWidget = DialogWidget.extend({ |
||
| 11 | shoppingListCollection: null, |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @inheritDoc |
||
| 15 | */ |
||
| 16 | constructor: function ShoppingListCreateWidget() { |
||
| 17 | ShoppingListCreateWidget.__super__.constructor.apply(this, arguments); |
||
| 18 | }, |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @inheritDoc |
||
| 22 | */ |
||
| 23 | initialize: function(options) { |
||
| 24 | var urlOptions = {}; |
||
| 25 | if (options.createOnly) { |
||
| 26 | urlOptions.createOnly = true; |
||
| 27 | } |
||
| 28 | this.options.url = options.url = routing.generate('oro_shopping_list_frontend_create', urlOptions); |
||
| 29 | |||
| 30 | this.options.title = _.__('oro.shoppinglist.widget.add_to_new_shopping_list'); |
||
| 31 | this.options.regionEnabled = false; |
||
| 32 | this.options.incrementalPosition = false; |
||
| 33 | this.options.shoppingListCreateEnabled = true; |
||
| 34 | |||
| 35 | options.dialogOptions = { |
||
| 36 | modal: true, |
||
| 37 | resizable: false, |
||
| 38 | width: '480', |
||
| 39 | autoResize: true, |
||
| 40 | dialogClass: 'shopping-list-dialog' |
||
| 41 | }; |
||
| 42 | |||
| 43 | this.on('formSave', _.bind(this.onFormSave, this)); |
||
| 44 | |||
| 45 | ShoppingListCollectionService.shoppingListCollection.done(_.bind(function(collection) { |
||
| 46 | this.shoppingListCollection = collection; |
||
| 47 | }, this)); |
||
| 48 | |||
| 49 | ShoppingListCreateWidget.__super__.initialize.apply(this, arguments); |
||
| 50 | }, |
||
| 51 | |||
| 52 | dispose: function() { |
||
| 53 | if (this.disposed) { |
||
| 54 | return; |
||
| 55 | } |
||
| 56 | delete this.shoppingListCollection; |
||
| 57 | return ShoppingListCreateWidget.__super__.dispose.apply(this, arguments); |
||
| 58 | }, |
||
| 59 | |||
| 60 | onFormSave: function(data) { |
||
| 61 | var label = data.label || this.$el.find('.form-field-label').val(); |
||
| 62 | if (this.shoppingListCollection.length) { |
||
| 63 | this.shoppingListCollection.each(function(model) { |
||
| 64 | model.set('is_current', model.get('id') === data.savedId, {silent: true}); |
||
| 65 | }); |
||
| 66 | } |
||
| 67 | |||
| 68 | this.shoppingListCollection.add({ |
||
| 69 | id: data.savedId, |
||
| 70 | label: label, |
||
| 71 | is_current: true |
||
| 72 | }); |
||
| 73 | this.shoppingListCollection.trigger('change', { |
||
| 74 | shoppingListCreateEnabled: data.shoppingListCreateEnabled |
||
| 75 | }); |
||
| 76 | } |
||
| 77 | }); |
||
| 78 | |||
| 79 | return ShoppingListCreateWidget; |
||
| 80 | }); |
||
| 81 |