forked from ezsystems/PlatformUIBundle
/
ez-locationviewview.js
430 lines (394 loc) · 13.9 KB
/
ez-locationviewview.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
/*
* Copyright (C) eZ Systems AS. All rights reserved.
* For full copyright and license information view LICENSE file distributed with this source code.
*/
YUI.add('ez-locationviewview', function (Y) {
"use strict";
/**
* Provides the Location view View class
*
* @module ez-locationviewview
*/
Y.namespace('eZ');
var MINIMIZE_ACTION_BAR_CLASS = 'is-actionbar-minimized';
/**
* The location view view
*
* @namespace eZ
* @class LocationViewView
* @constructor
* @extends eZ.TemplateBasedView
*/
Y.eZ.LocationViewView = Y.Base.create('locationViewView', Y.eZ.TemplateBasedView, [Y.eZ.Tabs], {
initializer: function () {
this.on('*:minimizeActionBarAction', this._handleMinimizeActionBar);
this.after('changeTab', this._syncSelectedTab);
this.after('selectedTabChange', this._syncTabSelectedAttr);
this.after('activeChange', function () {
Y.Array.each(this.get('tabs'), function (t) {
t.set('active', this.get('active'));
}, this);
});
},
/**
* Event handler for the minimizeActionBarAction event
*
* @protected
* @method _handleMinimizeActionBar
*/
_handleMinimizeActionBar: function () {
this.get('container').toggleClass(MINIMIZE_ACTION_BAR_CLASS);
},
/**
* Converts each location in the path to a plain object representation
*
* @method _pathToJSON
* @private
* @return Array
*/
_pathToJSON: function () {
return Y.Array.map(this.get('path'), function (location) {
return location.toJSON();
});
},
/**
* Renders the location view
*
* @method render
* @return {eZ.LocationViewView} the view itself
*/
render: function () {
var container = this.get('container'),
subitemBox = this.get('subitemBox');
container.setHTML(this.template({
location: this.get('location').toJSON(),
content: this.get('content').toJSON(),
contentType: this.get('contentType').toJSON(),
tabs: this._getTabsList(),
path: this._pathToJSON()
}));
container.one('.ez-actionbar-container').append(
this.get('actionBar').render().get('container')
);
this._renderTabViews();
if ( subitemBox ) {
container.one('.ez-subitem-container').append(
subitemBox.render().get('container')
);
}
this._uiSetMinHeight();
return this;
},
/**
* Renders the tab views in their container.
*
* @method _renderTabViews
* @protected
*/
_renderTabViews: function () {
var container = this.get('container');
Y.Array.each(this.get('tabs'), function (tab) {
container.one('#ez-tabs-' + tab.get('identifier')).append(
tab.render().get('container')
);
});
},
/**
* Returns the tabs list suitable for the template. Each element in the
* returned array is an object containing the title, the identifier and
* whether the tab is selected.
*
* @method _getTabsList
* @protected
* @return {Array}
*/
_getTabsList: function () {
var tabs = [];
Y.Array.each(this.get('tabs'), function (tab) {
tabs.push({
title: tab.get('title'),
identifier: tab.get('identifier'),
selected: tab.get('identifier') === this.get('selectedTab'),
});
}, this);
return tabs;
},
/**
* `changeTab` event handler. It synchronizes the `selectedTab`
* attribute.
*
* @method _syncSelectedTab
* @protected
* @param {EventFacade} e the changeTab event facade
*/
_syncSelectedTab: function (e) {
this._set('selectedTab', e.tabLabelNode.getAttribute('data-tab-identifier'));
},
/**
* `selectedTabChange` event handler. It makes sure the the `selectedTab`
* attribute and the tab view's `selected` attribute are in sync.
*
* @method _syncTabSelectedAttr
* @protected
*/
_syncTabSelectedAttr: function () {
Y.Array.each(this.get('tabs'), function (tab) {
tab.set('selected', this.get('selectedTab') === tab.get('identifier'));
}, this);
},
/**
* Returns the title of the page when the location view is the active
* view.
*
* @method getTitle
* @return String
*/
getTitle: function () {
var title = this.get('content').get('name');
return Y.Array.reduce(this.get('path'), title, function (title, val) {
return title + ' / ' + val.get('contentInfo').get('name');
});
},
/**
* Sets the minimum height of the view
*
* @private
* @method _uiSetMinHeight
*/
_uiSetMinHeight: function () {
var container = this.get('container');
container.one('.ez-locationview-content').setStyle(
'minHeight', container.get('winHeight') + 'px'
);
},
/**
* Adds a tabView to the list of tabs.
*
* @method addTabView
* @param {eZ.LocationViewTabView} tabView
*/
addTabView: function (tabView) {
var tabs = this.get('tabs');
tabs.push(tabView);
tabView.addTarget(this);
tabs.sort(function (a, b) {
return b.get('priority') - a.get('priority');
});
},
/**
* Removes a tab from its identifier. When found, the location view is
* removed from the bubble targets list of the tabView.
*
* @method removeTabView
* @param {String} identifier
* @return {eZ.LocationViewTabView|Null} the removed tab view or null
*/
removeTabView: function (identifier) {
var removed = null;
this._set('tabs', Y.Array.reject(this.get('tabs'), function (tab) {
if ( tab.get('identifier') === identifier ) {
tab.removeTarget(this);
removed = tab;
return true;
}
}, this));
return removed;
},
destructor: function () {
var bar = this.get('actionBar'),
subitemBox = this.get('subitemBox');
bar.removeTarget(this);
bar.destroy();
Y.Array.each(this.get('tabs'), function (tab) {
tab.removeTarget(this);
tab.destroy();
});
if ( subitemBox ) {
subitemBox.removeTarget(this);
subitemBox.destroy();
}
}
}, {
ATTRS: {
/**
* The location being rendered
*
* @attribute location
* @type Y.eZ.Location
* @writeOnce
*/
location: {
writeOnce: "initOnly",
},
/**
* The content associated the current location
*
* @attribute content
* @type Y.eZ.Content
* @writeOnce
*/
content: {
writeOnce: "initOnly",
},
/**
* The content type of the content at the current location
*
* @attribute contentType
* @type Y.eZ.ContentType
* @writeOnce
*/
contentType: {
writeOnce: "initOnly",
},
/**
* The path from the root location to the current location. Each
* entry of the path consists of the location.
*
* @attribute path
* @type Array
* @writeOnce
*/
path: {
writeOnce: "initOnly",
},
/**
* Language code of language currently active for the current location
*
* @attribute languageCode
* @type String
*/
languageCode: {},
/**
* The action bar instance, by default an instance {{#crossLink
* "eZ.ActionBarView"}}eZ.ActionBarView{{/crossLink}}
*
* @attribute actionBar
* @type eZ.BarView
*/
actionBar: {
valueFn: function () {
return new Y.eZ.ActionBarView({
location: this.get('location'),
content: this.get('content'),
contentType: this.get('contentType'),
config: this.get('config'),
bubbleTargets: this,
});
}
},
/**
* The list of the Location View tab Views.
* Do NOT change this attribute directly, use addTabView or
* removeTabView to handle the tabs list.
*
* @attribute tabs
* @type {Array} of {eZ.LocationViewTabView}
* @writeOnce
*/
tabs: {
valueFn: function () {
return [
new Y.eZ.LocationViewViewTabView({
content: this.get('content'),
location: this.get('location'),
contentType: this.get('contentType'),
config: this.get('config'),
languageCode: this.get('languageCode'),
priority: 4000,
selected: true,
bubbleTargets: this,
}),
new Y.eZ.LocationViewDetailsTabView({
content: this.get('content'),
location: this.get('location'),
config: this.get('config'),
priority: 3000,
selected: false,
bubbleTargets: this,
}),
new Y.eZ.LocationViewVersionsTabView({
content: this.get('content'),
config: this.get('config'),
priority: 2500,
selected: false,
bubbleTargets: this,
}),
new Y.eZ.LocationViewLocationsTabView({
content: this.get('content'),
location: this.get('location'),
config: this.get('config'),
priority: 2000,
selected: false,
bubbleTargets: this,
}),
new Y.eZ.LocationViewRelationsTabView({
content: this.get('content'),
contentType: this.get('contentType'),
config: this.get('config'),
priority: 1000,
selected: false,
bubbleTargets: this,
}),
];
},
writeOnce: 'initOnly',
},
/**
* The subitem box view or null if the content (type) is not
* configured to be a container.
*
* @attribute subitemBox
* @type {eZ.SubitemBoxView|Null}
* @writeOnce
*/
subitemBox: {
valueFn: function () {
var contentType = this.get('contentType');
if ( contentType && contentType.get('isContainer') ) {
return new Y.eZ.SubitemBoxView({
location: this.get('location'),
content: this.get('content'),
contentType: this.get('contentType'),
config: this.get('config'),
bubbleTargets: this,
});
}
return null;
},
writeOnce: 'initOnly',
},
/**
* Returns the subitem list view. This attribute is deprecated and
* will be removed in PlatformUI 2.0
*
* @attribute subitemList
* @writeOnce
* @type {eZ.SubitemListView|Null}
* @deprecated
*/
subitemList: {
writeOnce: 'initOnly',
valueFn: function () {
var box = this.get('subitemBox');
if ( !box ) {
return null;
}
return Y.Array.find(box.get('subitemViews'), function (view) {
return view.get('identifier') === 'list';
});
},
},
/**
* Stores the identifier of the selected tab.
*
* @attribute selectedTab
* @type {String}
* @readOnly
*/
selectedTab: {
value: "view",
readOnly: true,
}
}
});
});