| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
| 7 var ArrayDataModel = cr.ui.ArrayDataModel; | 7 var ArrayDataModel = cr.ui.ArrayDataModel; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * ManageProfileOverlay class | 10 * ManageProfileOverlay class |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 iconGridSelectedURL_: null, | 34 iconGridSelectedURL_: null, |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * Initialize the page. | 37 * Initialize the page. |
| 38 */ | 38 */ |
| 39 initializePage: function() { | 39 initializePage: function() { |
| 40 // Call base class implementation to start preference initialization. | 40 // Call base class implementation to start preference initialization. |
| 41 OptionsPage.prototype.initializePage.call(this); | 41 OptionsPage.prototype.initializePage.call(this); |
| 42 | 42 |
| 43 var self = this; | 43 var self = this; |
| 44 var iconGrid = $('manage-profile-icon-grid'); | 44 options.ProfilesIconGrid.decorate($('manage-profile-icon-grid')); |
| 45 var createIconGrid = $('create-profile-icon-grid'); | 45 options.ProfilesIconGrid.decorate($('create-profile-icon-grid')); |
| 46 options.ProfilesIconGrid.decorate(iconGrid); | 46 self.registerCommonEventHandlers_('create', |
| 47 options.ProfilesIconGrid.decorate(createIconGrid); | 47 self.submitCreateProfile_.bind(self)); |
| 48 iconGrid.addEventListener('change', function(e) { | 48 self.registerCommonEventHandlers_('manage', |
| 49 self.onIconGridSelectionChanged_('manage'); | 49 self.submitManageChanges_.bind(self)); |
| 50 }); | |
| 51 createIconGrid.addEventListener('change', function(e) { | |
| 52 self.onIconGridSelectionChanged_('create'); | |
| 53 }); | |
| 54 | 50 |
| 55 $('manage-profile-name').oninput = function(event) { | |
| 56 self.onNameChanged_(event, 'manage'); | |
| 57 }; | |
| 58 $('create-profile-name').oninput = function(event) { | |
| 59 self.onNameChanged_(event, 'create'); | |
| 60 }; | |
| 61 if (loadTimeData.getBoolean('managedUsersEnabled')) { | 51 if (loadTimeData.getBoolean('managedUsersEnabled')) { |
| 62 $('create-profile-managed-container').hidden = false; | 52 $('create-profile-managed-container').hidden = false; |
| 63 $('managed-user-settings-button').onclick = function(event) { | 53 $('managed-user-settings-button').onclick = function(event) { |
| 64 OptionsPage.navigateToPage('managedUser'); | 54 OptionsPage.navigateToPage('managedUser'); |
| 65 chrome.send('coreOptionsUserMetricsAction', | 55 chrome.send('coreOptionsUserMetricsAction', |
| 66 ['Options_ManagedUserPassphraseOverlay']); | 56 ['Options_ManagedUserPassphraseOverlay']); |
| 67 }; | 57 }; |
| 68 } | 58 } |
| 69 $('manage-profile-cancel').onclick = | 59 $('manage-profile-cancel').onclick = |
| 70 $('delete-profile-cancel').onclick = | 60 $('delete-profile-cancel').onclick = |
| 71 $('create-profile-cancel').onclick = function(event) { | 61 $('create-profile-cancel').onclick = function(event) { |
| 72 OptionsPage.closeOverlay(); | 62 OptionsPage.closeOverlay(); |
| 73 }; | 63 }; |
| 74 $('manage-profile-ok').onclick = function(event) { | |
| 75 OptionsPage.closeOverlay(); | |
| 76 self.submitManageChanges_(); | |
| 77 }; | |
| 78 $('delete-profile-ok').onclick = function(event) { | 64 $('delete-profile-ok').onclick = function(event) { |
| 79 OptionsPage.closeOverlay(); | 65 OptionsPage.closeOverlay(); |
| 80 chrome.send('deleteProfile', [self.profileInfo_.filePath]); | 66 chrome.send('deleteProfile', [self.profileInfo_.filePath]); |
| 81 }; | 67 }; |
| 82 $('create-profile-ok').onclick = function(event) { | |
| 83 OptionsPage.closeOverlay(); | |
| 84 // Get the user's chosen name and icon, or default if they do not | |
| 85 // wish to customize their profile. | |
| 86 var name = $('create-profile-name').value; | |
| 87 var icon_url = createIconGrid.selectedItem; | |
| 88 var create_shortcut = false; | |
| 89 if ($('create-shortcut')) | |
| 90 create_shortcut = $('create-shortcut').checked; | |
| 91 var is_managed = $('create-profile-managed').checked; | |
| 92 chrome.send('createProfile', | |
| 93 [name, icon_url, create_shortcut, is_managed]); | |
| 94 }; | |
| 95 }, | 68 }, |
| 96 | 69 |
| 97 /** @override */ | 70 /** @override */ |
| 98 didShowPage: function() { | 71 didShowPage: function() { |
| 99 chrome.send('requestDefaultProfileIcons'); | 72 chrome.send('requestDefaultProfileIcons'); |
| 100 | 73 |
| 101 if ($('manage-shortcut')) | 74 if ($('manage-shortcut')) |
| 102 $('manage-shortcut').checked = false; | 75 $('manage-shortcut').checked = false; |
| 103 | 76 |
| 104 // Just ignore the manage profile dialog on Chrome OS, they use /accounts. | 77 // Just ignore the manage profile dialog on Chrome OS, they use /accounts. |
| 105 if (!cr.isChromeOS && window.location.pathname == '/manageProfile') | 78 if (!cr.isChromeOS && window.location.pathname == '/manageProfile') |
| 106 ManageProfileOverlay.getInstance().prepareForManageDialog_(); | 79 ManageProfileOverlay.getInstance().prepareForManageDialog_(); |
| 107 | 80 |
| 108 $('manage-profile-name').focus(); | 81 $('manage-profile-name').focus(); |
| 109 }, | 82 }, |
| 110 | 83 |
| 111 /** | 84 /** |
| 85 * Registers event handlers that are common between create and manage modes. |
| 86 * @param {String} mode A label that specifies the type of dialog |
| 87 * box which is currently being viewed (i.e. 'create' or |
| 88 * 'manage'). |
| 89 * @param {function()} submitFunction The function that should be called |
| 90 * when the user chooses to submit (e.g. by clicking the OK button). |
| 91 * @private |
| 92 */ |
| 93 registerCommonEventHandlers_: function(mode, submitFunction) { |
| 94 var self = this; |
| 95 $(mode + '-profile-icon-grid').addEventListener('change', function(e) { |
| 96 self.onIconGridSelectionChanged_(mode); |
| 97 }); |
| 98 $(mode + '-profile-name').oninput = function(event) { |
| 99 self.onNameChanged_(event, mode); |
| 100 }; |
| 101 $(mode + '-profile-ok').onclick = function(event) { |
| 102 OptionsPage.closeOverlay(); |
| 103 submitFunction(); |
| 104 }; |
| 105 $(mode + '-profile-name').onkeydown = |
| 106 $(mode + '-profile-icon-grid').onkeydown = function(event) { |
| 107 // Submit if the OK button is enabled and we hit enter. |
| 108 if (!$(mode + '-profile-ok').disabled && event.keyCode == 13) { |
| 109 OptionsPage.closeOverlay(); |
| 110 submitFunction(); |
| 111 } |
| 112 }; |
| 113 }, |
| 114 |
| 115 /** |
| 112 * Set the profile info used in the dialog. | 116 * Set the profile info used in the dialog. |
| 113 * @param {Object} profileInfo An object of the form: | 117 * @param {Object} profileInfo An object of the form: |
| 114 * profileInfo = { | 118 * profileInfo = { |
| 115 * name: "Profile Name", | 119 * name: "Profile Name", |
| 116 * iconURL: "chrome://path/to/icon/image", | 120 * iconURL: "chrome://path/to/icon/image", |
| 117 * filePath: "/path/to/profile/data/on/disk" | 121 * filePath: "/path/to/profile/data/on/disk" |
| 118 * isCurrentProfile: false, | 122 * isCurrentProfile: false, |
| 119 * }; | 123 * }; |
| 120 * @param {string} mode A label that specifies the type of dialog | 124 * @param {string} mode A label that specifies the type of dialog |
| 121 * box which is currently being viewed (i.e. 'create' or | 125 * box which is currently being viewed (i.e. 'create' or |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 this.showErrorBubble_('manageProfilesDuplicateNameError', mode); | 237 this.showErrorBubble_('manageProfilesDuplicateNameError', mode); |
| 234 } else { | 238 } else { |
| 235 this.hideErrorBubble_(mode); | 239 this.hideErrorBubble_(mode); |
| 236 | 240 |
| 237 var nameIsValid = $(mode + '-profile-name').validity.valid; | 241 var nameIsValid = $(mode + '-profile-name').validity.valid; |
| 238 $(mode + '-profile-ok').disabled = !nameIsValid; | 242 $(mode + '-profile-ok').disabled = !nameIsValid; |
| 239 } | 243 } |
| 240 }, | 244 }, |
| 241 | 245 |
| 242 /** | 246 /** |
| 243 * Called when the user clicks "OK". Saves the newly changed profile info. | 247 * Called when the user clicks "OK" or hits enter. Saves the newly changed |
| 248 * profile info. |
| 244 * @private | 249 * @private |
| 245 */ | 250 */ |
| 246 submitManageChanges_: function() { | 251 submitManageChanges_: function() { |
| 247 var name = $('manage-profile-name').value; | 252 var name = $('manage-profile-name').value; |
| 248 var iconURL = $('manage-profile-icon-grid').selectedItem; | 253 var iconURL = $('manage-profile-icon-grid').selectedItem; |
| 249 var manage_checkbox = false; | 254 var manage_checkbox = false; |
| 250 if ($('manage-shortcut')) | 255 if ($('manage-shortcut')) |
| 251 manage_checkbox = $('manage-shortcut').checked; | 256 manage_checkbox = $('manage-shortcut').checked; |
| 252 chrome.send('setProfileNameAndIcon', | 257 chrome.send('setProfileNameAndIcon', |
| 253 [this.profileInfo_.filePath, name, iconURL, | 258 [this.profileInfo_.filePath, name, iconURL, |
| 254 manage_checkbox]); | 259 manage_checkbox]); |
| 255 }, | 260 }, |
| 256 | 261 |
| 257 /** | 262 /** |
| 263 * Called when the user clicks "OK" or hits enter. Creates the profile |
| 264 * using the information in the dialog. |
| 265 * @private |
| 266 */ |
| 267 submitCreateProfile_: function() { |
| 268 // Get the user's chosen name and icon, or default if they do not |
| 269 // wish to customize their profile. |
| 270 var name = $('create-profile-name').value; |
| 271 var icon_url = $('create-profile-icon-grid').selectedItem; |
| 272 var create_shortcut = false; |
| 273 if ($('create-shortcut')) |
| 274 create_checkbox = $('create-shortcut').checked; |
| 275 var is_managed = $('create-profile-managed').checked; |
| 276 chrome.send('createProfile', |
| 277 [name, icon_url, create_shortcut, is_managed]); |
| 278 }, |
| 279 |
| 280 /** |
| 258 * Called when the selected icon in the icon grid changes. | 281 * Called when the selected icon in the icon grid changes. |
| 259 * @param {string} mode A label that specifies the type of dialog | 282 * @param {string} mode A label that specifies the type of dialog |
| 260 * box which is currently being viewed (i.e. 'create' or | 283 * box which is currently being viewed (i.e. 'create' or |
| 261 * 'manage'). | 284 * 'manage'). |
| 262 * @private | 285 * @private |
| 263 */ | 286 */ |
| 264 onIconGridSelectionChanged_: function(mode) { | 287 onIconGridSelectionChanged_: function(mode) { |
| 265 var iconURL = $(mode + '-profile-icon-grid').selectedItem; | 288 var iconURL = $(mode + '-profile-icon-grid').selectedItem; |
| 266 if (!iconURL || iconURL == this.iconGridSelectedURL_) | 289 if (!iconURL || iconURL == this.iconGridSelectedURL_) |
| 267 return; | 290 return; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 $('create-profile-ok').disabled = true; | 398 $('create-profile-ok').disabled = true; |
| 376 }, | 399 }, |
| 377 }; | 400 }; |
| 378 | 401 |
| 379 // Export | 402 // Export |
| 380 return { | 403 return { |
| 381 ManageProfileOverlay: ManageProfileOverlay, | 404 ManageProfileOverlay: ManageProfileOverlay, |
| 382 CreateProfileOverlay: CreateProfileOverlay, | 405 CreateProfileOverlay: CreateProfileOverlay, |
| 383 }; | 406 }; |
| 384 }); | 407 }); |
| OLD | NEW |