Mercurial > hg > dml-open-vis
comparison src/DML/MainVisBundle/Resources/assets/marionette/modules/MainRegionModule/MainRegionModule.01-MainRegionView.js @ 0:493bcb69166c
added public content
author | Daniel Wolff |
---|---|
date | Tue, 09 Feb 2016 20:54:02 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:493bcb69166c |
---|---|
1 "use strict"; | |
2 | |
3 App.module("MainRegionModule", function (MainRegionModule, App, Backbone, Marionette, $, _, Logger) { | |
4 | |
5 MainRegionModule.MainRegionView = Backbone.View.extend({ | |
6 | |
7 initialize: function(options) { | |
8 var _this = this; | |
9 _this.options = _.defaults(options || {}, this.options); | |
10 | |
11 var $collectionsGridEl = _this.$(".config-grid"); | |
12 var $recordingsGridEl = $collectionsGridEl.clone(); | |
13 $recordingsGridEl.appendTo(_this.el); | |
14 | |
15 // Render when the state changes | |
16 _this.options.state.on("change", function() { | |
17 _this.render(); | |
18 }); | |
19 | |
20 // Init sub-views | |
21 _this._musicCollectionConfigGridView = new MainRegionModule.ConfigGridView({ | |
22 el: $collectionsGridEl, | |
23 state: _this.options.state, | |
24 configGrid: _this.options.state.get("musicCollectionGrid"), | |
25 parentState: _this.options.state, | |
26 parentContainerElement: _this.el | |
27 }); | |
28 | |
29 _this._musicRecordingConfigGridView = new MainRegionModule.ConfigGridView({ | |
30 el: $recordingsGridEl, | |
31 state: _this.options.state, | |
32 configGrid: _this.options.state.get("musicRecordingGrid"), | |
33 parentState: _this.options.state, | |
34 parentContainerElement: _this.el | |
35 }); | |
36 | |
37 _this._$flipper = $.bem.generateElement("main-region", "flipper"); | |
38 | |
39 _this._$flipper.append( | |
40 _this._musicRecordingConfigGridView.$ghost, | |
41 _this._musicCollectionConfigGridView.$ghost | |
42 ); | |
43 _this._$flipperContainer = $.bem.generateElement("main-region", "flipper-container"); | |
44 _this._$flipperContainer.append(_this._$flipper); | |
45 | |
46 _this._$flipper.on( | |
47 "transitionend MSTransitionEnd webkitTransitionEnd oTransitionEnd", | |
48 function() { | |
49 _this._stopFlipping(); | |
50 } | |
51 ); | |
52 | |
53 _this.render(true, true); | |
54 }, | |
55 | |
56 render: function(deep, instant) { | |
57 var _this = this; | |
58 | |
59 var musicRecordingsGridNeedsToBeShown = !! _this.options.state.get("musicRecordingsGridIsShown"); | |
60 var gridViewToShow = musicRecordingsGridNeedsToBeShown ? _this._musicRecordingConfigGridView : _this._musicCollectionConfigGridView; | |
61 var gridViewToHide = !musicRecordingsGridNeedsToBeShown ? _this._musicRecordingConfigGridView : _this._musicCollectionConfigGridView; | |
62 | |
63 // need to swap grids | |
64 if (!gridViewToShow.el.getAttribute("data-active")) { | |
65 | |
66 // launch the flipper | |
67 if (!instant) { | |
68 if (!_this.isSwitchingBetweenGrids()) { | |
69 _this._$flipper.removeClass("main-region__flipper_animating"); | |
70 _this._$flipper.setMod("main-region", "flipper", "to", !musicRecordingsGridNeedsToBeShown ? "recording" : "collection"); | |
71 _this._$flipper.addClass("main-region__flipper_animating"); | |
72 _this._$flipperContainer.appendTo(_this.el); | |
73 } | |
74 setTimeout(function() { | |
75 _this._$flipper.setMod("main-region", "flipper", "to", musicRecordingsGridNeedsToBeShown ? "recording" : "collection"); | |
76 }, 10); | |
77 } | |
78 | |
79 // swap the grids and render a new current one | |
80 gridViewToHide.$el.attr("data-active", null).detach(); | |
81 gridViewToShow.$el.attr("data-active", "1") .appendTo(_this.$el); | |
82 // gridViewToHide.$el.attr("data-active", null).hide(); | |
83 // gridViewToShow.$el.attr("data-active", "1") .show(); | |
84 gridViewToShow.render(true, true); | |
85 | |
86 // no need to swap grids - render only if it's a deep render | |
87 } else if (deep) { | |
88 gridViewToShow.render(deep, instant); | |
89 } | |
90 }, | |
91 | |
92 isSwitchingBetweenGrids: function() { | |
93 var _this = this; | |
94 return _this._$flipperContainer.parent().length; | |
95 }, | |
96 | |
97 _stopFlipping: function() { | |
98 var _this = this; | |
99 _this._$flipperContainer.detach(); | |
100 }, | |
101 }); | |
102 }, Logger); |