/[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

Annotation of /sql-editor.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35 - (hide 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 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 dpavlin 35 $('table#results td').bind('click', function(e) {
14 dpavlin 10
15 dpavlin 35 var col_nr = $(this).parent().children().index( $(this) );
16 dpavlin 34
17 dpavlin 10 var column = $('table#results th:nth-child(' + ( col_nr + 1 ) + ')').text();
18     var where_operator = '=';
19 dpavlin 35 var where_value = '';
20     var selected_text = window.getSelection().getRangeAt(0).cloneContents().textContent;
21     if ( selected_text != '' )
22     where_value = '%' + selected_text + '%';
23 dpavlin 10 else
24 dpavlin 35 where_value = $(this).text();
25 dpavlin 10
26 dpavlin 14 var type = column_type[col_nr];
27    
28 dpavlin 35 console.debug('td',
29 dpavlin 14 column, type, where_operator, where_value
30 dpavlin 10 );
31    
32 dpavlin 11 $('form#sql .changed').removeClass('changed');
33    
34 dpavlin 35 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 dpavlin 10
54 dpavlin 22 $('form#sql').addClass('visible').addClass('fixed');
55 dpavlin 35 });
56 dpavlin 10
57 dpavlin 35
58 dpavlin 34 $('table#results th').bind('click', function(e) {
59     var column = $(this).text();
60 dpavlin 35 console.info('th', column);
61 dpavlin 10
62 dpavlin 34 $('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 dpavlin 10 $('#status').bind('click', function() {
74 dpavlin 22 $('form#sql').toggleClass('visible').addClass('fixed');
75 dpavlin 10 });
76    
77 dpavlin 20 $('input[name=lookup_col]').bind('click', function(e) {
78 dpavlin 10 var l = $('div#lookup');
79 dpavlin 20 var column = $('form#sql input[name=lookup_col]').attr('value');
80 dpavlin 15 var col_nr = $('form#sql select[name=where_column]').attr('options').selectedIndex;
81 dpavlin 16 var operator = $('select[name=where_operator]').attr('options').selectedIndex;
82 dpavlin 10
83 dpavlin 25 l.html('...loading lookup for '+column+'...').css('display','block').scrollTop(0);
84 dpavlin 15
85     console.debug( this, e, column, col_nr, l );
86    
87 dpavlin 20 $('input[name=lookup_col]')
88 dpavlin 11 .removeClass('changed')
89     .attr('disabled', 1);
90 dpavlin 10
91 dpavlin 23 var where_parts = [];
92     $('input[name=where_parts]').each(function(){ if (this.checked) where_parts.push(this.value) });
93     var args = {
94 dpavlin 28 table: $('input[name=from]').val(),
95 dpavlin 23 lookup_col: column,
96     where_parts: where_parts,
97     };
98     console.debug( 'get', args );
99     $.get('', args, function(data,textStatus) {
100 dpavlin 15 console.debug( data, textStatus );
101     l.addClass('changed');
102     l.html( data );
103    
104     $('div#lookup a')
105     .bind('click', function(e) {
106 dpavlin 16 console.debug( 'lookup click', e );
107 dpavlin 15 $('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 dpavlin 16 $('select[name=where_operator]')
114     .attr('options').selectedIndex = operator + 1 // remove not
115     ;
116 dpavlin 15 return false;
117     });
118     });
119    
120    
121 dpavlin 11 $('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 dpavlin 10 });
136    
137     console.info('ready');
138     });
139    

  ViewVC Help
Powered by ViewVC 1.1.26