Home | History | Annotate | Download | only in options
      1 // Copyright (c) 2011 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 cr.define('options', function() {
      6   const OptionsPage = options.OptionsPage;
      7   const ArrayDataModel = cr.ui.ArrayDataModel;
      8 
      9   /**
     10    * Encapsulated handling of search engine management page.
     11    * @constructor
     12    */
     13   function SearchEngineManager() {
     14     this.activeNavTab = null;
     15     OptionsPage.call(this, 'searchEngines',
     16                      templateData.searchEngineManagerPageTabTitle,
     17                      'searchEngineManagerPage');
     18   }
     19 
     20   cr.addSingletonGetter(SearchEngineManager);
     21 
     22   SearchEngineManager.prototype = {
     23     __proto__: OptionsPage.prototype,
     24 
     25     /**
     26      * List for default search engine options
     27      * @type {boolean}
     28      * @private
     29      */
     30     defaultsList_: null,
     31 
     32     /**
     33      * List for other search engine options
     34      * @type {boolean}
     35      * @private
     36      */
     37     othersList_: null,
     38 
     39     /** inheritDoc */
     40     initializePage: function() {
     41       OptionsPage.prototype.initializePage.call(this);
     42 
     43       this.defaultsList_ = $('defaultSearchEngineList');
     44       this.setUpList_(this.defaultsList_);
     45 
     46       this.othersList_ = $('otherSearchEngineList');
     47       this.setUpList_(this.othersList_);
     48     },
     49 
     50     /**
     51      * Sets up the given list as a search engine list
     52      * @param {List} list The list to set up.
     53      * @private
     54      */
     55     setUpList_: function(list) {
     56       options.search_engines.SearchEngineList.decorate(list);
     57       list.autoExpands = true;
     58     },
     59 
     60     /**
     61      * Updates the search engine list with the given entries.
     62      * @private
     63      * @param {Array} defaultEngines List of possible default search engines.
     64      * @param {Array} otherEngines List of other search engines.
     65      */
     66     updateSearchEngineList_: function(defaultEngines, otherEngines) {
     67       this.defaultsList_.dataModel = new ArrayDataModel(defaultEngines);
     68       var othersModel = new ArrayDataModel(otherEngines);
     69       // Add a "new engine" row.
     70       othersModel.push({
     71         'modelIndex': '-1'
     72       });
     73       this.othersList_.dataModel = othersModel;
     74     },
     75   };
     76 
     77   SearchEngineManager.updateSearchEngineList = function(defaultEngines,
     78                                                         otherEngines) {
     79     SearchEngineManager.getInstance().updateSearchEngineList_(defaultEngines,
     80                                                               otherEngines);
     81   };
     82 
     83   SearchEngineManager.validityCheckCallback = function(validity, modelIndex) {
     84     // Forward to both lists; the one without a matching modelIndex will ignore
     85     // it.
     86     SearchEngineManager.getInstance().defaultsList_.validationComplete(
     87         validity, modelIndex);
     88     SearchEngineManager.getInstance().othersList_.validationComplete(
     89         validity, modelIndex);
     90   };
     91 
     92   // Export
     93   return {
     94     SearchEngineManager: SearchEngineManager
     95   };
     96 
     97 });
     98 
     99