Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / resources / options / chromeos / proxy_rules_list.js
blob6660bc10c9dc45e9898d2c8684bfc2ab327d5711
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('options.proxyexceptions', function() {
6 /** @const */ var List = cr.ui.List;
7 /** @const */ var ListItem = cr.ui.ListItem;
8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel;
10 /**
11 * Creates a new exception list.
12 * @param {Object=} opt_propertyBag Optional properties.
13 * @constructor
14 * @extends {cr.ui.List}
16 var ProxyExceptions = cr.ui.define('list');
18 ProxyExceptions.prototype = {
19 __proto__: List.prototype,
21 pref: 'cros.session.proxy.ignorelist',
23 /** @override */
24 decorate: function() {
25 List.prototype.decorate.call(this);
26 this.autoExpands = true;
28 // HACK(arv): http://crbug.com/40902
29 window.addEventListener('resize', this.redraw.bind(this));
31 this.addEventListener('click', this.handleClick_);
33 var self = this;
35 // Listens to pref changes.
36 Preferences.getInstance().addEventListener(this.pref,
37 function(event) {
38 self.load_(event.value.value);
39 });
42 createItem: function(exception) {
43 return new ProxyExceptionsItem(exception);
46 /**
47 * Adds given exception to model and update backend.
48 * @param {Object} exception A exception to be added to exception list.
50 addException: function(exception) {
51 this.dataModel.push(exception);
52 this.updateBackend_();
55 /**
56 * Removes given exception from model and update backend.
58 removeException: function(exception) {
59 var dataModel = this.dataModel;
61 var index = dataModel.indexOf(exception);
62 if (index >= 0) {
63 dataModel.splice(index, 1);
64 this.updateBackend_();
68 /**
69 * Handles the clicks on the list and triggers exception removal if the
70 * click is on the remove exception button.
71 * @private
72 * @param {!Event} e The click event object.
74 handleClick_: function(e) {
75 // Handle left button click
76 if (e.button == 0) {
77 var el = e.target;
78 if (el.className == 'remove-exception-button') {
79 this.removeException(el.parentNode.exception);
84 /**
85 * Loads given exception list.
86 * @param {!Array} exceptions An array of exception object.
88 load_: function(exceptions) {
89 this.dataModel = new ArrayDataModel(exceptions);
92 /**
93 * Updates backend.
95 updateBackend_: function() {
96 Preferences.setListPref(this.pref, this.dataModel.slice(), true);
101 * Creates a new exception list item.
102 * @param {Object} exception The exception account this represents.
103 * @constructor
104 * @extends {cr.ui.ListItem}
106 function ProxyExceptionsItem(exception) {
107 var el = cr.doc.createElement('div');
108 el.exception = exception;
109 ProxyExceptionsItem.decorate(el);
110 return el;
114 * Decorates an element as a exception account item.
115 * @param {!HTMLElement} el The element to decorate.
117 ProxyExceptionsItem.decorate = function(el) {
118 el.__proto__ = ProxyExceptionsItem.prototype;
119 el.decorate();
122 ProxyExceptionsItem.prototype = {
123 __proto__: ListItem.prototype,
125 /** @override */
126 decorate: function() {
127 ListItem.prototype.decorate.call(this);
128 this.className = 'exception-list-item';
130 var labelException = this.ownerDocument.createElement('span');
131 labelException.className = '';
132 labelException.textContent = this.exception;
133 this.appendChild(labelException);
137 return {
138 ProxyExceptions: ProxyExceptions