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() {
10 cr.addSingletonGetter(ChooseNetwork);
12 ChooseNetwork.prototype = {
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;
24 var container = $('choosing');
25 container.innerHTML = '';
26 for (var i in networks) {
27 var elem = document.createElement('div');
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';
40 $('network' + i).addEventListener('click', function(event) {
41 $('connect').disabled = false;
45 $('scanning').hidden = true;
46 $('choosing').hidden = false;
47 $('no-mobile-networks').hidden = true;
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();
58 showScanning_: function() {
59 $('scanning').hidden = false;
60 $('choose').hidden = true;
61 $('no-mobile-networks').hidden = true;
65 ChooseNetwork.cancel = function() {
66 chrome.send('cancel');
67 ChooseNetwork.close();
70 ChooseNetwork.close = function() {
74 ChooseNetwork.connect = function() {
75 ChooseNetwork.getInstance().connect_();
78 ChooseNetwork.showScanning = function() {
79 ChooseNetwork.getInstance().showScanning_();
82 ChooseNetwork.initialize = function() {
83 $('cancel').addEventListener('click', function(event) {
84 ChooseNetwork.cancel();
87 $('connect').disabled = true;
88 $('connect').addEventListener('click', function(event) {
89 ChooseNetwork.connect();
91 chrome.send('pageReady');
94 ChooseNetwork.showNetworks = function(networks) {
95 ChooseNetwork.getInstance().showNetworks_(networks);
100 ChooseNetwork: ChooseNetwork
104 var ChooseNetwork = mobile.ChooseNetwork;
106 document.addEventListener('DOMContentLoaded', function() {
107 // TODO(dpolukhin): refactor spinner code&css to be reusable.
108 // Setup css canvas 'spinner-circle'
112 var ctx = document.getCSSCanvasContext(
113 '2d', 'spinner-circle', 2 * r, 2 * r);
115 ctx.lineWidth = lineWidth;
116 ctx.lineCap = 'round';
117 ctx.lineJoin = 'round';
119 ctx.strokeStyle = '#4e73c7';
121 ctx.moveTo(lineWidth / 2, r - lineWidth / 2);
122 ctx.arc(r, r, r - lineWidth / 2, Math.PI, Math.PI * 3 / 2);
126 ChooseNetwork.initialize();
129 disableTextSelectAndDrag();