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 |
if ( tag == 'TH' ) { |
24 |
console.info('header', column); |
25 |
$('form#sql input[name=order_by]').attr('value', where_value + ' desc'); |
26 |
} else if ( tag = 'TD' ) { |
27 |
console.info('column', column, where_operator, where_value); |
28 |
$('form#sql input[name=where_value]').attr('value', where_value); |
29 |
$('form#sql select[name=where_column]').attr('options').selectedIndex = col_nr; |
30 |
$('form#sql input[name=add_group_by]').attr('value', column).css('display','block').attr('disabled',0); |
31 |
} else { |
32 |
console.error('unknown click on ', tag, e); |
33 |
} |
34 |
|
35 |
$('form#sql').addClass('visible'); |
36 |
}; |
37 |
|
38 |
$('table#results').bind('mouseup', click_on_cell); |
39 |
|
40 |
$('#status').bind('click', function() { |
41 |
$('form#sql').toggleClass('visible'); |
42 |
}); |
43 |
|
44 |
$('input[name=add_group_by]').bind('click', function(e) { |
45 |
var l = $('div#lookup'); |
46 |
l.css('display','block'); |
47 |
var column = $('form#sql input[name=add_group_by]').attr('value'); |
48 |
console.debug( this, e, column, l ); |
49 |
|
50 |
$('input[name=add_group_by]').attr('disabled', 1); |
51 |
|
52 |
l.load('?add_group_by='+column); |
53 |
$('input[name=close_group_by]').attr('disabled', 0).bind('click', function() { |
54 |
l.css('display','none'); |
55 |
$('input[name=add_group_by]').attr('disabled', 0); |
56 |
$('input[name=close_group_by]').attr('disabled', 1); |
57 |
console.debug('closed group by lookup', column); |
58 |
}); |
59 |
}); |
60 |
|
61 |
console.info('ready'); |
62 |
}); |
63 |
|