Revision 228d0df5

View differences:

src/sunstone/public/app/app.js
27 27

  
28 28
  _setupDataTableSearch();
29 29

  
30
  var DASHBOARD_TAB_ID = require('tabs/dashboard-tab/tabId');
31 30
  var SETTINGS_TAB_ID = require('tabs/settings-tab/tabId');
32 31
  var PROVISION_TAB_ID = require('tabs/provision-tab/tabId');
33 32
  var Sunstone = require('sunstone');
......
61 60
      Menu.insertProvision();
62 61
    }else{
63 62
      Menu.insert();
63
      Sunstone.setupNavigoRoutes();
64 64
    }
65 65

  
66 66
    _setupAccordion();
......
69 69

  
70 70
    if (Config.isTabEnabled(PROVISION_TAB_ID)) {
71 71
      Sunstone.showTab(PROVISION_TAB_ID);
72
      $('#loading').hide();
73
    } else if (Config.isTabEnabled(DASHBOARD_TAB_ID)) {
74
      Sunstone.showTab(DASHBOARD_TAB_ID);
75
      $('#loading').hide();
76 72
    }
73

  
74
    $('#loading').hide();
77 75
  });
78 76

  
79 77
  function _setupCloseDropdownsOnClick() {
src/sunstone/public/app/main.js
107 107
    'spice-filexfer': '../bower_components/spice-html5/filexfer',
108 108

  
109 109
    /* vis.js */
110
    'vis': '../bower_components/vis/dist/vis.min'
110
    'vis': '../bower_components/vis/dist/vis.min',
111

  
112
    /* navigo */
113
    'Navigo': '../bower_components/navigo/lib/navigo.min'
111 114
  },
