2 * Copyright 2010-2013 Ben Birch
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this software except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 (function( $, app, i18n ) {
18 var ui = app.ns("ui");
20 ui.IndexSelector = ui.AbstractWidget.extend({
21 init: function(parent) {
23 this.el = $(this._main_template());
24 this.attach( parent );
25 this.cluster = this.config.cluster;
29 this.cluster.get( "_stats", this._update_handler );
32 _update_handler: function(data) {
34 var index_names = Object.keys(data.indices).sort();
35 for(var i=0; i < index_names.length; i++) {
36 name = index_names[i];
37 options.push(this._option_template(name, data.indices[name]));
39 this.el.find(".uiIndexSelector-select").empty().append(this._select_template(options));
40 this._indexChanged_handler();
43 _main_template: function() {
44 return { tag: "DIV", cls: "uiIndexSelector", children: i18n.complex( "IndexSelector.SearchIndexForDocs", { tag: "SPAN", cls: "uiIndexSelector-select" } ) };
47 _indexChanged_handler: function() {
48 this.fire("indexChanged", this.el.find("SELECT").val());
51 _select_template: function(options) {
52 return { tag: "SELECT", children: options, onChange: this._indexChanged_handler };
55 _option_template: function(name, index) {
56 return { tag: "OPTION", value: name, text: i18n.text("IndexSelector.NameWithDocs", name, index.primaries.docs.count ) };
60 })( this.jQuery, this.app, this.i18n );