less false positives in debug output
[objavi2.git] / static / form.js
blob709b1373cc4783e305b7ffd3847dd6130b6d000f
1 /* Part of Objavi2, which turns html manuals into books. This file
2  * provides javascript to help people select the book and options they
3  * want.
4  *
5  * Copyright (C) 2009 Douglas Bagnall
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
22 function toggle_advanced(){
23     var adv = $(".advanced");
24     if (adv.filter(".gone").length){
25         $("#toggle-advanced").text('Hide advanced options');
26         adv.removeClass("gone");
27     }
28     else {
29         $("#toggle-advanced").text('Show advanced options');
30         adv.addClass("gone");
31     }
32     return false;
36 function css_mode_switch(){
37     var v = $("#css-control").val();
39     function on(s){
40         $('.css-' + s).removeClass("hidden-css");
41         $('.css-' + s + ' input').removeAttr('disabled');
42         $('.css-' + s + ' textarea').removeAttr('disabled');
43     }
44     function off(s){
45         $('.css-' + s + ' input').attr('disabled', 'disabled');
46         $('.css-' + s + ' textarea').attr('disabled', 'disabled');
47         $('.css-' + s).addClass("hidden-css");
48     }
50     if (v == 'default'){
51         off('custom');
52         off('url');
53     }
54     else {
55         var not_v = (v == 'url') ? 'custom' : 'url';
56         on(v);
57         off(not_v);
58     }
61 function mode_switch(){
62     /*For openoffice mode, hide the irrelevant inputs */
63     var mode = $("#mode").val();
64     if (mode == 'openoffice'){
65         $('.advanced').not($('.openoffice')).addClass('hidden-mode');
66     }
67     else {
68         $('div.advanced').removeClass('hidden-mode');
69     }
72 function load_booklist(){
73     var server = $("#server").val();
74     var w = $("#book");
75     var book = w.val();
76     w.attr('disabled', 'disabled');
77     w.load("?server=" + server + "&book=" + book + "&mode=booklist",
78            undefined, function(){w.removeAttr('disabled');}
79     );
82 function load_css(){
83     var server = $("#server").val();
84     var textarea = $('#css');
86     //Try to get CSS to suit current mode
87     $.get("?server=" + server + "&mode=css&pdftype=" + $("#mode").val(),
88           undefined, function(data){textarea.val(data);}
89     );
93 function toggle_custom_size(){
94     var v = $("#booksize").val();
95     if (v == 'custom'){
96         $('.booksize').removeClass("hidden");
97     }
98     else {
99         $('.booksize').addClass("hidden");
100     }
103 function onload(){
104     $(".advanced").addClass("gone");
106     if ($("#toggle-advanced").length == 0){
107         $("#license_div").after('<button id="toggle-advanced">Show advanced options</button>');
108         $("#toggle-advanced").click(toggle_advanced);
109     }
111     $("#booksize").change(toggle_custom_size);
112     toggle_custom_size();
114     $("#server").change(load_booklist);
116     if ($("#css-control").length == 0){
117         $(".css-url").before('<div id="css-control_div" class="advanced form-item openoffice">' +
118                              '<div class="input_title">CSS mode</div>' +
119                              '<div><select id="css-control">' +
120                              '<option value="default" selected="selected">Server default</option>' +
121                              '<option value="url">URL</option>' +
122                              '<option value="custom">Custom</option>' +
123                              '</select></div></div>'
124                             ).attr("name", 'css');
125         $('#css_div .input_title').after('<a href="#" onclick="load_css(); return false;">' +
126                                          'Load default CSS for this server and mode ' +
127                                          '(lose changes)</a>');
128     }
130     $("#mode").change(mode_switch);
131     $("#css-control").change(css_mode_switch);
132     css_mode_switch();
133     //load the booklist for the selected server
134     load_booklist();
138 $(onload);