| 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 created: function() { |
| 52 this.browserProxy_ = settings.SearchEnginesBrowserProxyImpl.getInstance(); |
| 53 }, |
| 54 |
| 55 /** @override */ |
| 56 ready: function() { |
| 57 if (this.model) { |
| 58 // TODO(dpapad): Localize strings. |
| 59 this.dialogTitle_ = 'Edit search engine'; |
| 60 this.actionButtonText_ = 'Edit'; |
| 61 |
| 62 // If editing an existing search engine, pre-populate the input fields. |
| 63 this.searchEngine_ = this.model.displayName; |
| 64 this.keyword_ = this.model.keyword; |
| 65 this.queryUrl_ = this.model.url; |
| 66 } else { |
| 67 // TODO(dpapad): Localize string. |
| 68 this.dialogTitle_ = 'Add search engine'; |
| 69 this.actionButtonText_ = loadTimeData.getString('searchEnginesAdd'); |
| 70 } |
| 71 }, |
| 72 |
| 73 /** @override */ |
| 74 attached: function() { |
| 75 this.updateActionButtonState_(); |
| 76 this.browserProxy_.searchEngineEditStarted( |
| 77 this.model ? this.model.modelIndex : this.DEFAULT_MODEL_INDEX); |
| 78 this.$.dialog.open(); |
| 79 }, |
| 80 |
| 81 /** @private */ |
| 82 cancel_: function() { |
| 83 this.browserProxy_.searchEngineEditCancelled(); |
| 84 this.$.dialog.close(); |
| 85 }, |
| 86 |
| 87 /** @private */ |
| 88 onActionButtonTap_: function() { |
| 89 this.browserProxy_.searchEngineEditCompleted( |
| 90 this.searchEngine_, this.keyword_, this.queryUrl_); |
| 91 this.$.dialog.close(); |
| 92 }, |
| 93 |
| 94 /** |
| 95 * @param {!Event} event |
| 96 * @private |
| 97 */ |
| 98 validate_: function(event) { |
| 99 var inputElement = Polymer.dom(event).localTarget; |
| 100 |
| 101 this.browserProxy_.validateSearchEngineInput( |
| 102 inputElement.id, inputElement.value).then(function(isValid) { |
| 103 inputElement.invalid = !isValid; |
| 104 this.updateActionButtonState_(); |
| 105 }.bind(this)); |
| 106 }, |
| 107 |
| 108 /** @private */ |
| 109 updateActionButtonState_: function() { |
| 110 var allValid = [ |
| 111 this.$.searchEngine, this.$.keyword, this.$.queryUrl |
| 112 ].every(function(inputElement) { |
| 113 return !inputElement.invalid && inputElement.value.length != 0; |
| 114 }); |
| 115 this.$.actionButton.disabled = !allValid; |
| 116 }, |
| 117 }); |
| OLD | NEW |