1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5/**
6 * The status view at the top of the page.  It displays what mode net-internals
7 * is in (capturing, viewing only, viewing loaded log), and may have extra
8 * information and actions depending on the mode.
9 */
10var TopBarView = (function() {
11  'use strict';
12
13  // We inherit from View.
14  var superClass = DivView;
15
16  /**
17   * Main entry point. Called once the page has loaded.
18   * @constructor
19   */
20  function TopBarView() {
21    assertFirstConstructorCall(TopBarView);
22
23    superClass.call(this, TopBarView.BOX_ID);
24
25    this.nameToSubView_ = {
26      capture: new CaptureStatusView(),
27      loaded: new LoadedStatusView(),
28      halted: new HaltedStatusView()
29    };
30
31    this.activeSubView_ = null;
32  }
33
34  TopBarView.BOX_ID = 'top-bar-view';
35  TopBarView.TAB_DROPDOWN_MENU_ID = 'top-bar-view-tab-selecter';
36
37  cr.addSingletonGetter(TopBarView);
38
39  TopBarView.prototype = {
40    // Inherit the superclass's methods.
41    __proto__: superClass.prototype,
42
43    switchToSubView: function(name) {
44      var newSubView = this.nameToSubView_[name];
45
46      if (!newSubView)
47        throw Error('Invalid subview name');
48
49      var prevSubView = this.activeSubView_;
50      this.activeSubView_ = newSubView;
51
52      if (prevSubView)
53        prevSubView.show(false);
54      newSubView.show(this.isVisible());
55
56      // Let the subview change the color scheme of the top bar.
57      $(TopBarView.BOX_ID).className = name + '-status-view';
58
59      return newSubView;
60    },
61  };
62
63  return TopBarView;
64})();
65