1
|
|
|
define(function(require) { |
2
|
|
|
'use strict'; |
3
|
|
|
|
4
|
|
|
var ContentSidebarView; |
5
|
|
|
var _ = require('underscore'); |
6
|
|
|
var tools = require('oroui/js/tools'); |
7
|
|
|
var BaseView = require('oroui/js/app/views/base/view'); |
8
|
|
|
var layoutHelper = require('oroui/js/tools/layout-helper'); |
9
|
|
|
var mediator = require('oroui/js/mediator'); |
10
|
|
|
var ResizableAreaPlugin = require('oroui/js/app/plugins/plugin-resizable-area'); |
11
|
|
|
var PluginManager = require('oroui/js/app/plugins/plugin-manager'); |
12
|
|
|
var config = require('module').config(); |
13
|
|
|
|
14
|
|
|
config = _.extend({ |
15
|
|
|
autoRender: true, |
16
|
|
|
fixSidebarHeight: true, |
17
|
|
|
sidebar: '[data-role="sidebar"]', |
18
|
|
|
scrollbar: '[data-role="sidebar"]', |
19
|
|
|
content: '[data-role="content"]', |
20
|
|
|
resizableSidebar: !tools.isMobile() |
21
|
|
|
}, config); |
22
|
|
|
|
23
|
|
|
ContentSidebarView = BaseView.extend({ |
24
|
|
|
optionNames: BaseView.prototype.optionNames.concat([ |
25
|
|
|
'autoRender', |
26
|
|
|
'fixSidebarHeight', |
27
|
|
|
'sidebar', |
28
|
|
|
'scrollbar', |
29
|
|
|
'content', |
30
|
|
|
'resizableSidebar' |
31
|
|
|
]), |
32
|
|
|
|
33
|
|
|
autoRender: config.autoRender, |
34
|
|
|
|
35
|
|
|
fixSidebarHeight: config.fixSidebarHeight, |
36
|
|
|
|
37
|
|
|
sidebar: config.sidebar, |
38
|
|
|
|
39
|
|
|
scrollbar: config.scrollbar, |
40
|
|
|
|
41
|
|
|
content: config.content, |
42
|
|
|
|
43
|
|
|
resizableSidebar: config.resizableSidebar, |
44
|
|
|
|
45
|
|
|
events: { |
46
|
|
|
'click [data-role="sidebar-minimize"]': 'minimize', |
47
|
|
|
'click [data-role="sidebar-maximize"]': 'maximize' |
48
|
|
|
}, |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritDoc} |
52
|
|
|
*/ |
53
|
|
|
initialize: function(options) { |
|
|
|
|
54
|
|
|
if (this.resizableSidebar) { |
55
|
|
|
this.initResizableSidebar(); |
56
|
|
|
} |
57
|
|
|
ContentSidebarView.__super__.initialize.call(this, arguments); |
58
|
|
|
}, |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritDoc} |
63
|
|
|
*/ |
64
|
|
|
render: function() { |
65
|
|
|
if (this.fixSidebarHeight && !tools.isMobile()) { |
66
|
|
|
layoutHelper.setAvailableHeight(this.scrollbar, this.$el); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
this._toggle(this.getSidebarState()); |
70
|
|
|
|
71
|
|
|
ContentSidebarView.__super__.render.apply(this, arguments); |
72
|
|
|
}, |
73
|
|
|
|
74
|
|
|
initResizableSidebar: function() { |
75
|
|
|
this.pluginManager = new PluginManager(this); |
76
|
|
|
this.pluginManager.create(ResizableAreaPlugin, { |
77
|
|
|
$resizableEl: this.sidebar |
78
|
|
|
}); |
79
|
|
|
}, |
80
|
|
|
|
81
|
|
|
getSidebarState: function() { |
82
|
|
|
return tools.unpackFromQueryString(location.search).sidebar || 'on'; |
83
|
|
|
}, |
84
|
|
|
|
85
|
|
|
minimize: function() { |
86
|
|
|
this._toggle('off'); |
87
|
|
|
}, |
88
|
|
|
|
89
|
|
|
maximize: function() { |
90
|
|
|
this._toggle('on'); |
91
|
|
|
}, |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @private |
95
|
|
|
* @param {String} state |
96
|
|
|
*/ |
97
|
|
|
_toggle: function(state) { |
98
|
|
|
var show = state === 'on'; |
99
|
|
|
|
100
|
|
|
if (this.resizableSidebar) { |
101
|
|
|
if (!show) { |
102
|
|
|
this.pluginManager.getInstance(ResizableAreaPlugin).removePreviousState(); |
103
|
|
|
} |
104
|
|
|
this.pluginManager[show ? 'enable' : 'disable'](ResizableAreaPlugin); |
105
|
|
|
} |
106
|
|
|
this.$(this.sidebar).toggleClass('content-sidebar-minimized', !show); |
107
|
|
|
mediator.execute('changeUrlParam', 'sidebar', show ? null : state); |
108
|
|
|
}, |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @inheritDoc |
112
|
|
|
*/ |
113
|
|
|
dispose: function() { |
114
|
|
|
if (this.pluginManager) { |
115
|
|
|
this.pluginManager.dispose(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
ContentSidebarView.__super__.dispose.call(this); |
119
|
|
|
} |
120
|
|
|
}); |
121
|
|
|
|
122
|
|
|
return ContentSidebarView; |
123
|
|
|
}); |
124
|
|
|
|
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.