YANG Model update for A1 Adapter
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / resources / elasticsearch / plugins / head / src / app / ui / indexSelector / indexSelector.js
1 /**
2  * Copyright 2010-2013 Ben Birch
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 (function( $, app, i18n ) {
17
18         var ui = app.ns("ui");
19
20         ui.IndexSelector = ui.AbstractWidget.extend({
21                 init: function(parent) {
22                         this._super();
23                         this.el = $(this._main_template());
24                         this.attach( parent );
25                         this.cluster = this.config.cluster;
26                         this.update();
27                 },
28                 update: function() {
29                         this.cluster.get( "_stats", this._update_handler );
30                 },
31                 
32                 _update_handler: function(data) {
33                         var options = [];
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])); 
38                         }
39                         this.el.find(".uiIndexSelector-select").empty().append(this._select_template(options));
40                         this._indexChanged_handler();
41                 },
42                 
43                 _main_template: function() {
44                         return { tag: "DIV", cls: "uiIndexSelector", children: i18n.complex( "IndexSelector.SearchIndexForDocs", { tag: "SPAN", cls: "uiIndexSelector-select" } ) };
45                 },
46
47                 _indexChanged_handler: function() {
48                         this.fire("indexChanged", this.el.find("SELECT").val());
49                 },
50
51                 _select_template: function(options) {
52                         return { tag: "SELECT", children: options, onChange: this._indexChanged_handler };
53                 },
54                 
55                 _option_template: function(name, index) {
56                         return  { tag: "OPTION", value: name, text: i18n.text("IndexSelector.NameWithDocs", name, index.primaries.docs.count ) };
57                 }
58         });
59
60 })( this.jQuery, this.app, this.i18n );