6c7cf558df38050b5ae990cb24019eac4cab712f
[ccsdk/features.git] /
1 (function( $, app ) {
2
3         var ui = app.ns("ui");
4
5         ui.ResultTable = ui.Table.extend({
6                 defaults: {
7                         width: 500,
8                         height: 400
9                 },
10
11                 init: function() {
12                         this._super();
13                         this.on("rowClick", this._showPreview_handler);
14                         this.selectedRow = null;
15                         $(document).bind("keydown", this._nav_handler);
16                 },
17                 remove: function() {
18                         $(document).unbind("keydown", this._nav_handler);
19                         this._super();
20                 },
21                 attach: function(parent) {
22                         if(parent) {
23                                 var height = parent.height() || ( $(document).height() - parent.offset().top - 41 ); // 41 = height in px of .uiTable-tools + uiTable-header
24                                 var width = parent.width();
25                                 this.el.width( width );
26                                 this.body.width( width ).height( height );
27                         }
28                         this._super(parent);
29                 },
30                 showPreview: function(row) {
31                         row.addClass("selected");
32                         this.preview = new app.ui.JsonPanel({
33                                 title: i18n.text("Browser.ResultSourcePanelTitle"),
34                                 json: row.data("row")._source,
35                                 onClose: function() { row.removeClass("selected"); }
36                         });
37                 },
38                 _nav_handler: function(jEv) {
39                         if(jEv.keyCode !== 40 && jEv.keyCode !== 38) {
40                                 return;
41                         }
42                         this.selectedRow && this.preview && this.preview.remove();
43                         if(jEv.keyCode === 40) { // up arrow
44                                 this.selectedRow = this.selectedRow ? this.selectedRow.next("TR") : this.body.find("TR:first");
45                         } else if(jEv.keyCode === 38) { // down arrow
46                                 this.selectedRow = this.selectedRow ? this.selectedRow.prev("TR") : this.body.find("TR:last");
47                         }
48                         this.selectedRow && this.showPreview(this.selectedRow);
49                 },
50                 _showPreview_handler: function(obj, data) {
51                         this.showPreview(this.selectedRow = data.row);
52                 }
53         });
54
55 })( this.jQuery, this.app );