API Docs for:
Show:

File: view\MainView.js

  1. /*
  2. * BGPlay.js #9660
  3. * A web-based service for the visualization of the Internet routing
  4. *
  5. * Copyright (c) 2012 Roma Tre University and RIPE NCC
  6. *
  7. * See the file LICENSE.txt for copying permission.
  8. */
  9.  
  10. /**
  11. * MainView manages all the modules.
  12. * At initialization time it injects all the needed DOM elements.
  13. * Template: main.html
  14. * @class MainView
  15. * @module modules
  16. */
  17. var MainView=Backbone.View.extend({
  18.  
  19. /**
  20. * The initialization method of this object.
  21. * @method initialize
  22. * @param {Map} A map of parameters
  23. */
  24. initialize:function(){
  25. this.environment=this.options.environment;
  26. this.bgplay=this.environment.bgplay;
  27. this.fileRoot=this.environment.fileRoot;
  28. this.eventAggregator=this.environment.eventAggregator;
  29.  
  30. this.selectedNode=null;
  31. this.modulesLoaded=0;
  32. this.rootDom=$(this.el);
  33. this.autoStartFunctions=[];
  34.  
  35. this.eventAggregator.on("destroyAll", function(){
  36. this.destroyMe();
  37. },this);
  38.  
  39. this.eventAggregator.on("autoStartFunction", function(callback){
  40. this.autoStartFunctions.push(callback);
  41. },this);
  42.  
  43. this.render();
  44.  
  45. this.eventAggregator.on("moduleLoading",function(isLoading){
  46. if (isLoading==false){
  47. this.modulesLoaded++;
  48. }
  49. if (this.modulesLoaded==this.environment.modules.length){
  50. this.allModulesLoaded();
  51. }
  52. },this);
  53. },
  54.  
  55. /**
  56. * This method draws this module (eg. inject the DOM and elements).
  57. * @method render
  58. */
  59. render:function(){
  60. parseTemplate('main.html',this,this.el, "prepend");
  61. this.layoutManager();
  62. return this;
  63. },
  64.  
  65. /**
  66. * 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.
  67. * @method layoutManager
  68. */
  69. layoutManager:function(){
  70. var innerBorder=16;
  71. var marginTop=(this.environment.thisWidget)?100:0;
  72.  
  73. this.bgplayDom=this.environment.thisWidget.bgplayDom;
  74.  
  75. this.infoDiv=this.bgplayDom.find('.bgplayInfoDiv');
  76. this.centerDiv=this.bgplayDom.find('.bgplayCenterDiv');
  77. this.timelineDiv=this.bgplayDom.find('.bgplayTimelineDiv');
  78.  
  79. this.centerDiv.height(Math.max($(window).height() - this.infoDiv.outerHeight(true) - this.timelineDiv.outerHeight(true) - marginTop, this.environment.config.graph.paperMinHeight));
  80. this.centerDiv.width(this.rootDom.width()-innerBorder);
  81. this.timelineDiv.width(this.rootDom.width()-innerBorder);
  82. },
  83.  
  84. /**
  85. * This method initializes all the modules declared in the modules.js file.
  86. * In this environment a module is a View-Controller object:
  87. * - each module is responsible for its representation;
  88. * - each module is combined with a DOM element of the MainView's template;
  89. * - each DOM element has an ID with prefix 'bgplay' to avoid ambiguities with the background html.
  90. * @method loadViews
  91. */
  92. loadViews:function(){
  93. var module, element, n, length;
  94.  
  95.  
  96. for (n = 0, length=this.environment.modules.length; n<length; n++){
  97. module = this.environment.modules[n];
  98. if (module["type"]==this.environment.bgplay.get("type") || module["type"]=="all"){
  99. element = this.bgplayDom.find('.'+module.elementId);
  100. if (element!=null){
  101. new module.view({el:this.bgplayDom.find('.'+module.elementId), environment:this.environment});
  102. }else{
  103. new module.view({environment:this.environment});
  104. }
  105. }
  106. }
  107. },
  108.  
  109. /**
  110. * This method executes a set of functions when all the modules have been loaded.
  111. * @method allModulesLoaded
  112. */
  113. allModulesLoaded:function(){
  114. var n, length;
  115. this.autoStartFunctions.forEach(function(callback){
  116. callback.func.call(callback.context);
  117. });
  118. }
  119. });