329aa4d6c04267e8d9fc74dc534adc282682256e
[ccsdk/features.git] /
1 (function( $, app, i18n ){
2
3         var ui = app.ns("ui");
4         var data = app.ns("data");
5
6         ui.Browser = ui.Page.extend({
7                 defaults: {
8                         cluster: null  // (required) instanceof app.services.Cluster
9                 },
10                 init: function() {
11                         this._super();
12                         this.cluster = this.config.cluster;
13                         this.query = new app.data.Query( { cluster: this.cluster } );
14                         this._refreshButton = new ui.Button({
15                                 label: i18n.text("General.RefreshResults"),
16                                 onclick: function( btn ) {
17                                         this.query.query();
18                                 }.bind(this)
19                         });
20                         this.el = $(this._main_template());
21                         new data.MetaDataFactory({
22                                 cluster: this.cluster,
23                                 onReady: function(metadata) {
24                                         this.metadata = metadata;
25                                         this.store = new data.QueryDataSourceInterface( { metadata: metadata, query: this.query } );
26                                         this.queryFilter = new ui.QueryFilter({ metadata: metadata, query: this.query });
27                                         this.queryFilter.attach(this.el.find("> .uiBrowser-filter") );
28                                         this.resultTable = new ui.ResultTable( {
29                                                 onHeaderClick: this._changeSort_handler,
30                                                 store: this.store
31                                         } );
32                                         this.resultTable.attach( this.el.find("> .uiBrowser-table") );
33                                         this.updateResults();
34                                 }.bind(this)
35                         });
36                 },
37                 updateResults: function() {
38                         this.query.query();
39                 },
40                 _changeSort_handler: function(table, wEv) {
41                         this.query.setSort(wEv.column, wEv.dir === "desc");
42                         this.query.setPage(1);
43                         this.query.query();
44                 },
45                 _main_template: function() {
46                         return { tag: "DIV", cls: "uiBrowser", children: [
47                                 new ui.Toolbar({
48                                         label: i18n.text("Browser.Title"),
49                                         left: [ ],
50                                         right: [ this._refreshButton ]
51                                 }),
52                                 { tag: "DIV", cls: "uiBrowser-filter" },
53                                 { tag: "DIV", cls: "uiBrowser-table" }
54                         ] };
55                 }
56         });
57
58 })( this.jQuery, this.app, this.i18n );