summaryrefslogtreecommitdiff
path: root/extras/appengine/static/script.js
blob: 8bdf271e725f20a9cbf68f8c7004881109f2ff82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var initialized = false;

function update_output() {
    data = {}
    data.data = $('#id_data').val();
    data.format = 'json';
    if ( $('#id_remove_comments').attr('checked') ) {
	data.remove_comments = 1
    }
    if ( $('#id_highlight').attr('checked') ) { data.highlight = 1 }
    data.keyword_case = $('#id_keyword_case').val();
    data.identifier_case = $('#id_identifier_case').val();
    data.n_indents = $('#id_n_indents').val();
    data.output_format = $('#id_output_format').val();
    form = document.getElementById('form_options');
    $(form.elements).attr('disabled', 'disabled');
    $('#response').addClass('loading');
    $.post('/', data,
	function(data) {
	    if ( data.output )  {
		$('#response').html(data.output);
		proc_time = 'Processed in '+data.proc_time+' seconds.';
	    } else {
		$('#response').html('An error occured: '+data.errors);
		proc_time = '';
	    }
	    $('#proc_time').html(proc_time);
	    $(form.elements).each( function(idx) {
		    obj = $(this);
		    if ( ! obj.is('.keep-disabled') ) {
			obj.removeAttr('disabled');
		    }
		});
	    $('#response').removeClass('loading');
	}, 'json');
    return false;
}

function toggle_fieldset(event) {
    id = $(this).attr('id');
    $('#'+id+'_content').slideDown();
    $('legend').each(function(idx) {
	    obj = $('#'+this.id+'_content');
	    if ( this.id != id ) {
		obj.slideUp();
	    }
	});
}


function textarea_grab_focus(evt) {
    evt.stopPropagation();
    evt.preventDefault();
    $('#id_data').focus();
    return false;
}


function show_help() {
    $('#help').toggle();
    return false;
}


function hide_help() {
    $('#help').hide();
    return false;
}

function load_example() {
    fname = $('#sel_example').val();
    data = {fname: fname};
    $.post('/load_example', data,
	       function(data) {
	       $('#id_data').val(data.answer);
	   }, 'json');
}


function init() {
    if (initialized) { return }
    //$('legend').bind('click', toggle_fieldset);
    //    $('legend').each(function(idx) {
    //	    obj = $('#'+this.id+'_content');
    //	    if ( this.id != 'general' ) {
    //		obj.hide();
    //	    }
    //	});
    $(document).bind('keydown', {combi:'Ctrl+f'},
		     update_output);
    $('#btn_format').val('Format SQL [Ctrl+F]');
    $(document).bind('keydown', {combi: 'h', disableInInput: true},
		     show_help);
    $(document).bind('keydown', 'Esc', hide_help);
    $(document).bind('keydown', {combi: 't', disableInInput: true},
		     textarea_grab_focus);
    initialized = true;
}