summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/options/sync_options.js
blob: 59c3781f6b8569c8a1e61d7ae93a95aa9227c659 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2010 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.

cr.define('options', function() {
  const OptionsPage = options.OptionsPage;

  /**
   * Encapsulated handling of the sync options page.
   * @constructor
   */
  function SyncOptions() {
    OptionsPage.call(this, 'sync', templateData.syncPage, 'syncPage');
  }

  cr.addSingletonGetter(SyncOptions);

  SyncOptions.prototype = {
    __proto__: OptionsPage.prototype,

    initializePage: function() {
      OptionsPage.prototype.initializePage.call(this);
      this.registerEventHandlers();
    },

    /**
     * Registers event handler on all the data type checkboxes so that the set
     * of data types to sync get updated as the user checks/unchecks them.
     */
     registerEventHandlers: function() {
      checks = $('syncPage').getElementsByTagName('input');
      for (var i = 0; i < checks.length; i++) {
        checks[i].onclick = function(event) {
          chrome.send('updatePreferredDataTypes');
        };
      }
    }
  };

  /**
   * Toggles the visibility of the data type checkboxes based on whether they
   * are enabled on not.
   * @param {Object} dict A mapping from data type to a boolean indicating
   *     whether it is enabled.
   */
  SyncOptions.setRegisteredDataTypes = function(dict) {
    for (var type in dict) {
      if (type.match(/Registered$/) && !dict[type]) {
        node = $(type.replace(/([a-z]+)Registered$/i, '$1').toLowerCase()
                 + '-check');
        if (node) {
          node.parentNode.style.display = 'none';
        }
      }
    }
  };

  // Export
  return {
    SyncOptions: SyncOptions
  };

});