1
|
|
View Code Duplication |
define(function(require) { |
|
|
|
|
2
|
|
|
'use strict'; |
3
|
|
|
|
4
|
|
|
var Select2GridChannelAwareComponent; |
5
|
|
|
var _ = require('underscore'); |
6
|
|
|
var Select2GridComponent = require('oro/select2-grid-component'); |
7
|
|
|
var BaseSelect2View = require('oroform/js/app/views/select2-view'); |
8
|
|
|
var viewFactory = require('orochannel/js/app/factory/select2-channel-aware-view-factory'); |
9
|
|
|
var Select2View = viewFactory(BaseSelect2View); |
10
|
|
|
|
11
|
|
|
Select2GridChannelAwareComponent = Select2GridComponent.extend({ |
12
|
|
|
$sourceElement: null, |
13
|
|
|
channelId: '', |
14
|
|
|
channelFieldName: '', |
15
|
|
|
gridName: '', |
16
|
|
|
ViewType: Select2View, |
17
|
|
|
/** |
18
|
|
|
* @inheritDoc |
19
|
|
|
*/ |
20
|
|
|
constructor: function Select2GridChannelAwareComponent() { |
21
|
|
|
Select2GridChannelAwareComponent.__super__.constructor.apply(this, arguments); |
22
|
|
|
}, |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @inheritDoc |
26
|
|
|
*/ |
27
|
|
|
initialize: function(options) { |
28
|
|
|
this.$sourceElement = options._sourceElement; |
29
|
|
|
this.channelId = _.result(options, 'channel_id') || this.channelId; |
30
|
|
|
this.channelFieldName = _.result(options, 'channel_field_name') || this.channelFieldName; |
31
|
|
|
this.gridName = options.configs.grid.name; |
32
|
|
|
Select2GridChannelAwareComponent.__super__.initialize.call(this, options); |
33
|
|
|
}, |
34
|
|
|
prepareViewOptions: function(options, config) { |
|
|
|
|
35
|
|
|
var opts = Select2GridChannelAwareComponent.__super__.prepareViewOptions.apply(this, arguments); |
36
|
|
|
opts.$channelSelector = this.findChannelSelectorElement(); |
37
|
|
|
opts.additionalParamsCb = _.bind(this._getAdditionalParams, this); |
38
|
|
|
|
39
|
|
|
return opts; |
40
|
|
|
}, |
41
|
|
|
preConfig: function(config) { |
42
|
|
|
Select2GridChannelAwareComponent.__super__.preConfig.call(this, config); |
43
|
|
|
|
44
|
|
|
var that = this; |
45
|
|
|
config.ajax.data = _.wrap(config.ajax.data, function(parentDataFunction) { |
46
|
|
|
var result = parentDataFunction.apply(this, _.rest(arguments)); |
47
|
|
|
|
48
|
|
|
return _.extend(result, that._getAdditionalParams()); |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
return config; |
52
|
|
|
}, |
53
|
|
|
findChannelSelectorElement: function() { |
54
|
|
|
return this.$sourceElement.closest('form').find('select[name="' + this.channelFieldName + '"]'); |
55
|
|
|
}, |
56
|
|
|
_getAdditionalParams: function() { |
57
|
|
|
var result = {}; |
58
|
|
|
var $channel = this.findChannelSelectorElement(); |
59
|
|
|
var channelIds = [$channel.val()]; |
60
|
|
|
|
61
|
|
|
if (this.channelId) { |
62
|
|
|
channelIds.push(this.channelId); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
result.channelIds = channelIds.join(','); |
66
|
|
|
|
67
|
|
|
result[this.gridName + '[channelIds]'] = channelIds.join(','); |
68
|
|
|
|
69
|
|
|
return result; |
70
|
|
|
} |
71
|
|
|
}); |
72
|
|
|
|
73
|
|
|
return Select2GridChannelAwareComponent; |
74
|
|
|
}); |
75
|
|
|
|
76
|
|
|
|