Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview 'settings-search-engine-dialog' is a component for adding | |
| 7 * or editing a search engine entry. | |
| 8 * | |
| 9 * @group Chrome Settings Elements | |
| 10 * @element settings-search-engine-dialog | |
| 11 */ | |
| 12 Polymer({ | |
| 13 is: 'settings-search-engine-dialog', | |
| 14 | |
| 15 properties: { | |
| 16 /** | |
| 17 * The search engine to be edited. If not populated a new search engine | |
| 18 * should be added. | |
| 19 * @type {?SearchEngine} | |
| 20 */ | |
| 21 model: Object, | |
| 22 | |
| 23 /** @private {string} */ | |
| 24 searchEngine_: String, | |
| 25 | |
| 26 /** @private {string} */ | |
| 27 keyword_: String, | |
| 28 | |
| 29 /** @private {string} */ | |
| 30 queryUrl_: String, | |
| 31 | |
| 32 /** @private {string} */ | |
| 33 dialogTitle_: String, | |
| 34 | |
| 35 /** @private {string} */ | |
| 36 actionButtonText_: String, | |
| 37 }, | |
| 38 | |
| 39 /** @private {!settings.SearchEnginesBrowserProxy} */ | |
| 40 browserProxy_: null, | |
| 41 | |
| 42 /** | |
| 43 * The |modelIndex| to use when a new search engine is added. Must match with | |
| 44 * kNewSearchEngineIndex constant specified at | |
| 45 * chrome/browser/ui/webui/settings/search_engines_handler.cc | |
| 46 * @const {number} | |
| 47 */ | |
| 48 DEFAULT_MODEL_INDEX: -1, | |
| 49 | |
| 50 /** @override */ | |
| 51 ready: function() { | |
| 52 if (this.model) { | |
| 53 // TODO(dpapad): Localize strings. | |
| 54 this.dialogTitle_ = 'Edit search engine'; | |
| 55 this.actionButtonText_ = 'Edit'; | |
| 56 | |
| 57 // If editing an existing search engine, pre-populate the input fields. | |
| 58 this.searchEngine_ = this.model.displayName; | |
| 59 this.keyword_ = this.model.keyword; | |
| 60 this.queryUrl_ = this.model.url; | |
| 61 } else { | |
| 62 // TODO(dpapad): Localize string. | |
| 63 this.dialogTitle_ = 'Add search engine'; | |
| 64 this.actionButtonText_ = loadTimeData.getString('searchEnginesAdd'); | |
| 65 } | |
| 66 }, | |
| 67 | |
| 68 /** @override */ | |
| 69 attached: function() { | |
| 70 this.browserProxy_ = settings.SearchEnginesBrowserProxy.getInstance(); | |
| 71 this.updateActionButtonState_(); | |
| 72 this.browserProxy_.searchEngineEditStarted( | |
| 73 this.model ? this.model.modelIndex : this.DEFAULT_MODEL_INDEX); | |
| 74 this.$.dialog.open(); | |
| 75 }, | |
| 76 | |
| 77 /** @private */ | |
| 78 onCancelTap_: function() { | |
| 79 this.browserProxy_.searchEngineEditCancelled(); | |
| 80 this.$.dialog.close(); | |
| 81 }, | |
| 82 | |
| 83 /** @private */ | |
| 84 onActionButtonTap_: function() { | |
| 85 this.browserProxy_.searchEngineEditCompleted( | |
| 86 this.searchEngine_, this.keyword_, this.queryUrl_); | |
| 87 this.$.dialog.close(); | |
| 88 }, | |
| 89 | |
| 90 /** | |
| 91 * @param {!Event} event | |
| 92 * @private | |
| 93 */ | |
| 94 validate_: function(event) { | |
| 95 var inputElement = Polymer.dom(event).localTarget; | |
| 96 | |
| 97 this.browserProxy_.validateSearchEngineInput( | |
| 98 inputElement.id, inputElement.value).then(function(isValid) { | |
| 99 if (isValid) | |
| 100 inputElement.removeAttribute('invalid'); | |
| 101 else | |
| 102 inputElement.setAttribute('invalid', true); | |
|
Dan Beam
2016/02/17 02:21:35
inputElement.valid = isValid;
dpapad
2016/02/17 03:22:36
If you are suggesting to replace both setAttribute
| |
| 103 this.updateActionButtonState_(); | |
| 104 }.bind(this)); | |
| 105 }, | |
| 106 | |
| 107 /** @private */ | |
| 108 updateActionButtonState_: function() { | |
| 109 var allValid = [ | |
| 110 this.$.searchEngine, this.$.keyword, this.$.queryUrl | |
| 111 ].every(function(inputElement) { | |
| 112 return !inputElement.invalid && inputElement.value.length != 0; | |
| 113 }); | |
| 114 this.$.actionButton.disabled = !allValid; | |
| 115 }, | |
| 116 }); | |
| OLD | NEW |