b288f976ab34817cf1083186570323cf9863c433
[ccsdk/features.git] /
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         var data = app.ns("data");
20
21         ui.Browser = ui.Page.extend({
22                 defaults: {
23                         cluster: null  // (required) instanceof app.services.Cluster
24                 },
25                 init: function() {
26                         this._super();
27                         this.cluster = this.config.cluster;
28                         this.query = new app.data.Query( { cluster: this.cluster } );
29                         this._refreshButton = new ui.Button({
30                                 label: i18n.text("General.RefreshResults"),
31                                 onclick: function( btn ) {
32                                         this.query.query();
33                                 }.bind(this)
34                         });
35                         this.el = $(this._main_template());
36                         new data.MetaDataFactory({
37                                 cluster: this.cluster,
38                                 onReady: function(metadata) {
39                                         this.metadata = metadata;
40                                         this.store = new data.QueryDataSourceInterface( { metadata: metadata, query: this.query } );
41                                         this.queryFilter = new ui.QueryFilter({ metadata: metadata, query: this.query });
42                                         this.queryFilter.attach(this.el.find("> .uiBrowser-filter") );
43                                         this.resultTable = new ui.ResultTable( {
44                                                 onHeaderClick: this._changeSort_handler,
45                                                 store: this.store
46                                         } );
47                                         this.resultTable.attach( this.el.find("> .uiBrowser-table") );
48                                         this.updateResults();
49                                 }.bind(this)
50                         });
51                 },
52                 updateResults: function() {
53                         this.query.query();
54                 },
55                 _changeSort_handler: function(table, wEv) {
56                         this.query.setSort(wEv.column, wEv.dir === "desc");
57                         this.query.setPage(1);
58                         this.query.query();
59                 },
60                 _main_template: function() {
61                         return { tag: "DIV", cls: "uiBrowser", children: [
62                                 new ui.Toolbar({
63                                         label: i18n.text("Browser.Title"),
64                                         left: [ ],
65                                         right: [ this._refreshButton ]
66                                 }),
67                                 { tag: "DIV", cls: "uiBrowser-filter" },
68                                 { tag: "DIV", cls: "uiBrowser-table" }
69                         ] };
70                 }
71         });
72
73 })( this.jQuery, this.app, this.i18n );