112 115
  shim: {
113 116
    /* Tabs */
src/sunstone/public/app/sunstone.js
25 25
  var Notifier = require('utils/notifier');
26 26
  var Menu = require('utils/menu');
27 27
  var Tips = require('utils/tips');
28
  var Navigo = require('Navigo');
29

  
30
  var router;
28 31

  
29 32
  var TOP_INTERVAL = 10000; //ms
30 33
  var CONFIRM_DIALOG_ID = require('utils/dialogs/confirm/dialogId');
31 34
  var CONFIRM_WITH_SELECT_DIALOG_ID = require('utils/dialogs/confirm-with-select/dialogId');
35
  var DASHBOARD_TAB_ID = require('tabs/dashboard-tab/tabId');
32 36

  
33 37
  var SunstoneCfg = {
34 38
    "actions" : {},
......
121 125

  
122 126
  //Inserts all main tabs in the DOM
123 127
  var _insertTabs = function() {
124
    for (tabName in SunstoneCfg["tabs"]) {
128
    for (var tabName in SunstoneCfg["tabs"]) {
125 129
      _insertTab(tabName);
126 130
      _insertButtonsInTab(tabName);
127 131
      _setupDataTable(tabName);
......
505 509

  
506 510
    // Button to return to the list view from the detailed view
507 511
    $(document).on("click", "button[href='back']", function(e) {
508
      $(".navigation-active-li a", $("#navigation")).click();
512
      window.history.back();
509 513
      e.preventDefault();
510 514
    });
511 515
  }
......
572 576
  }
573 577

  
574 578
  var _showTab = function(tabName) {
579
    if (_getTab() == tabName && _rightListVisible()){
580
      _routerShowTab(tabName);
581
    } else {
582
      if (router != undefined){
583
        router.navigate(tabName);
584
      }else{
585
        _routerShowTab(tabName);
586
      }
587
    }
588
  }
589

  
590
  var _routerShowTab = function(tabName) {
575 591
    $('.labels-tree', '#navigation').remove();
576 592

  
577 593
    if (!SunstoneCfg['tabs'][tabName]) {
......
614 630
    return $(".tab:visible").attr("id");
615 631
  }
616 632

  
617
  var _showElement = function(tabName, infoAction, elementId) {
618
    _showTab(tabName);
633
  var _showElement = function(tabName, elementId) {
634
    if(!Config.isTabEnabled(tabName)){
635
      return;
636
    }
637

  
638
    if (router != undefined){
639
      router.navigate(tabName + "/" + elementId);
640
    }else{
641
      _routerShowElement(tabName, elementId);
642
    }
643
  }
644

  
645
  var _routerShowElement = function(tabName, elementId) {
646
    var resource = SunstoneCfg["tabs"][tabName].resource;
647

  
648
    if (resource == undefined){
649
      return;
650
    }
651

  
652
    var infoAction = resource + ".show";
653

  
654
    _routerShowTab(tabName);
619 655

  
620 656
    var context = $('#' + tabName);
621 657

  
......
993 1029
  }
994 1030

  
995 1031
  function _popFormPanelLoading(tabId) {
1032
    if (!_formPanelVisible($("#"+tabId)) && router != undefined){
1033
      router.navigate(tabId+"/form");
1034
    }
1035

  
996 1036
    var context = $("#" + tabId);
997 1037
    $(".sunstone-list", context).hide();
998 1038
    $(".sunstone-info", context).hide();
......
1093 1133
    return dialogInstance;
1094 1134
  }
1095 1135

  
1136
  var _setupNavigoRoutes = function() {
1137
    router =  new Navigo(null, true);
1138

  
1139
    for (var tabName in SunstoneCfg["tabs"]) {
1140
      router.on(new RegExp("(?:#|/)"+tabName+"/form"), function(){
1141
      }.bind(tabName));
1142

  
1143
      router.on(new RegExp("(?:#|/)"+tabName+"/(\\d+)"), function(id){
1144
        _routerShowElement(this, id)
1145
      }.bind(tabName));
1146

  
1147
      router.on(new RegExp("(?:#|/)"+tabName), function(){
1148
        _routerShowTab(this);
1149
      }.bind(tabName));
1150
    }
1151

  
1152
    router.on(function(){
1153
      _routerShowTab(DASHBOARD_TAB_ID);
1154
    });
1155

  
1156
    $(document).on("click", "a", function(e){
1157
      if ($(this).attr("href") != undefined &&
1158
          $(this).attr("href").startsWith("#")){
1159
        e.preventDefault();
1160
      }
1161
    });
1162

  
1163
    router.resolve();
1164
  }
1165

  
1096 1166
  var Sunstone = {
1097 1167
    "addMainTabs": _addMainTabs,
1098 1168
    "addDialogs": _addDialogs,
......
1128 1198

  
1129 1199
    "insertButtonsInTab": _insertButtonsInTab,
1130 1200

  
1131
    "TOP_INTERVAL": TOP_INTERVAL
1201
    "TOP_INTERVAL": TOP_INTERVAL,
1202

  
1203
    "setupNavigoRoutes": _setupNavigoRoutes
1132 1204
  }
1133 1205

  
1134 1206
  return Sunstone;
src/sunstone/public/app/tabs/vms-tab/panels/info.js
127 127
    PermissionsTable.setup(TAB_ID, RESOURCE, this.element, context);
128 128

  
129 129
    $("a.vrid", context).on("click", function(){
130
      // TODO: this should be checked internally in showElement,
131
      // but it won't work because of bug #4198
132

  
133
      if (Config.isTabEnabled("vrouters-tab")){
134
        Sunstone.showElement("vrouters-tab", "VirtualRouter.show", $(this).text());
135
      }
130
      Sunstone.showElement("vrouters-tab", $(this).text());
136 131
    });
137 132

  
138 133
    // Get rid of the unwanted (for show) SCHED_* keys
src/sunstone/public/app/tabs/vnets-topology-tab.js
485 485
    _network.on("doubleClick", function(params) {
486 486
      if (params.nodes.length == 1 && _network.isCluster(params.nodes[0]) == false) {
487 487
        if ( params.nodes[0].match(/vm\d+/) ){
488
          // TODO: this should be checked internally in showElement,
489
          // but it won't work because of bug #4198
490

  
491
          if (Config.isTabEnabled("vms-tab")){
492
            Sunstone.showElement("vms-tab", "VM.show", params.nodes[0].split("vm")[1]);
493
          }
488
          Sunstone.showElement("vms-tab", params.nodes[0].split("vm")[1]);
494 489
        } else if ( params.nodes[0].match(/vnet\d+/) ){
495
          // TODO: this should be checked internally in showElement,
496
          // but it won't work because of bug #4198
497

  
498
          if (Config.isTabEnabled("vnets-tab")){
499
            Sunstone.showElement("vnets-tab", "Network.show", params.nodes[0].split("vnet")[1]);
500
          }
490
          Sunstone.showElement("vnets-tab", params.nodes[0].split("vnet")[1]);
501 491
        } else if ( params.nodes[0].match(/vr\d+/) ){
502
          // TODO: this should be checked internally in showElement,
503
          // but it won't work because of bug #4198
504

  
505
          if (Config.isTabEnabled("vrouters-tab")){
506
            Sunstone.showElement("vrouters-tab", "VirtualRouter.show", params.nodes[0].split("vr")[1]);
507
          }
492
          Sunstone.showElement("vrouters-tab", params.nodes[0].split("vr")[1]);
508 493
        }
509 494
      }
510 495
    });
src/sunstone/public/app/utils/tab-datatable.js
402 402
    var id = $(aData[0]).val();
403 403
    if (!id) return true;
404 404

  
405
    Sunstone.showElement(tableObj.tabId, tableObj.resource + ".show", id);
405
    Sunstone.showElement(tableObj.tabId, id);
406 406

  
407 407
    return false;
408 408
  }
src/sunstone/public/bower.json
22 22
    "requirejs": "2.1.22",
23 23
    "foundation-sites": "6.2.1",
24 24
    "jquery": "2.2.3",
25
    "datatables": "1.10.12"
25
    "datatables": "1.10.12",
26
    "navigo": "2.1.1"
26 27
  },
27 28
  "authors": [
28
    "Daniel Molina <dmolina@opennebula.org>"
29
    "Daniel Molina <dmolina@opennebula.org>",
30
    "Carlos Martin <cmartin@opennebula.org>"
29 31
  ],
30 32
  "description": "OpenNebula Sunstone",
31 33
  "moduleType": [
src/sunstone/sunstone-server.rb
479 479
    content_type 'text/html', :charset => 'utf-8'
480 480
    if !authorized?
481 481
        erb :login
482
    else
483
        redirect to('/')
482 484
    end
483 485
end
484 486

  

Also available in: Unified diff