11999a915f45c36dde3c6ecc4e085fc8254bd413
[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 ) {
17
18         var ui = app.ns("ui");
19
20         ui.ResultTable = ui.Table.extend({
21                 defaults: {
22                         width: 500,
23                         height: 400
24                 },
25
26                 init: function() {
27                         this._super();
28                         this.on("rowClick", this._showPreview_handler);
29                         this.selectedRow = null;
30                         $(document).bind("keydown", this._nav_handler);
31                 },
32                 remove: function() {
33                         $(document).unbind("keydown", this._nav_handler);
34                         this._super();
35                 },
36                 attach: function(parent) {
37                         if(parent) {
38                                 var height = parent.height() || ( $(document).height() - parent.offset().top - 41 ); // 41 = height in px of .uiTable-tools + uiTable-header
39                                 var width = parent.width();
40                                 this.el.width( width );
41                                 this.body.width( width ).height( height );
42                         }
43                         this._super(parent);
44                 },
45                 showPreview: function(row) {
46                         row.addClass("selected");
47                         this.preview = new app.ui.JsonPanel({
48                                 title: i18n.text("Browser.ResultSourcePanelTitle"),
49                                 json: row.data("row")._source,
50                                 onClose: function() { row.removeClass("selected"); }
51                         });
52                 },
53                 _nav_handler: function(jEv) {
54                         if(jEv.keyCode !== 40 && jEv.keyCode !== 38) {
55                                 return;
56                         }
57                         this.selectedRow && this.preview && this.preview.remove();
58                         if(jEv.keyCode === 40) { // up arrow
59                                 this.selectedRow = this.selectedRow ? this.selectedRow.next("TR") : this.body.find("TR:first");
60                         } else if(jEv.keyCode === 38) { // down arrow
61                                 this.selectedRow = this.selectedRow ? this.selectedRow.prev("TR") : this.body.find("TR:last");
62                         }
63                         this.selectedRow && this.showPreview(this.selectedRow);
64                 },
65                 _showPreview_handler: function(obj, data) {
66                         this.showPreview(this.selectedRow = data.row);
67                 }
68         });
69
70 })( this.jQuery, this.app );