/[sql-web-session]/sql-editor.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /sql-editor.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (show annotations)
Wed Dec 9 13:43:34 2009 UTC (14 years, 4 months ago) by dpavlin
File MIME type: application/javascript
File size: 3656 byte(s)
rewrite click on table cells and header to work in Chrome

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

  ViewVC Help
Powered by ViewVC 1.1.26