File: view\MainView.js
- /*
- * BGPlay.js #9660
- * A web-based service for the visualization of the Internet routing
- *
- * Copyright (c) 2012 Roma Tre University and RIPE NCC
- *
- * See the file LICENSE.txt for copying permission.
- */
-
- /**
- * MainView manages all the modules.
- * At initialization time it injects all the needed DOM elements.
- * Template: main.html
- * @class MainView
- * @module modules
- */
- var MainView=Backbone.View.extend({
-
- /**
- * The initialization method of this object.
- * @method initialize
- * @param {Map} A map of parameters
- */
- initialize:function(){
- this.environment=this.options.environment;
- this.bgplay=this.environment.bgplay;
- this.fileRoot=this.environment.fileRoot;
- this.eventAggregator=this.environment.eventAggregator;
-
- this.selectedNode=null;
- this.modulesLoaded=0;
- this.rootDom=$(this.el);
- this.autoStartFunctions=[];
-
- this.eventAggregator.on("destroyAll", function(){
- this.destroyMe();
- },this);
-
- this.eventAggregator.on("autoStartFunction", function(callback){
- this.autoStartFunctions.push(callback);
- },this);
-
- this.render();
-
- this.eventAggregator.on("moduleLoading",function(isLoading){
- if (isLoading==false){
- this.modulesLoaded++;
- }
- if (this.modulesLoaded==this.environment.modules.length){
- this.allModulesLoaded();
- }
- },this);
- },
-
- /**
- * This method draws this module (eg. inject the DOM and elements).
- * @method render
- */
- render:function(){
- parseTemplate('main.html',this,this.el, "prepend");
- this.layoutManager();
- return this;
- },
-
- /**
- * This method alters the layout at run-time. It should be used only when absolutely necessary preferring instead a static CSS+HTML+Mustaches.js layout.
- * @method layoutManager
- */
- layoutManager:function(){
- var innerBorder=16;
- var marginTop=(this.environment.thisWidget)?100:0;
-
- this.bgplayDom=this.environment.thisWidget.bgplayDom;
-
- this.infoDiv=this.bgplayDom.find('.bgplayInfoDiv');
- this.centerDiv=this.bgplayDom.find('.bgplayCenterDiv');
- this.timelineDiv=this.bgplayDom.find('.bgplayTimelineDiv');
-
- this.centerDiv.height(Math.max($(window).height() - this.infoDiv.outerHeight(true) - this.timelineDiv.outerHeight(true) - marginTop, this.environment.config.graph.paperMinHeight));
- this.centerDiv.width(this.rootDom.width()-innerBorder);
- this.timelineDiv.width(this.rootDom.width()-innerBorder);
- },
-
- /**
- * This method initializes all the modules declared in the modules.js file.
- * In this environment a module is a View-Controller object:
- * - each module is responsible for its representation;
- * - each module is combined with a DOM element of the MainView's template;
- * - each DOM element has an ID with prefix 'bgplay' to avoid ambiguities with the background html.
- * @method loadViews
- */
- loadViews:function(){
- var module, element, n, length;
-
-
- for (n = 0, length=this.environment.modules.length; n<length; n++){
- module = this.environment.modules[n];
- if (module["type"]==this.environment.bgplay.get("type") || module["type"]=="all"){
- element = this.bgplayDom.find('.'+module.elementId);
- if (element!=null){
- new module.view({el:this.bgplayDom.find('.'+module.elementId), environment:this.environment});
- }else{
- new module.view({environment:this.environment});
- }
- }
- }
- },
-
- /**
- * This method executes a set of functions when all the modules have been loaded.
- * @method allModulesLoaded
- */
- allModulesLoaded:function(){
- var n, length;
- this.autoStartFunctions.forEach(function(callback){
- callback.func.call(callback.context);
- });
- }
- });
-