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=lookup_col]') |
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').addClass('fixed'); |
67 |
}; |
68 |
|
69 |
$('table#results').bind('mouseup', click_on_cell); |
70 |
|
71 |
$('#status').bind('click', function() { |
72 |
$('form#sql').toggleClass('visible').addClass('fixed'); |
73 |
}); |
74 |
|
75 |
$('input[name=lookup_col]').bind('click', function(e) { |
76 |
var l = $('div#lookup'); |
77 |
var column = $('form#sql input[name=lookup_col]').attr('value'); |
78 |
var col_nr = $('form#sql select[name=where_column]').attr('options').selectedIndex; |
79 |
var operator = $('select[name=where_operator]').attr('options').selectedIndex; |
80 |
|
81 |
l.html('...loading lookup for '+column+'...').css('display','block').scrollTop(0); |
82 |
|
83 |
console.debug( this, e, column, col_nr, l ); |
84 |
|
85 |
$('input[name=lookup_col]') |
86 |
.removeClass('changed') |
87 |
.attr('disabled', 1); |
88 |
|
89 |
var where_parts = []; |
90 |
$('input[name=where_parts]').each(function(){ if (this.checked) where_parts.push(this.value) }); |
91 |
var args = { |
92 |
lookup_col: column, |
93 |
where_parts: where_parts, |
94 |
}; |
95 |
console.debug( 'get', args ); |
96 |
$.get('', args, function(data,textStatus) { |
97 |
console.debug( data, textStatus ); |
98 |
l.addClass('changed'); |
99 |
l.html( data ); |
100 |
|
101 |
$('div#lookup a') |
102 |
.bind('click', function(e) { |
103 |
console.debug( 'lookup click', e ); |
104 |
$('form#sql input[name=where_value]') |
105 |
.attr('value', e.target.text ) |
106 |
; |
107 |
$('form#sql select[name=where_column]') |
108 |
.attr('options').selectedIndex = col_nr |
109 |
; |
110 |
$('select[name=where_operator]') |
111 |
.attr('options').selectedIndex = operator + 1 // remove not |
112 |
; |
113 |
return false; |
114 |
}); |
115 |
}); |
116 |
|
117 |
|
118 |
$('input[name=close_group_by]') |
119 |
.addClass('changed') |
120 |
.attr('disabled', 0) |
121 |
.bind('click', function() { |
122 |
l.css('display','none') |
123 |
.addClass('changed') |
124 |
.attr('disabled', 0) |
125 |
; |
126 |
$('input[name=close_group_by]') |
127 |
.removeClass('changed') |
128 |
.attr('disabled', 1) |
129 |
; |
130 |
console.debug('closed group by lookup', column); |
131 |
}); |
132 |
}); |
133 |
|
134 |
console.info('ready'); |
135 |
}); |
136 |
|