rootUi.js revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
1// Copyright 2014 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 5rootUi = new (function() { 6 7this.onDomReady_ = function() { 8 $('#js_loading_banner').hide(); 9 $('#tabs').tabs({activate: this.onTabChange_.bind(this)}); 10 $('#tabs').css('visibility', 'visible'); 11 webservice.onServerUnreachableOrTimeout = 12 this.onServerUnreachableOrTimeout.bind(this); 13 14 // Initialize the status bar. 15 $('#status_messages').mouseenter(function() { 16 $('#status_bar').addClass('expanded'); 17 $('#status_messages').scrollTop($('#status_messages').height()); 18 }); 19 $('#status_messages').mouseleave(function() { 20 $('#status_bar').removeClass('expanded'); 21 }); 22 $('#progress_bar').progressbar({value: 1}); 23}; 24 25this.showTab = function(tabId) { 26 var index = $('#tabs-' + tabId).index(); 27 if (index > 0) 28 $('#tabs').tabs('option', 'active', index - 1); 29}; 30 31this.onTabChange_ = function(_, ui) { 32 switch(ui.newPanel.attr('id').replace('tabs-', '')) { 33 case 'ps': 34 return processes.redraw(); 35 case 'prof': 36 return profiler.redraw(); 37 case 'mm': 38 return mmap.redraw(); 39 case 'nheap': 40 return nheap.redraw(); 41 case 'settings': 42 return settings.reload(); 43 case 'storage': 44 return storage.reload(); 45 } 46}; 47 48this.showDialog = function(content, title) { 49 var dialog = $('#message_dialog'); 50 title = title || ''; 51 if (dialog.length == 0) { 52 dialog = $('<div id="message_dialog"/>'); 53 $('body').append(dialog); 54 } 55 if (typeof(content) == 'string') 56 dialog.empty().text(content); 57 else 58 dialog.empty().append(content); // Assume is a jQuery DOM object. 59 60 dialog.dialog({modal: true, title: title, height:'auto', width:'auto'}); 61}; 62 63this.hideDialog = function() { 64 $('#message_dialog').dialog('close'); 65}; 66 67this.setProgress = function(value) { 68 $('#progress_bar').progressbar('option', 'value', value); 69 $('#progress_bar-label').text(value + '%' ); 70}; 71 72this.setStatusMessage = function(content) { 73 $('#status_messages').text(content); 74}; 75 76this.onServerUnreachableOrTimeout = function() { 77 timers.stopAll(); 78 this.showDialog('The www service is unreachable. ' + 79 'It probably crashed, Check the terminal output.'); 80}; 81 82$(document).ready(this.onDomReady_.bind(this)); 83 84})();