7f51d5f7423f6b2a9d6395480c673c383df268d4
[ccsdk/features.git] /
1 (function( $, app, i18n ) {
2
3         var ui = app.ns("ui");
4
5         ui.IndexSelector = ui.AbstractWidget.extend({
6                 init: function(parent) {
7                         this._super();
8                         this.el = $(this._main_template());
9                         this.attach( parent );
10                         this.cluster = this.config.cluster;
11                         this.update();
12                 },
13                 update: function() {
14                         this.cluster.get( "_stats", this._update_handler );
15                 },
16                 
17                 _update_handler: function(data) {
18                         var options = [];
19                         var index_names = Object.keys(data.indices).sort();
20                         for(var i=0; i < index_names.length; i++) { 
21                                 name = index_names[i];
22                                 options.push(this._option_template(name, data.indices[name])); 
23                         }
24                         this.el.find(".uiIndexSelector-select").empty().append(this._select_template(options));
25                         this._indexChanged_handler();
26                 },
27                 
28                 _main_template: function() {
29                         return { tag: "DIV", cls: "uiIndexSelector", children: i18n.complex( "IndexSelector.SearchIndexForDocs", { tag: "SPAN", cls: "uiIndexSelector-select" } ) };
30                 },
31
32                 _indexChanged_handler: function() {
33                         this.fire("indexChanged", this.el.find("SELECT").val());
34                 },
35
36                 _select_template: function(options) {
37                         return { tag: "SELECT", children: options, onChange: this._indexChanged_handler };
38                 },
39                 
40                 _option_template: function(name, index) {
41                         return  { tag: "OPTION", value: name, text: i18n.text("IndexSelector.NameWithDocs", name, index.primaries.docs.count ) };
42                 }
43         });
44
45 })( this.jQuery, this.app, this.i18n );