2 * Copyright 2010-2013 Ben Birch
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 var ui = app.ns("ui");
20 ui.ResultTable = ui.Table.extend({
28 this.on("rowClick", this._showPreview_handler);
29 this.selectedRow = null;
30 $(document).bind("keydown", this._nav_handler);
33 $(document).unbind("keydown", this._nav_handler);
36 attach: function(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 );
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"); }
53 _nav_handler: function(jEv) {
54 if(jEv.keyCode !== 40 && jEv.keyCode !== 38) {
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");
63 this.selectedRow && this.showPreview(this.selectedRow);
65 _showPreview_handler: function(obj, data) {
66 this.showPreview(this.selectedRow = data.row);
70 })( this.jQuery, this.app );