1 |
|
2 |
$(document).ready( function() { |
3 |
|
4 |
function click_on_cell(e) { |
5 |
|
6 |
var tag = e.originalTarget.tagName; |
7 |
|
8 |
var col_nr = e.originalTarget.cellIndex; |
9 |
|
10 |
var column = $('table#results th:nth-child(' + ( col_nr + 1 ) + ')').text(); |
11 |
var where_operator = '='; |
12 |
var where_value = window.getSelection().getRangeAt(0).cloneContents().textContent; |
13 |
if ( where_value.length == 0 ) |
14 |
where_value = e.originalTarget.textContent; |
15 |
else |
16 |
where_value = '%' + where_value + '%'; |
17 |
|
18 |
console.debug('click on ', this, e, |
19 |
e.originalTarget, |
20 |
column, where_operator, where_value |
21 |
); |
22 |
|
23 |
$('form#sql .changed').removeClass('changed'); |
24 |
|
25 |
if ( tag == 'TH' ) { |
26 |
console.info('header', column); |
27 |
$('form#sql input[name=order_by]') |
28 |
.addClass('changed') |
29 |
.attr('value', where_value + ' desc') |
30 |
; |
31 |
} else if ( tag = 'TD' ) { |
32 |
console.info('column', column, where_operator, where_value); |
33 |
$('form#sql input[name=where_value]') |
34 |
.addClass('changed') |
35 |
.attr('value', where_value) |
36 |
; |
37 |
$('form#sql select[name=where_column]') |
38 |
.addClass('changed') |
39 |
.attr('options').selectedIndex = col_nr |
40 |
; |
41 |
$('form#sql input[name=add_group_by]') |
42 |
.addClass('changed') |
43 |
.attr('value', column) |
44 |
.css('display','block') |
45 |
.attr('disabled',0) |
46 |
; |
47 |
} else { |
48 |
console.error('unknown click on ', tag, e); |
49 |
} |
50 |
|
51 |
$('form#sql').addClass('visible'); |
52 |
}; |
53 |
|
54 |
$('table#results').bind('mouseup', click_on_cell); |
55 |
|
56 |
$('#status').bind('click', function() { |
57 |
$('form#sql').toggleClass('visible'); |
58 |
}); |
59 |
|
60 |
$('input[name=add_group_by]').bind('click', function(e) { |
61 |
var l = $('div#lookup'); |
62 |
l.html('...loading...').css('display','block'); |
63 |
var column = $('form#sql input[name=add_group_by]').attr('value'); |
64 |
console.debug( this, e, column, l ); |
65 |
|
66 |
$('input[name=add_group_by]') |
67 |
.removeClass('changed') |
68 |
.attr('disabled', 1); |
69 |
|
70 |
l.load('?add_group_by='+column).addClass('changed'); |
71 |
$('input[name=close_group_by]') |
72 |
.addClass('changed') |
73 |
.attr('disabled', 0) |
74 |
.bind('click', function() { |
75 |
l.css('display','none') |
76 |
.addClass('changed') |
77 |
.attr('disabled', 0) |
78 |
; |
79 |
$('input[name=close_group_by]') |
80 |
.removeClass('changed') |
81 |
.attr('disabled', 1) |
82 |
; |
83 |
console.debug('closed group by lookup', column); |
84 |
}); |
85 |
}); |
86 |
|
87 |
console.info('ready'); |
88 |
}); |
89 |
|