1
|
|
View Code Duplication |
define(function(require) { |
|
|
|
|
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) { |
|
|
|
|
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
|
|
|
|