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

Diff of /sql-editor.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 23 by dpavlin, Sat Apr 18 23:14:41 2009 UTC revision 35 by dpavlin, Wed Dec 9 13:43:34 2009 UTC
# Line 10  if (!window.console) { Line 10  if (!window.console) {
10    
11  $(document).ready( function() {  $(document).ready( function() {
12    
13          function click_on_cell(e) {          $('table#results td').bind('click', function(e) {
14    
15                  var tag = e.originalTarget.tagName;                  var col_nr = $(this).parent().children().index( $(this) );
   
                 var col_nr = e.originalTarget.cellIndex;  
16    
17                  var column = $('table#results th:nth-child(' + ( col_nr + 1 ) + ')').text();                  var column = $('table#results th:nth-child(' + ( col_nr + 1 ) + ')').text();
18                  var where_operator = '=';                  var where_operator = '=';
19                  var where_value = window.getSelection().getRangeAt(0).cloneContents().textContent;                  var where_value = '';
20                  if ( where_value.length == 0 )                  var selected_text = window.getSelection().getRangeAt(0).cloneContents().textContent;
21                          where_value = e.originalTarget.textContent;                  if ( selected_text != '' )
22                            where_value = '%' + selected_text + '%';
23                  else                  else
24                          where_value = '%' + where_value + '%';                          where_value = $(this).text();
25    
26                  var type = column_type[col_nr];                  var type = column_type[col_nr];
27    
28                  console.debug('click on ', this, e,                  console.debug('td',
                         e.originalTarget,  
29                          column, type, where_operator, where_value                          column, type, where_operator, where_value
30                  );                  );
31    
32                  $('form#sql .changed').removeClass('changed');                  $('form#sql .changed').removeClass('changed');
33    
34                  if ( tag == 'TH' ) {                  console.info('column', column, where_operator, where_value);
35                          console.info('header', column);                  $('form#sql input[name=where_value]')
36                          $('form#sql input[name=order_by]')                          .addClass('changed')
37                                  .addClass('changed')                          .attr('value', where_value)
38                                  .attr('value', where_value + ' desc')                          ;
39                                  ;                  $('form#sql select[name=where_column]')
40                  } else if ( tag = 'TD' ) {                          .addClass('changed')
41                          console.info('column', column, where_operator, where_value);                          .attr('options').selectedIndex = col_nr
42                          $('form#sql input[name=where_value]')                          ;
43                                  .addClass('changed')                  $('form#sql input[name=lookup_col]')
44                                  .attr('value', where_value)                          .addClass('changed')
45                                  ;                          .attr('value', column)
46                          $('form#sql select[name=where_column]')                          .css('display','block')
47                                  .addClass('changed')                          .attr('disabled',0)
48                                  .attr('options').selectedIndex = col_nr                          ;
49                                  ;                  $('select[name=where_operator]')
50                          $('form#sql input[name=lookup_col]')                          .addClass('changed')
51                                  .addClass('changed')                          .attr('selectedIndex', type < 0 ? 0 : 2)
52                                  .attr('value', column)                          ;
                                 .css('display','block')  
                                 .attr('disabled',0)  
                                 ;  
                         $('select[name=where_operator]')  
                                 .addClass('changed')  
                                 .attr('selectedIndex', type < 0 ? 0 : 2)  
                                 ;  
                 } else {  
                         console.error('unknown click on ', tag, e);  
                 }  
53                    
54                  $('form#sql').addClass('visible').addClass('fixed');                  $('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    
         $('table#results').bind('mouseup', click_on_cell);  
72    
73          $('#status').bind('click', function() {          $('#status').bind('click', function() {
74                  $('form#sql').toggleClass('visible').addClass('fixed');                  $('form#sql').toggleClass('visible').addClass('fixed');
# Line 78  $(document).ready( function() { Line 80  $(document).ready( function() {
80                  var col_nr = $('form#sql select[name=where_column]').attr('options').selectedIndex;                  var col_nr = $('form#sql select[name=where_column]').attr('options').selectedIndex;
81                  var operator = $('select[name=where_operator]').attr('options').selectedIndex;                  var operator = $('select[name=where_operator]').attr('options').selectedIndex;
82    
83                  l.html('...loading lookup for '+column+'...').css('display','block');                  l.html('...loading lookup for '+column+'...').css('display','block').scrollTop(0);
84    
85                  console.debug( this, e, column, col_nr, l );                  console.debug( this, e, column, col_nr, l );
86    
# Line 89  $(document).ready( function() { Line 91  $(document).ready( function() {
91                  var where_parts = [];                  var where_parts = [];
92                  $('input[name=where_parts]').each(function(){ if (this.checked) where_parts.push(this.value) });                  $('input[name=where_parts]').each(function(){ if (this.checked) where_parts.push(this.value) });
93                  var args = {                  var args = {
94                            table: $('input[name=from]').val(),
95                          lookup_col: column,                          lookup_col: column,
96                          where_parts: where_parts,                          where_parts: where_parts,
97                  };                  };

Legend:
Removed from v.23  
changed lines
  Added in v.35

  ViewVC Help
Powered by ViewVC 1.1.26