1 |
|
2 |
// 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 |
$(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 |
var type = column_type[col_nr]; |
28 |
|
29 |
console.debug('click on ', this, e, |
30 |
e.originalTarget, |
31 |
column, type, where_operator, where_value |
32 |
); |
33 |
|
34 |
$('form#sql .changed').removeClass('changed'); |
35 |
|
36 |
if ( tag == 'TH' ) { |
37 |
console.info('header', column); |
38 |
$('form#sql input[name=order_by]') |
39 |
.addClass('changed') |
40 |
.attr('value', where_value + ' desc') |
41 |
; |
42 |
} else if ( tag = 'TD' ) { |
43 |
console.info('column', column, where_operator, where_value); |
44 |
$('form#sql input[name=where_value]') |
45 |
.addClass('changed') |
46 |
.attr('value', where_value) |
47 |
; |
48 |
$('form#sql select[name=where_column]') |
49 |
.addClass('changed') |
50 |
.attr('options').selectedIndex = col_nr |
51 |
; |
52 |
$('form#sql input[name=add_group_by]') |
53 |
.addClass('changed') |
54 |
.attr('value', column) |
55 |
.css('display','block') |
56 |
.attr('disabled',0) |
57 |
; |
58 |
$('select[name=where_operator]') |
59 |
.addClass('changed') |
60 |
.attr('selectedIndex', type < 0 ? 0 : 2) |
61 |
; |
62 |
} else { |
63 |
console.error('unknown click on ', tag, e); |
64 |
} |
65 |
|
66 |
$('form#sql').addClass('visible'); |
67 |
}; |
68 |
|
69 |
$('table#results').bind('mouseup', click_on_cell); |
70 |
|
71 |
$('#status').bind('click', function() { |
72 |
$('form#sql').toggleClass('visible'); |
73 |
}); |
74 |
|
75 |
$('input[name=add_group_by]').bind('click', function(e) { |
76 |
var l = $('div#lookup'); |
77 |
l.html('...loading...').css('display','block'); |
78 |
var column = $('form#sql input[name=add_group_by]').attr('value'); |
79 |
console.debug( this, e, column, l ); |
80 |
|
81 |
$('input[name=add_group_by]') |
82 |
.removeClass('changed') |
83 |
.attr('disabled', 1); |
84 |
|
85 |
l.load('?add_group_by='+column).addClass('changed'); |
86 |
$('input[name=close_group_by]') |
87 |
.addClass('changed') |
88 |
.attr('disabled', 0) |
89 |
.bind('click', function() { |
90 |
l.css('display','none') |
91 |
.addClass('changed') |
92 |
.attr('disabled', 0) |
93 |
; |
94 |
$('input[name=close_group_by]') |
95 |
.removeClass('changed') |
96 |
.attr('disabled', 1) |
97 |
; |
98 |
console.debug('closed group by lookup', column); |
99 |
}); |
100 |
}); |
101 |
|
102 |
console.info('ready'); |
103 |
}); |
104 |
|