Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / choose_mobile_network.js
blob7181c07a6f46c103cd1d9777f2aa17391175e32b
1 // Copyright (c) 2012 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.
5 cr.define('mobile', function() {
7   function ChooseNetwork() {
8   }
10   cr.addSingletonGetter(ChooseNetwork);
12   ChooseNetwork.prototype = {
13     networks_: [],
14     showNetworks_: function(networks) {
15       this.networks_ = networks;
17       if (networks.length == 0) {
18         $('scanning').hidden = true;
19         $('choosing').hidden = true;
20         $('no-mobile-networks').hidden = false;
21         return;
22       }
24       var container = $('choosing');
25       container.innerHTML = '';
26       for (var i in networks) {
27         var elem = document.createElement('div');
28         elem.innerHTML =
29             '<input type="radio" name="network" id="network' + i + '" />' +
30             '<label for="network' + i + '" id="label' + i + '"></label>';
31         container.appendChild(elem);
32         $('label' + i).textContent = networks[i].operatorName;
33         if (networks[i].status == 'current') {
34           $('network' + i).checked = true;
35           $('connect').disabled = false;
36         } else if (networks[i].status == 'forbidden') {
37           $('network' + i).disabled = true;
38           elem.className = 'disabled';
39         } else {
40           $('network' + i).addEventListener('click', function(event) {
41             $('connect').disabled = false;
42           });
43         }
44       }
45       $('scanning').hidden = true;
46       $('choosing').hidden = false;
47       $('no-mobile-networks').hidden = true;
48     },
49     connect_: function() {
50       for (var i in this.networks_) {
51         if ($('network' + i).checked) {
52           chrome.send('connect', [this.networks_[i].networkId]);
53           ChooseNetwork.close();
54           return;
55         }
56       }
57     },
58     showScanning_: function() {
59       $('scanning').hidden = false;
60       $('choose').hidden = true;
61       $('no-mobile-networks').hidden = true;
62     }
63   };
65   ChooseNetwork.cancel = function() {
66     chrome.send('cancel');
67     ChooseNetwork.close();
68   };
70   ChooseNetwork.close = function() {
71     window.close();
72   };
74   ChooseNetwork.connect = function() {
75     ChooseNetwork.getInstance().connect_();
76   };
78   ChooseNetwork.showScanning = function() {
79     ChooseNetwork.getInstance().showScanning_();
80   };
82   ChooseNetwork.initialize = function() {
83     $('cancel').addEventListener('click', function(event) {
84       ChooseNetwork.cancel();
85     });
87     $('connect').disabled = true;
88     $('connect').addEventListener('click', function(event) {
89       ChooseNetwork.connect();
90     });
91     chrome.send('pageReady');
92   };
94   ChooseNetwork.showNetworks = function(networks) {
95     ChooseNetwork.getInstance().showNetworks_(networks);
96   };
98   // Export
99   return {
100     ChooseNetwork: ChooseNetwork
101   };
104 var ChooseNetwork = mobile.ChooseNetwork;
106 document.addEventListener('DOMContentLoaded', ChooseNetwork.initialize);
108 disableTextSelectAndDrag();