/[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 34 - (hide annotations)
Wed Dec 9 13:10:54 2009 UTC (14 years, 4 months ago) by dpavlin
File MIME type: application/javascript
File size: 4045 byte(s)
split clicks on header and make it work on 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     function click_on_cell(e) {
14    
15 dpavlin 34 console.debug( e, this );
16    
17 dpavlin 10 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 dpavlin 14 var type = column_type[col_nr];
30    
31 dpavlin 10 console.debug('click on ', this, e,
32     e.originalTarget,
33 dpavlin 14 column, type, where_operator, where_value
34 dpavlin 10 );
35    
36 dpavlin 11 $('form#sql .changed').removeClass('changed');
37    
38 dpavlin 10 if ( tag == 'TH' ) {
39     console.info('header', column);
40 dpavlin 11 $('form#sql input[name=order_by]')
41     .addClass('changed')
42     .attr('value', where_value + ' desc')
43     ;
44 dpavlin 10 } else if ( tag = 'TD' ) {
45     console.info('column', column, where_operator, where_value);
46 dpavlin 11 $('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 dpavlin 20 $('form#sql input[name=lookup_col]')
55 dpavlin 11 .addClass('changed')
56     .attr('value', column)
57     .css('display','block')
58     .attr('disabled',0)
59     ;
60 dpavlin 14 $('select[name=where_operator]')
61     .addClass('changed')
62     .attr('selectedIndex', type < 0 ? 0 : 2)
63     ;
64 dpavlin 10 } else {
65     console.error('unknown click on ', tag, e);
66     }
67    
68 dpavlin 22 $('form#sql').addClass('visible').addClass('fixed');
69 dpavlin 10 };
70    
71 dpavlin 34 $('table#results th').bind('click', function(e) {
72     var column = $(this).text();
73     console.info('header', column);
74 dpavlin 10
75 dpavlin 34 $('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 dpavlin 10 $('#status').bind('click', function() {
88 dpavlin 22 $('form#sql').toggleClass('visible').addClass('fixed');
89 dpavlin 10 });
90    
91 dpavlin 20 $('input[name=lookup_col]').bind('click', function(e) {
92 dpavlin 10 var l = $('div#lookup');
93 dpavlin 20 var column = $('form#sql input[name=lookup_col]').attr('value');
94 dpavlin 15 var col_nr = $('form#sql select[name=where_column]').attr('options').selectedIndex;
95 dpavlin 16 var operator = $('select[name=where_operator]').attr('options').selectedIndex;
96 dpavlin 10
97 dpavlin 25 l.html('...loading lookup for '+column+'...').css('display','block').scrollTop(0);
98 dpavlin 15
99     console.debug( this, e, column, col_nr, l );
100    
101 dpavlin 20 $('input[name=lookup_col]')
102 dpavlin 11 .removeClass('changed')
103     .attr('disabled', 1);
104 dpavlin 10
105 dpavlin 23 var where_parts = [];
106     $('input[name=where_parts]').each(function(){ if (this.checked) where_parts.push(this.value) });
107     var args = {
108 dpavlin 28 table: $('input[name=from]').val(),
109 dpavlin 23 lookup_col: column,
110     where_parts: where_parts,
111     };
112     console.debug( 'get', args );
113     $.get('', args, function(data,textStatus) {
114 dpavlin 15 console.debug( data, textStatus );
115     l.addClass('changed');
116     l.html( data );
117    
118     $('div#lookup a')
119     .bind('click', function(e) {
120 dpavlin 16 console.debug( 'lookup click', e );
121 dpavlin 15 $('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 dpavlin 16 $('select[name=where_operator]')
128     .attr('options').selectedIndex = operator + 1 // remove not
129     ;
130 dpavlin 15 return false;
131     });
132     });
133    
134    
135 dpavlin 11 $('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 dpavlin 10 });
150    
151     console.info('ready');
152     });
153    

  ViewVC Help
Powered by ViewVC 1.1.26