1
|
|
|
define(function(require) { |
2
|
|
|
'use strict'; |
3
|
|
|
|
4
|
|
|
var AccountMulticustomerView; |
5
|
|
|
var _ = require('underscore'); |
6
|
|
|
var $ = require('jquery'); |
7
|
|
|
var BaseView = require('oroui/js/app/views/base/view'); |
8
|
|
|
|
9
|
|
|
AccountMulticustomerView = BaseView.extend({ |
10
|
|
|
|
11
|
|
|
activeTab: null, |
12
|
|
|
|
13
|
|
|
customerType: 'sales_b2bcustomer', |
14
|
|
|
|
15
|
|
|
useChannel: true, |
16
|
|
|
|
17
|
|
|
events: { |
18
|
|
|
'shown.bs.tab .tab-content': 'onTabShown', |
19
|
|
|
'shown.bs.tab >.oro-tabs>ul': 'onCustomerShown' |
20
|
|
|
}, |
21
|
|
|
|
22
|
|
|
listen: { |
23
|
|
|
'customer-info-widget:init mediator': function(widget, options) { |
24
|
|
|
if (this.$(options.container || options.el).length !== 0) { |
25
|
|
|
widget.setActiveTab(this.activeTab); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
}, |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @inheritDoc |
32
|
|
|
*/ |
33
|
|
|
constructor: function AccountMulticustomerView() { |
34
|
|
|
AccountMulticustomerView.__super__.constructor.apply(this, arguments); |
35
|
|
|
}, |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @inheritDoc |
39
|
|
|
*/ |
40
|
|
|
initialize: function(options) { |
41
|
|
|
_.extend(this, _.pick(options, ['customerType', 'useChannel'])); |
42
|
|
|
AccountMulticustomerView.__super__.initialize.call(this, options); |
43
|
|
|
}, |
44
|
|
|
|
45
|
|
|
onTabShown: function(e) { |
46
|
|
|
var contentId = this.$(e.target).data('target'); |
47
|
|
|
var targetRegExp = this.makeTargetRegExp('(.*)'); |
48
|
|
|
this.activeTab = _.result(contentId.match(targetRegExp), 1, null); |
49
|
|
|
}, |
50
|
|
|
|
51
|
|
|
onCustomerShown: function(e) { |
|
|
|
|
52
|
|
|
if (this.activeTab) { |
53
|
|
|
var targetRegExp = this.makeTargetRegExp(this.activeTab); |
54
|
|
|
var $link = this.$('a[data-target]:visible').filter(function() { |
55
|
|
|
return targetRegExp.test($(this).data('target')); |
56
|
|
|
}); |
57
|
|
|
if ($link.length === 1 && !$link.parent().hasClass('active')) { |
58
|
|
|
$link.click(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
}, |
62
|
|
|
|
63
|
|
|
makeTargetRegExp: function(activeTabPlaceholder) { |
64
|
|
|
var pattern = '#oro_' + this.customerType + '_' + activeTabPlaceholder + '_customer_\\d+'; |
65
|
|
|
if (this.useChannel) { |
66
|
|
|
pattern += '_channel_\\d+'; |
67
|
|
|
} |
68
|
|
|
return new RegExp(pattern); |
69
|
|
|
} |
70
|
|
|
}); |
71
|
|
|
|
72
|
|
|
return AccountMulticustomerView; |
73
|
|
|
}); |
74
|
|
|
|
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.