Chromium Code Reviews| 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.autofillOptions', function() { | 5 cr.define('options.autofillOptions', function() { |
| 6 /** @const */ var DeletableItem = options.DeletableItem; | 6 /** @const */ var DeletableItem = options.DeletableItem; |
| 7 /** @const */ var DeletableItemList = options.DeletableItemList; | 7 /** @const */ var DeletableItemList = options.DeletableItemList; |
| 8 /** @const */ var InlineEditableItem = options.InlineEditableItem; | 8 /** @const */ var InlineEditableItem = options.InlineEditableItem; |
| 9 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; | 9 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; |
| 10 | 10 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 return; | 201 return; |
| 202 } | 202 } |
| 203 | 203 |
| 204 var entries = this.list.dataModel.slice(); | 204 var entries = this.list.dataModel.slice(); |
| 205 if (this.valueIsNonEmpty_(value) && | 205 if (this.valueIsNonEmpty_(value) && |
| 206 !entries.some(this.valuesAreEqual_.bind(this, value))) { | 206 !entries.some(this.valuesAreEqual_.bind(this, value))) { |
| 207 // Update with new value. | 207 // Update with new value. |
| 208 if (this.isPlaceholder) { | 208 if (this.isPlaceholder) { |
| 209 // It is important that updateIndex is done before validateAndSave. | 209 // It is important that updateIndex is done before validateAndSave. |
| 210 // Otherwise we can not be sure about AddRow index. | 210 // Otherwise we can not be sure about AddRow index. |
| 211 this.list.eventsDisabled = true; | |
| 211 this.list.dataModel.updateIndex(i); | 212 this.list.dataModel.updateIndex(i); |
| 213 this.list.eventsDisabled = false; | |
| 212 this.list.validateAndSave(i, 0, value); | 214 this.list.validateAndSave(i, 0, value); |
| 213 } else { | 215 } else { |
| 214 this.list.validateAndSave(i, 1, value); | 216 this.list.validateAndSave(i, 1, value); |
| 215 } | 217 } |
| 216 } else { | 218 } else { |
| 217 // Reject empty values and duplicates. | 219 // Reject empty values and duplicates. |
| 218 if (!this.isPlaceholder) | 220 if (!this.isPlaceholder) { |
| 221 this.list.eventsDisabled = true; | |
| 219 this.list.dataModel.splice(i, 1); | 222 this.list.dataModel.splice(i, 1); |
| 223 this.list.eventsDisabled = false; | |
| 224 this.list.setSelectedIndexWithoutFocusing(i); | |
| 225 } | |
|
Dan Beam
2015/01/21 18:18:07
} else {
bondd
2015/01/22 01:05:22
Done.
| |
| 220 else | 226 else |
| 221 this.clearValue_(); | 227 this.clearValue_(); |
| 222 } | 228 } |
| 223 }, | 229 }, |
| 224 }; | 230 }; |
| 225 | 231 |
| 226 /** | 232 /** |
| 227 * Creates a new name value list item. | 233 * Creates a new name value list item. |
| 228 * @param {options.autofillOptions.AutofillNameValuesList} list The parent | 234 * @param {options.autofillOptions.AutofillNameValuesList} list The parent |
| 229 * list of this item. | 235 * list of this item. |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 }, | 441 }, |
| 436 | 442 |
| 437 /** | 443 /** |
| 438 * Called when a new list item should be validated; subclasses are | 444 * Called when a new list item should be validated; subclasses are |
| 439 * responsible for implementing if validation is required. | 445 * responsible for implementing if validation is required. |
| 440 * @param {number} index The index of the item that was inserted or changed. | 446 * @param {number} index The index of the item that was inserted or changed. |
| 441 * @param {number} remove The number items to remove. | 447 * @param {number} remove The number items to remove. |
| 442 * @param {string} value The value of the item to insert. | 448 * @param {string} value The value of the item to insert. |
| 443 */ | 449 */ |
| 444 validateAndSave: function(index, remove, value) { | 450 validateAndSave: function(index, remove, value) { |
| 451 this.eventsDisabled = true; | |
| 445 this.dataModel.splice(index, remove, value); | 452 this.dataModel.splice(index, remove, value); |
| 453 this.eventsDisabled = false; | |
| 454 this.setSelectedIndexWithoutFocusing(index); | |
| 446 }, | 455 }, |
| 447 }; | 456 }; |
| 448 | 457 |
| 449 /** | 458 /** |
| 450 * Create a new value list for phone number validation. | 459 * Create a new value list for phone number validation. |
| 451 * @constructor | 460 * @constructor |
| 452 * @extends {options.autofillOptions.AutofillValuesList} | 461 * @extends {options.autofillOptions.AutofillValuesList} |
| 453 */ | 462 */ |
| 454 var AutofillNameValuesList = cr.ui.define('list'); | 463 var AutofillNameValuesList = cr.ui.define('list'); |
| 455 | 464 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 * This should be called when a reply of chrome.send('validatePhoneNumbers') | 515 * This should be called when a reply of chrome.send('validatePhoneNumbers') |
| 507 * is received. | 516 * is received. |
| 508 */ | 517 */ |
| 509 didReceiveValidationResult: function() { | 518 didReceiveValidationResult: function() { |
| 510 this.validationRequests_--; | 519 this.validationRequests_--; |
| 511 assert(this.validationRequests_ >= 0); | 520 assert(this.validationRequests_ >= 0); |
| 512 if (this.validationRequests_ <= 0) { | 521 if (this.validationRequests_ <= 0) { |
| 513 while (this.validationPromiseResolvers_.length) { | 522 while (this.validationPromiseResolvers_.length) { |
| 514 this.validationPromiseResolvers_.pop()(); | 523 this.validationPromiseResolvers_.pop()(); |
| 515 } | 524 } |
| 516 // List has been repopulated. Focus the placeholder. | |
| 517 this.focusPlaceholder(); | |
| 518 } | 525 } |
| 519 }, | 526 }, |
| 520 | 527 |
| 521 /** | 528 /** |
| 522 * Returns a Promise which is fulfilled when all of validation requests are | 529 * Returns a Promise which is fulfilled when all of validation requests are |
| 523 * completed. | 530 * completed. |
| 524 * @return {!Promise} A promise. | 531 * @return {!Promise} A promise. |
| 525 */ | 532 */ |
| 526 doneValidating: function() { | 533 doneValidating: function() { |
| 527 if (this.validationRequests_ <= 0) | 534 if (this.validationRequests_ <= 0) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 538 CreditCardListItem: CreditCardListItem, | 545 CreditCardListItem: CreditCardListItem, |
| 539 ValuesListItem: ValuesListItem, | 546 ValuesListItem: ValuesListItem, |
| 540 NameListItem: NameListItem, | 547 NameListItem: NameListItem, |
| 541 AutofillAddressList: AutofillAddressList, | 548 AutofillAddressList: AutofillAddressList, |
| 542 AutofillCreditCardList: AutofillCreditCardList, | 549 AutofillCreditCardList: AutofillCreditCardList, |
| 543 AutofillValuesList: AutofillValuesList, | 550 AutofillValuesList: AutofillValuesList, |
| 544 AutofillNameValuesList: AutofillNameValuesList, | 551 AutofillNameValuesList: AutofillNameValuesList, |
| 545 AutofillPhoneValuesList: AutofillPhoneValuesList, | 552 AutofillPhoneValuesList: AutofillPhoneValuesList, |
| 546 }; | 553 }; |
| 547 }); | 554 }); |
| OLD | NEW |