| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 const OptionsPage = options.OptionsPage; | 6 const OptionsPage = options.OptionsPage; |
| 7 const ArrayDataModel = cr.ui.ArrayDataModel; | 7 const ArrayDataModel = cr.ui.ArrayDataModel; |
| 8 const ListSelectionModel = cr.ui.ListSelectionModel; | 8 const ListSelectionModel = cr.ui.ListSelectionModel; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 list_: null, | 25 list_: null, |
| 26 | 26 |
| 27 initializePage: function() { | 27 initializePage: function() { |
| 28 OptionsPage.prototype.initializePage.call(this); | 28 OptionsPage.prototype.initializePage.call(this); |
| 29 | 29 |
| 30 var list = $('startupPagesFullList'); | 30 var list = $('startupPagesFullList'); |
| 31 options.browser_options.StartupPageList.decorate(list); | 31 options.browser_options.StartupPageList.decorate(list); |
| 32 list.autoExpands = true; | 32 list.autoExpands = true; |
| 33 list.selectionModel = new ListSelectionModel; | 33 list.selectionModel = new ListSelectionModel; |
| 34 | 34 |
| 35 list.selectionModel.addEventListener( | |
| 36 'change', this.updateRemoveButtonState_.bind(this)); | |
| 37 | |
| 38 // Wire up controls. | 35 // Wire up controls. |
| 39 $('startupAddButton').onclick = function(event) { | 36 $('startupAddButton').onclick = function(event) { |
| 40 OptionsPage.showOverlay('addStartupPageOverlay'); | 37 OptionsPage.showOverlay('addStartupPageOverlay'); |
| 41 }; | 38 }; |
| 42 $('startupRemoveButton').onclick = | |
| 43 this.removeSelectedStartupPages_.bind(this); | |
| 44 | 39 |
| 45 // Remove Windows-style accelerators from button labels. | 40 // Remove Windows-style accelerators from button labels. |
| 46 // TODO(stuartmorgan): Remove this once the strings are updated. | 41 // TODO(stuartmorgan): Remove this once the strings are updated. |
| 47 $('startupAddButton').textContent = | 42 $('startupAddButton').textContent = |
| 48 localStrings.getStringWithoutAccelerator('startupAddButton'); | 43 localStrings.getStringWithoutAccelerator('startupAddButton'); |
| 49 $('startupRemoveButton').textContent = | |
| 50 localStrings.getStringWithoutAccelerator('startupRemoveButton'); | |
| 51 }, | 44 }, |
| 52 | 45 |
| 53 /** | 46 /** |
| 54 * Updates the startup pages list with the given entries. | 47 * Updates the startup pages list with the given entries. |
| 55 * @param {Array} pages List of startup pages. | 48 * @param {Array} pages List of startup pages. |
| 56 * @private | 49 * @private |
| 57 */ | 50 */ |
| 58 updateStartupPages_: function(pages) { | 51 updateStartupPages_: function(pages) { |
| 59 $('startupPagesFullList').dataModel = new ArrayDataModel(pages); | 52 $('startupPagesFullList').dataModel = new ArrayDataModel(pages); |
| 60 this.updateRemoveButtonState_(); | |
| 61 }, | 53 }, |
| 62 | 54 |
| 63 /** | 55 /** |
| 64 * Sets the enabled state of the startup page Remove button based on | 56 * Adds the given startup page at the current selection point. |
| 65 * the current selection in the startup pages list. | |
| 66 * @private | 57 * @private |
| 67 */ | 58 */ |
| 68 updateRemoveButtonState_: function() { | 59 addStartupPage_: function(url) { |
| 69 $('startupRemoveButton').disabled = | 60 var firstSelection = |
| 70 $('startupPagesFullList').selectionModel.selectedIndex == -1; | 61 $('startupPagesFullList').selectionModel.selectedIndex; |
| 71 }, | 62 chrome.send('addStartupPage', [url, String(firstSelection)]); |
| 72 | |
| 73 /** | |
| 74 * Removes the selected startup pages. | |
| 75 * @private | |
| 76 */ | |
| 77 removeSelectedStartupPages_: function() { | |
| 78 var selections = | |
| 79 $('startupPagesFullList').selectionModel.selectedIndexes.map(String); | |
| 80 chrome.send('removeStartupPages', selections); | |
| 81 }, | 63 }, |
| 82 }; | 64 }; |
| 83 | 65 |
| 84 StartupPageManager.updateStartupPages = function(pages) { | 66 StartupPageManager.updateStartupPages = function(pages) { |
| 85 StartupPageManager.getInstance().updateStartupPages_(pages); | 67 StartupPageManager.getInstance().updateStartupPages_(pages); |
| 86 }; | 68 }; |
| 87 | 69 |
| 70 StartupPageManager.addStartupPage = function(url) { |
| 71 StartupPageManager.getInstance().addStartupPage_(url); |
| 72 }; |
| 73 |
| 88 // Export | 74 // Export |
| 89 return { | 75 return { |
| 90 StartupPageManager: StartupPageManager | 76 StartupPageManager: StartupPageManager |
| 91 }; | 77 }; |
| 92 | 78 |
| 93 }); | 79 }); |
| 94 | 80 |
| OLD | NEW |