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.
7 /** @suppress {duplicate} */
8 var remoting = remoting || {};
10 remoting.initElementEventHandlers = function() {
11 var goHome = function() {
12 remoting.setMode(remoting.AppMode.HOME);
14 var goEnterAccessCode = function() {
15 // We don't need a token until we authenticate, but asking for one here
16 // handles the token-expired case earlier, avoiding asking the user for
17 // the access code both before and after re-authentication.
18 remoting.identity.getToken().
19 then(function(token) {
20 remoting.setMode(remoting.AppMode.CLIENT_UNCONNECTED);
22 catch(remoting.Error.handler(remoting.showErrorMessage));
24 var goFinishedIT2Me = function() {
25 if (remoting.currentMode == remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME) {
26 remoting.setMode(remoting.AppMode.CLIENT_UNCONNECTED);
31 /** @param {Event} event The event. */
32 var sendAccessCode = function(event) {
33 remoting.connectIT2Me();
34 event.preventDefault();
36 var reconnect = function() {
37 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
38 remoting.app.getSessionConnector().reconnect();
40 /** @param {Event} event The event. */
41 var stopDaemon = function(event) {
42 remoting.hostSetupDialog.showForStop();
43 event.stopPropagation();
45 var cancelAccessCode = function() {
46 remoting.setMode(remoting.AppMode.HOME);
47 document.getElementById('access-code-entry').value = '';
49 /** @type {Array<{event: string, id: string, fn: function(Event):void}>} */
51 { event: 'click', id: 'access-mode-button', fn: goEnterAccessCode },
52 { event: 'submit', id: 'access-code-form', fn: sendAccessCode },
53 { event: 'click', id: 'cancel-access-code-button', fn: cancelAccessCode},
54 { event: 'click', id: 'cancel-share-button', fn: remoting.cancelShare },
55 { event: 'click', id: 'client-finished-it2me-button', fn: goHome },
56 { event: 'click', id: 'get-started-it2me',
57 fn: remoting.showIT2MeUiAndSave },
58 { event: 'click', id: 'host-finished-button', fn: goHome },
59 { event: 'click', id: 'share-button', fn: remoting.tryShare }
61 /** @type {Array<{event: string, id: string, fn: function(Event):void}>} */
63 { event: 'click', id: 'change-daemon-pin',
64 fn: function() { remoting.hostSetupDialog.showForPin(); } },
65 { event: 'click', id: 'client-finished-me2me-button', fn: goHome },
66 { event: 'click', id: 'client-reconnect-button', fn: reconnect },
67 { event: 'click', id: 'daemon-pin-cancel', fn: goHome },
68 { event: 'click', id: 'get-started-me2me',
69 fn: remoting.showMe2MeUiAndSave },
70 { event: 'click', id: 'start-daemon',
71 fn: function() { remoting.hostSetupDialog.showForStart(); } },
72 { event: 'click', id: 'stop-daemon', fn: stopDaemon }
74 /** @type {Array<{event: string, id: string, fn: function(Event):void}>} */
76 { event: 'click', id: 'close-paired-client-manager-dialog', fn: goHome },
77 { event: 'click', id: 'host-config-done-dismiss', fn: goHome },
78 { event: 'click', id: 'host-config-error-dismiss', fn: goHome },
79 { event: 'click', id: 'open-paired-client-manager-dialog',
80 fn: remoting.setMode.bind(null,
81 remoting.AppMode.HOME_MANAGE_PAIRINGS) },
82 { event: 'click', id: 'stop-sharing-button', fn: remoting.cancelShare }
84 /** @type {Array<{event: string, id: string, fn: function(Event):void}>} */
86 { event: 'click', id: 'cancel-connect-button', fn: goHome },
87 { event: 'click', id: 'sign-out', fn:remoting.signOut },
88 { event: 'click', id: 'token-refresh-error-ok', fn: goHome },
89 { event: 'click', id: 'token-refresh-error-sign-in',
90 fn: remoting.handleAuthFailureAndRelaunch }
92 registerEventListeners(it2me_actions);
93 registerEventListeners(me2me_actions);
94 registerEventListeners(host_actions);
95 registerEventListeners(auth_actions);