/**
 * Copyright 2015 Solinea, Inc.
 *
 * Licensed under the Solinea Software License Agreement (goldstone),
 * Version 1.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *     http://www.solinea.com/goldstone/LICENSE.pdf
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var LauncherView = Backbone.View.extend({
    initialize: function(options) {
        this.render();
    },

    render: function() {
        this.$el.html(this.template());
        return this;
    },

    template: _.template('' +
        '<div class="launcher-container"></div>')
});

var GoldstoneRouter = Backbone.Router.extend({
    routes: {
        "discover": "discover",
        "login": "login",
        "password": "password",
        "settings": "settings",
        "settings/tenants": "tenant",
        "api_perf/report": "apiPerfReport",
        "nova/report": "novaReport",
        "neutron/report": "neutronReport",
        "cinder/report": "cinderReport",
        "glance/report": "glanceReport",
        "keystone/report": "keystoneReport",
        "intelligence/search": "logSearch",
        "report/node/:nodeId": "nodeReport",
        "*default": "redirect"
    },
    switchView: function(view) {
        if (this.currentView) {
            this.currentView.remove();
        }
        var launcherView = new LauncherView({});
        this.currentView = launcherView;
        $('.router-content-container').append(launcherView.el);

        new view({el: '.launcher-container'});

    },
    keystoneReport: function() {
        this.switchView(KeystoneReportView);
    },
    login: function() {
        this.switchView(LoginPageView);
    },
    password: function() {
        this.switchView(PasswordResetView);
    },
    settings: function() {
        this.switchView(SettingsPageView);
    },
    tenant: function() {
        this.switchView(TenantSettingsPageView);
    },
    apiPerfReport: function() {
        this.switchView(ApiPerfReportView);
    },
    novaReport: function() {
        this.switchView(NovaReportView);
    },
    neutronReport: function() {
        this.switchView(NeutronReportView);
    },
    cinderReport: function() {
        this.switchView(CinderReportView);
    },
    glanceReport: function() {
        this.switchView(GlanceReportView);
    },
    logSearch: function() {
        this.switchView(LogSearchView);
    },
    nodeReport: function(nodeId) {
        app.nodeReportView = new NodeReportView({
            el: ".router-content-container",
            node_uuid: nodeId
        });
        this.switchView(app.nodeReportView);
    },
    discover: function() {
        this.switchView(DiscoverView);
    },
    redirect: function() {
        location.href = "#/discover";
    }
});

@@ -1545,16 +1545,24 @@
 ion(view
+, nodeId
 ) %7B%0A    
@@ -1569,129 +1569,623 @@
     
-if (this.currentView) %7B%0A            this.currentView.remove();%0A        %7D%0A        var launcherView = new LauncherView(%7B%7D);
+// prevent multiple successive calls to the same page%0A        if (this.switchTriggeredBy && this.switchTriggeredBy === view) %7B%0A            return;%0A        %7D%0A        this.switchTriggeredBy = view;%0A%0A        // Backbone's remove() calls this.$el.remove() and this.stopListening()%0A        if (this.currentView) %7B%0A            console.log('current views children: ', this.currentView);%0A            this.currentView.remove();%0A        %7D%0A%0A        // instantiate wrapper view that can be removed upon page change%0A        var launcherView = new LauncherView(%7B%7D);%0A        // store it as the current view so it can be remove()'d
 %0A   
@@ -2222,16 +2222,53 @@
 erView;%0A
+        // append it to the page div%0A
         
@@ -2327,55 +2327,375 @@
 l);%0A
-%0A        new view(%7Bel: '.launcher-container'%7D);
+        // instantiate the desired page view%0A        // if it's a node report page, add the node_uuid param%0A        if (nodeId !== undefined) %7B%0A            new view(%7B%0A                el: '.launcher-container',%0A                node_uuid: nodeId%0A            %7D);%0A        %7D else %7B%0A            new view(%7B%0A                el: '.launcher-container'%0A            %7D);%0A        %7D
 %0A%0A  
@@ -3610,145 +3610,8 @@
 ) %7B%0A
-        app.nodeReportView = new NodeReportView(%7B%0A            el: %22.router-content-container%22,%0A            node_uuid: nodeId%0A        %7D);%0A
     
@@ -3634,13 +3634,9 @@
 iew(
-app.n
+N
 odeR
@@ -3636,32 +3636,40 @@
 w(NodeReportView
+, nodeId
 );%0A    %7D,%0A    di

Update goldstoneRouter to accomodate passing through the nodeReport node_uuid param.