--- sql-editor.js 2009/04/14 20:53:44 11 +++ sql-editor.js 2009/04/15 18:42:41 15 @@ -1,4 +1,13 @@ +// fake firebug's console.* +if (!window.console) { + var names = [ "log", "debug", "info", "warn", "error" ]; + window.console = {}; + for (i in names) { + window.console[names[i]] = function() {}; + } +} + $(document).ready( function() { function click_on_cell(e) { @@ -15,9 +24,11 @@ else where_value = '%' + where_value + '%'; + var type = column_type[col_nr]; + console.debug('click on ', this, e, e.originalTarget, - column, where_operator, where_value + column, type, where_operator, where_value ); $('form#sql .changed').removeClass('changed'); @@ -44,6 +55,10 @@ .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); } @@ -59,15 +74,38 @@ $('input[name=add_group_by]').bind('click', function(e) { var l = $('div#lookup'); - l.css('display','block'); var column = $('form#sql input[name=add_group_by]').attr('value'); - console.debug( this, e, column, l ); + var col_nr = $('form#sql select[name=where_column]').attr('options').selectedIndex; + + l.html('...loading '+column+'...').css('display','block'); + + console.debug( this, e, column, col_nr, l ); $('input[name=add_group_by]') .removeClass('changed') .attr('disabled', 1); - l.load('?add_group_by='+column); + $.get('', { add_group_by: column }, function(data,textStatus) { + console.debug( data, textStatus ); + l.addClass('changed'); + l.html( data ); + + $('div#lookup a') + .bind('click', function(e) { + console.debug( e ); + $('form#sql input[name=where_value]') + .addClass('changed') + .attr('value', e.target.text ) + ; + $('form#sql select[name=where_column]') + .addClass('changed') + .attr('options').selectedIndex = col_nr + ; + return false; + }); + }); + + $('input[name=close_group_by]') .addClass('changed') .attr('disabled', 0)