API Docs for:
Show:

File: view\LivePermalinkView.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. * LivePermalinkView provides a dynamic permalink composed of parameters changed due to user interaction.
  12. * @class LivePermalinkView
  13. * @module modules
  14. */
  15. var LivePermalinkView=Backbone.View.extend({
  16.  
  17. /**
  18. * The initialization method of this object.
  19. * @method initialize
  20. * @param {Map} A map of parameters
  21. */
  22. initialize:function(){
  23. this.environment=this.options.environment;
  24. this.bgplay=this.environment.bgplay;
  25. this.fileRoot=this.environment.fileRoot;
  26. this.eventAggregator=this.environment.eventAggregator;
  27.  
  28. this.eventAggregator.trigger("moduleLoading", true);
  29.  
  30. this.positions="";
  31. this.eventAggregator.on("destroyAll", function(){
  32. this.destroyMe();
  33. },this);
  34. this.render();
  35. this.eventManager();
  36. this.managePermalink();
  37.  
  38. this.bgplay.on("change:cur_instant",function(){
  39. this.managePermalink();
  40. },this);
  41.  
  42. this.eventAggregator.trigger("moduleLoading", false);
  43. },
  44.  
  45. /**
  46. * This method draws this module (eg. inject the DOM and elements).
  47. * @method render
  48. */
  49. render:function(){
  50. var statWidget = this.environment.thisWidget.dom.closest('.stat-widget');
  51. this.permalinkPopup = statWidget.find('.permalink');
  52. this.permalinkPopup.append('<div style="width:120px;height:15px;position:absolute;bottom:50px;right:20px;"><input style="width:15px;" type="checkbox" name="liveCheck" value="0"/>Dynamic URL</div>');
  53. this.liveCheck = this.permalinkPopup.find('input[name=liveCheck]');
  54. this.permalinkField = this.permalinkPopup.children('input');
  55.  
  56. return this;
  57. },
  58.  
  59. /**
  60. * This method manages the events of the built DOM.
  61. * @method eventManager
  62. */
  63. eventManager:function(){
  64. var $this=this;
  65.  
  66. this.liveCheck.click(function(){
  67. $this.managePermalink();
  68. });
  69. },
  70.  
  71. /**
  72. * This method dispatches the computation of permalinks.
  73. * @method eventManager
  74. */
  75. managePermalink:function(){
  76. if (this.permalinkPopup.is(':visible')){
  77. if (this.liveCheck.is(':checked')){
  78. this.permalinkField.val(this.generateDynamicPermalink(this.environment.jsonWrap.setParams(this.environment.params)));
  79. }else{
  80. if (this.staticPermalink==null){
  81. this.staticPermalink = this.generateStaticPermalink(this.environment.jsonWrap.setParams(this.environment.params));
  82. }
  83. this.permalinkField.val(this.staticPermalink );
  84. }
  85. }
  86. },
  87.  
  88. /**
  89. * This method computes dynamic permalinks.
  90. * @method generateDynamicPermalink
  91. */
  92. generateDynamicPermalink:function(params) {
  93. var out = "";
  94. for (var key in params) {
  95. if (!this.environment.optionalParams.contains(key)){
  96. out += "w." + key + "=" + params[key]+"&";
  97. }
  98. }
  99. return STAT_HOME + 'widget/bgplay#' + out.slice(0, -1);
  100. },
  101.  
  102. /**
  103. * This method computes static permalinks.
  104. * @method generateStaticPermalink
  105. */
  106. generateStaticPermalink:function(params) {
  107. var out = "";
  108. for (var key in params) {
  109. if (!this.environment.optionalParams.contains(key) && !this.environment.dynamicParams.contains(key)){
  110. out += "w." + key + "=" + params[key]+"&";
  111. }
  112. }
  113. return STAT_HOME + 'widget/bgplay#' + out.slice(0, -1);
  114. }
  115. });