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
|
|
|
constructor: function ContentSidebarView() { |
54
|
|
|
ContentSidebarView.__super__.constructor.apply(this, arguments); |
55
|
|
|
}, |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritDoc} |
59
|
|
|
*/ |
60
|
|
|
initialize: function(options) { |
|
|
|
|
61
|
|
|
if (this.resizableSidebar) { |
62
|
|
|
this.initResizableSidebar(); |
63
|
|
|
} |
64
|
|
|
ContentSidebarView.__super__.initialize.call(this, arguments); |
65
|
|
|
|
66
|
|
|
mediator.on('swipe-action-left', this.minimize, this); |
67
|
|
|
mediator.on('swipe-action-right', this.maximize, this); |
68
|
|
|
}, |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritDoc} |
72
|
|
|
*/ |
73
|
|
|
render: function() { |
74
|
|
|
if (this.fixSidebarHeight && !tools.isMobile()) { |
75
|
|
|
layoutHelper.setAvailableHeight(this.scrollbar, this.$el); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
this._toggle(this.getSidebarState()); |
79
|
|
|
|
80
|
|
|
ContentSidebarView.__super__.render.apply(this, arguments); |
81
|
|
|
}, |
82
|
|
|
|
83
|
|
|
initResizableSidebar: function() { |
84
|
|
|
this.pluginManager = new PluginManager(this); |
85
|
|
|
this.pluginManager.create(ResizableAreaPlugin, { |
86
|
|
|
$resizableEl: this.sidebar, |
87
|
|
|
resizableOptions: { |
88
|
|
|
resize: _.bind(this._resize, this), |
89
|
|
|
create: _.bind(this._create, this) |
90
|
|
|
} |
91
|
|
|
}); |
92
|
|
|
}, |
93
|
|
|
|
94
|
|
|
getSidebarState: function() { |
95
|
|
|
return tools.unpackFromQueryString(location.search).sidebar || 'on'; |
96
|
|
|
}, |
97
|
|
|
|
98
|
|
|
minimize: function() { |
99
|
|
|
this._toggle('off'); |
100
|
|
|
}, |
101
|
|
|
|
102
|
|
|
maximize: function() { |
103
|
|
|
this._toggle('on'); |
104
|
|
|
}, |
105
|
|
|
|
106
|
|
|
_create: function() { |
107
|
|
|
this.$(this.content).css({ |
108
|
|
|
width: 'calc(100% - ' + this.$(this.sidebar).outerWidth() + 'px)' |
109
|
|
|
}); |
110
|
|
|
}, |
111
|
|
|
|
112
|
|
|
_resize: function(event, ui) { |
113
|
|
|
this.$(this.content).css({ |
114
|
|
|
width: 'calc(100% - ' + ui.size.width + 'px)' |
115
|
|
|
}); |
116
|
|
|
}, |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @private |
120
|
|
|
* @param {String} state |
121
|
|
|
*/ |
122
|
|
|
_toggle: function(state) { |
123
|
|
|
var show = state === 'on'; |
124
|
|
|
|
125
|
|
|
if (this.resizableSidebar) { |
126
|
|
|
if (!show) { |
127
|
|
|
this.pluginManager.getInstance(ResizableAreaPlugin).removePreviousState(); |
128
|
|
|
this.$(this.content).css({ |
129
|
|
|
width: '' |
130
|
|
|
}); |
131
|
|
|
} |
132
|
|
|
this.pluginManager[show ? 'enable' : 'disable'](ResizableAreaPlugin); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
if (!this.resizableSidebar && !show) { |
136
|
|
|
this.$(this.sidebar).css({ |
137
|
|
|
width: '' |
138
|
|
|
}); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
this.$(this.sidebar).toggleClass('content-sidebar-minimized', !show); |
142
|
|
|
mediator.execute('changeUrlParam', 'sidebar', show ? null : state); |
143
|
|
|
}, |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @inheritDoc |
147
|
|
|
*/ |
148
|
|
|
dispose: function() { |
149
|
|
|
if (this.pluginManager) { |
150
|
|
|
this.pluginManager.dispose(); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
ContentSidebarView.__super__.dispose.call(this); |
154
|
|
|
} |
155
|
|
|
}); |
156
|
|
|
|
157
|
|
|
return ContentSidebarView; |
158
|
|
|
}); |
159
|
|
|
|
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.