• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2011 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
5cr.define('mobile', function() {
6
7  function ChooseNetwork() {
8  }
9
10  cr.addSingletonGetter(ChooseNetwork);
11
12  ChooseNetwork.prototype = {
13    networks_: [],
14    showNetworks_: function(networks) {
15      this.networks_ = networks;
16
17      if (networks.length == 0) {
18        $('scanning').hidden = true;
19        $('no-mobile-networks').hidden = false;
20        return;
21      }
22
23      var container = $('choosing');
24      container.innerHTML = '';
25      for (var i in networks) {
26        var elem = document.createElement('div');
27        elem.innerHTML =
28            '<input type="radio" name="network" id="network' + i + '" />' +
29            '<label for="network' + i + '" id="label' + i + '"></label>';
30        container.appendChild(elem);
31        $('label' + i).textContent = networks[i].operatorName;
32        if (networks[i].status == 'current') {
33          $('network' + i).checked = true;
34          $('connect').disabled = false;
35        } else if (networks[i].status == 'forbidden') {
36          $('network' + i).disabled = true;
37          elem.className = 'disabled';
38        } else {
39          $('network' + i).addEventListener('click', function(event) {
40            $('connect').disabled = false;
41          });
42        }
43      }
44      $('scanning').hidden = true;
45      $('choosing').hidden = false;
46    },
47    connect_: function() {
48      for (var i in this.networks_) {
49        if ($('network' + i).checked) {
50          chrome.send('connect', [ this.networks_[i].networkId ]);
51          ChooseNetwork.close();
52          return;
53        }
54      }
55    }
56  };
57
58  ChooseNetwork.cancel = function() {
59    chrome.send('cancel');
60    ChooseNetwork.close();
61  };
62
63  ChooseNetwork.close = function() {
64    window.close();
65  };
66
67  ChooseNetwork.connect = function() {
68    ChooseNetwork.getInstance().connect_();
69  };
70
71  ChooseNetwork.initialize = function() {
72    $('cancel').addEventListener('click', function(event) {
73      ChooseNetwork.cancel();
74    });
75
76    $('connect').disabled = true;
77    $('connect').addEventListener('click', function(event) {
78      ChooseNetwork.connect();
79    });
80  };
81
82  ChooseNetwork.showNetworks = function(networks) {
83    ChooseNetwork.getInstance().showNetworks_(networks);
84  };
85
86  // Export
87  return {
88    ChooseNetwork: ChooseNetwork
89  };
90});
91