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