summaryrefslogtreecommitdiffstats
path: root/remoting/webapp/ui_mode.js
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-11 23:25:05 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-11 23:25:05 +0000
commit11cd112650c6c51b270eeae329d63a7cd732e605 (patch)
tree06d1122825e90616c5410157d83750800baf4540 /remoting/webapp/ui_mode.js
parent2c9f0def901b383bb003c4d10c198cabec1277f6 (diff)
downloadchromium_src-11cd112650c6c51b270eeae329d63a7cd732e605.zip
chromium_src-11cd112650c6c51b270eeae329d63a7cd732e605.tar.gz
chromium_src-11cd112650c6c51b270eeae329d63a7cd732e605.tar.bz2
Rename webapp_it2me to remoting_webapp and move it from webapp/me2mom to webapp/
The remoting webapp is not it2me specific anymore. Renaming stuff and moving it to avoid confusion, particularly for the newcomers. Review URL: http://codereview.chromium.org/9148043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@117322 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/webapp/ui_mode.js')
-rw-r--r--remoting/webapp/ui_mode.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/remoting/webapp/ui_mode.js b/remoting/webapp/ui_mode.js
new file mode 100644
index 0000000..da0253c
--- /dev/null
+++ b/remoting/webapp/ui_mode.js
@@ -0,0 +1,85 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview
+ * Functions related to controlling the modal ui state of the app.
+ */
+
+'use strict';
+
+/** @suppress {duplicate} */
+var remoting = remoting || {};
+
+/** @enum {string} */
+remoting.AppMode = {
+ HOME: 'home',
+ UNAUTHENTICATED: 'auth',
+ CLIENT: 'client',
+ CLIENT_UNCONNECTED: 'client.unconnected',
+ CLIENT_PIN_PROMPT: 'client.pin-prompt',
+ CLIENT_CONNECTING: 'client.connecting',
+ CLIENT_CONNECT_FAILED_IT2ME: 'client.connect-failed.it2me',
+ CLIENT_CONNECT_FAILED_ME2ME: 'client.connect-failed.me2me',
+ CLIENT_SESSION_FINISHED_IT2ME: 'client.session-finished.it2me',
+ CLIENT_SESSION_FINISHED_ME2ME: 'client.session-finished.me2me',
+ HOST: 'host',
+ HOST_WAITING_FOR_CODE: 'host.waiting-for-code',
+ HOST_WAITING_FOR_CONNECTION: 'host.waiting-for-connection',
+ HOST_SHARED: 'host.shared',
+ HOST_SHARE_FAILED: 'host.share-failed',
+ HOST_SHARE_FINISHED: 'host.share-finished',
+ IN_SESSION: 'in-session'
+};
+
+/**
+ * @type {remoting.AppMode} The current app mode
+ */
+remoting.currentMode = remoting.AppMode.HOME;
+
+/**
+ * Change the app's modal state to |mode|, which is considered to be a dotted
+ * hierachy of modes. For example, setMode('host.shared') will show any modal
+ * elements with an data-ui-mode attribute of 'host' or 'host.shared' and hide
+ * all others.
+ *
+ * @param {remoting.AppMode} mode The new modal state, expressed as a dotted
+ * hiearchy.
+ */
+remoting.setMode = function(mode) {
+ var modes = mode.split('.');
+ for (var i = 1; i < modes.length; ++i)
+ modes[i] = modes[i - 1] + '.' + modes[i];
+ var elements = document.querySelectorAll('[data-ui-mode]');
+ for (var i = 0; i < elements.length; ++i) {
+ var element = /** @type {Element} */ elements[i];
+ var hidden = true;
+ for (var m = 0; m < modes.length; ++m) {
+ if (hasClass(element.getAttribute('data-ui-mode'), modes[m])) {
+ hidden = false;
+ break;
+ }
+ }
+ element.hidden = hidden;
+ }
+ remoting.debug.log('App mode: ' + mode);
+ remoting.currentMode = mode;
+ if (mode == remoting.AppMode.IN_SESSION) {
+ document.removeEventListener('keydown', remoting.DebugLog.onKeydown, false);
+ } else {
+ document.addEventListener('keydown', remoting.DebugLog.onKeydown, false);
+ }
+ if (mode == remoting.AppMode.HOME) {
+ var display = function() { remoting.hostList.display(); };
+ remoting.hostList.refresh(display);
+ }
+};
+
+/**
+ * Get the major mode that the app is running in.
+ * @return {string} The app's current major mode.
+ */
+remoting.getMajorMode = function() {
+ return remoting.currentMode.split('.')[0];
+};