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