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 |
console.debug( e, this ); |
16 |
|
17 |
var tag = e.originalTarget.tagName; |
18 |
|
19 |
var col_nr = e.originalTarget.cellIndex; |
20 |
|
21 |
var column = $('table#results th:nth-child(' + ( col_nr + 1 ) + ')').text(); |
22 |
var where_operator = '='; |
23 |
var where_value = window.getSelection().getRangeAt(0).cloneContents().textContent; |
24 |
if ( where_value.length == 0 ) |
25 |
where_value = e.originalTarget.textContent; |
26 |
else |
27 |
where_value = '%' + where_value + '%'; |
28 |
|
29 |
var type = column_type[col_nr]; |
30 |
|
31 |
console.debug('click on ', this, e, |
32 |
e.originalTarget, |
33 |
column, type, where_operator, where_value |
34 |
); |
35 |
|
36 |
$('form#sql .changed').removeClass('changed'); |
37 |
|
38 |
if ( tag == 'TH' ) { |
39 |
console.info('header', column); |
40 |
$('form#sql input[name=order_by]') |
41 |
.addClass('changed') |
42 |
.attr('value', where_value + ' desc') |
43 |
; |
44 |
} else if ( tag = 'TD' ) { |
45 |
console.info('column', column, where_operator, where_value); |
46 |
$('form#sql input[name=where_value]') |
47 |
.addClass('changed') |
48 |
.attr('value', where_value) |
49 |
; |
50 |
$('form#sql select[name=where_column]') |
51 |
.addClass('changed') |
52 |
.attr('options').selectedIndex = col_nr |
53 |
; |
54 |
$('form#sql input[name=lookup_col]') |
55 |
.addClass('changed') |
56 |
.attr('value', column) |
57 |
.css('display','block') |
58 |
.attr('disabled',0) |
59 |
; |
60 |
$('select[name=where_operator]') |
61 |
.addClass('changed') |
62 |
.attr('selectedIndex', type < 0 ? 0 : 2) |
63 |
; |
64 |
} else { |
65 |
console.error('unknown click on ', tag, e); |
66 |
} |
67 |
|
68 |
$('form#sql').addClass('visible').addClass('fixed'); |
69 |
}; |
70 |
|
71 |
$('table#results th').bind('click', function(e) { |
72 |
var column = $(this).text(); |
73 |
console.info('header', column); |
74 |
|
75 |
$('form#sql .changed').removeClass('changed'); |
76 |
|
77 |
$('form#sql input[name=order_by]') |
78 |
.addClass('changed') |
79 |
.attr('value', column + ' desc') |
80 |
; |
81 |
|
82 |
$('form#sql').addClass('visible').addClass('fixed'); |
83 |
}); |
84 |
|
85 |
// $('table#results td').bind('click', click_on_cell); |
86 |
|
87 |
$('#status').bind('click', function() { |
88 |
$('form#sql').toggleClass('visible').addClass('fixed'); |
89 |
}); |
90 |
|
91 |
$('input[name=lookup_col]').bind('click', function(e) { |
92 |
var l = $('div#lookup'); |
93 |
var column = $('form#sql input[name=lookup_col]').attr('value'); |
94 |
var col_nr = $('form#sql select[name=where_column]').attr('options').selectedIndex; |
95 |
var operator = $('select[name=where_operator]').attr('options').selectedIndex; |
96 |
|
97 |
l.html('...loading lookup for '+column+'...').css('display','block').scrollTop(0); |
98 |
|
99 |
console.debug( this, e, column, col_nr, l ); |
100 |
|
101 |
$('input[name=lookup_col]') |
102 |
.removeClass('changed') |
103 |
.attr('disabled', 1); |
104 |
|
105 |
var where_parts = []; |
106 |
$('input[name=where_parts]').each(function(){ if (this.checked) where_parts.push(this.value) }); |
107 |
var args = { |
108 |
table: $('input[name=from]').val(), |
109 |
lookup_col: column, |
110 |
where_parts: where_parts, |
111 |
}; |
112 |
console.debug( 'get', args ); |
113 |
$.get('', args, function(data,textStatus) { |
114 |
console.debug( data, textStatus ); |
115 |
l.addClass('changed'); |
116 |
l.html( data ); |
117 |
|
118 |
$('div#lookup a') |
119 |
.bind('click', function(e) { |
120 |
console.debug( 'lookup click', e ); |
121 |
$('form#sql input[name=where_value]') |
122 |
.attr('value', e.target.text ) |
123 |
; |
124 |
$('form#sql select[name=where_column]') |
125 |
.attr('options').selectedIndex = col_nr |
126 |
; |
127 |
$('select[name=where_operator]') |
128 |
.attr('options').selectedIndex = operator + 1 // remove not |
129 |
; |
130 |
return false; |
131 |
}); |
132 |
}); |
133 |
|
134 |
|
135 |
$('input[name=close_group_by]') |
136 |
.addClass('changed') |
137 |
.attr('disabled', 0) |
138 |
.bind('click', function() { |
139 |
l.css('display','none') |
140 |
.addClass('changed') |
141 |
.attr('disabled', 0) |
142 |
; |
143 |
$('input[name=close_group_by]') |
144 |
.removeClass('changed') |
145 |
.attr('disabled', 1) |
146 |
; |
147 |
console.debug('closed group by lookup', column); |
148 |
}); |
149 |
}); |
150 |
|
151 |
console.info('ready'); |
152 |
}); |
153 |
|