Test Setup Failed
Push — master ( 982d9a...a2862f )
by
unknown
03:40
created

Select2AutocompleteChannelAwareComponent   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 3
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 3
loc 3
rs 10
c 0
b 0
f 0
1 View Code Duplication
define(function(require) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
    'use strict';
3
4
    var Select2AutocompleteChannelAwareComponent;
5
    var $ = require('jquery');
6
    var _ = require('underscore');
7
    var Select2AutocompleteComponent = require('oro/select2-autocomplete-component');
8
    var BaseSelect2View = require('oroform/js/app/views/select2-autocomplete-view');
9
    var viewFactory = require('orochannel/js/app/factory/select2-channel-aware-view-factory');
10
    var Select2View = viewFactory(BaseSelect2View);
11
12
    Select2AutocompleteChannelAwareComponent = Select2AutocompleteComponent.extend({
13
        $sourceElement: null,
14
        channelId: '',
15
        channelFieldName: '',
16
        ViewType: Select2View,
17
        /**
18
         * @inheritDoc
19
         */
20
        constructor: function Select2AutocompleteChannelAwareComponent() {
21
            Select2AutocompleteChannelAwareComponent.__super__.constructor.apply(this, arguments);
22
        },
23
        /**
24
         * @inheritDoc
25
         */
26
        initialize: function(options) {
27
            this.$sourceElement = options._sourceElement;
28
            this.channelId = _.result(options, 'channel_id') || this.channelId;
29
            this.channelFieldName = _.result(options, 'channel_field_name') || this.channelFieldName;
30
            Select2AutocompleteChannelAwareComponent.__super__.initialize.call(this, options);
31
        },
32
        prepareViewOptions: function(options, config) {
0 ignored issues
show
Unused Code introduced by
The parameter options is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter config is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
33
            var opts = Select2AutocompleteChannelAwareComponent.__super__.prepareViewOptions.apply(this, arguments);
34
            opts.$channelSelector = this.findChannelSelectorElement();
35
            opts.additionalParamsCb = _.bind(this._getAdditionalParams, this);
36
37
            return opts;
38
        },
39
        makeQuery: function(query) {
40
            var $channel = $('select[name="' + this.channelFieldName + '"]');
41
            return query + ';' + (this.channelId || $channel.val());
42
        },
43
        findChannelSelectorElement: function() {
44
            return this.$sourceElement.closest('form').find('select[name="' + this.channelFieldName + '"]');
45
        },
46
        _getAdditionalParams: function() {
47
            var params = {};
48
49
            var $channel = this.findChannelSelectorElement();
50
            var channelIds = [$channel.val()];
51
            if (this.channelId) {
52
                channelIds.push(this.channelId);
53
            }
54
55
            params.channelIds = channelIds.join(',');
56
57
            return {
58
                params: params
59
            };
60
        }
61
    });
62
    return Select2AutocompleteChannelAwareComponent;
63
});
64
65