/[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 25 - (hide annotations)
Sat Apr 18 23:35:57 2009 UTC (15 years ago) by dpavlin
File MIME type: application/javascript
File size: 3645 byte(s)
lookup is now scrollable and respects query limit

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     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 dpavlin 14 var type = column_type[col_nr];
28    
29 dpavlin 10 console.debug('click on ', this, e,
30     e.originalTarget,
31 dpavlin 14 column, type, where_operator, where_value
32 dpavlin 10 );
33    
34 dpavlin 11 $('form#sql .changed').removeClass('changed');
35    
36 dpavlin 10 if ( tag == 'TH' ) {
37     console.info('header', column);
38 dpavlin 11 $('form#sql input[name=order_by]')
39     .addClass('changed')
40     .attr('value', where_value + ' desc')
41     ;
42 dpavlin 10 } else if ( tag = 'TD' ) {
43     console.info('column', column, where_operator, where_value);
44 dpavlin 11 $('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 dpavlin 20 $('form#sql input[name=lookup_col]')
53 dpavlin 11 .addClass('changed')
54     .attr('value', column)
55     .css('display','block')
56     .attr('disabled',0)
57     ;
58 dpavlin 14 $('select[name=where_operator]')
59     .addClass('changed')
60     .attr('selectedIndex', type < 0 ? 0 : 2)
61     ;
62 dpavlin 10 } else {
63     console.error('unknown click on ', tag, e);
64     }
65    
66 dpavlin 22 $('form#sql').addClass('visible').addClass('fixed');
67 dpavlin 10 };
68    
69     $('table#results').bind('mouseup', click_on_cell);
70    
71     $('#status').bind('click', function() {
72 dpavlin 22 $('form#sql').toggleClass('visible').addClass('fixed');
73 dpavlin 10 });
74    
75 dpavlin 20 $('input[name=lookup_col]').bind('click', function(e) {
76 dpavlin 10 var l = $('div#lookup');
77 dpavlin 20 var column = $('form#sql input[name=lookup_col]').attr('value');
78 dpavlin 15 var col_nr = $('form#sql select[name=where_column]').attr('options').selectedIndex;
79 dpavlin 16 var operator = $('select[name=where_operator]').attr('options').selectedIndex;
80 dpavlin 10
81 dpavlin 25 l.html('...loading lookup for '+column+'...').css('display','block').scrollTop(0);
82 dpavlin 15
83     console.debug( this, e, column, col_nr, l );
84    
85 dpavlin 20 $('input[name=lookup_col]')
86 dpavlin 11 .removeClass('changed')
87     .attr('disabled', 1);
88 dpavlin 10
89 dpavlin 23 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 dpavlin 15 console.debug( data, textStatus );
98     l.addClass('changed');
99     l.html( data );
100    
101     $('div#lookup a')
102     .bind('click', function(e) {
103 dpavlin 16 console.debug( 'lookup click', e );
104 dpavlin 15 $('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 dpavlin 16 $('select[name=where_operator]')
111     .attr('options').selectedIndex = operator + 1 // remove not
112     ;
113 dpavlin 15 return false;
114     });
115     });
116    
117    
118 dpavlin 11 $('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 dpavlin 10 });
133    
134     console.info('ready');
135     });
136    

  ViewVC Help
Powered by ViewVC 1.1.26