9 {'actions':['print', 'export'], 'extension':'latex', 'label': gettext('download latex file (.tex)')}, |
9 {'actions':['print', 'export'], 'extension':'latex', 'label': gettext('download latex file (.tex)')}, |
10 {'actions':['print', 'export'], 'extension':'odt', 'label': gettext('download open document file (.odt)')}] ; |
10 {'actions':['print', 'export'], 'extension':'odt', 'label': gettext('download open document file (.odt)')}] ; |
11 |
11 |
12 |
12 |
13 gActions = {'print':{'dialogTitle':gettext('Print text'), 'chooseFormatLabel':gettext('How do you want to print?'), 'defaultMethod':'pdf', 'defaultWithColors':"no", 'defaultWhichComments':'all'}, |
13 gActions = {'print':{'dialogTitle':gettext('Print text'), 'chooseFormatLabel':gettext('How do you want to print?'), 'defaultMethod':'pdf', 'defaultWithColors':"no", 'defaultWhichComments':'all'}, |
14 'export':{'dialogTitle':gettext('Export text'), 'chooseFormatLabel':gettext('Choose file format'), 'defaultMethod':'pdf', 'defaultWithColors':"no", 'defaultWhichComments':'all'}} ; |
14 'export':{'dialogTitle':gettext('Export text'), 'chooseFormatLabel':gettext('Choose file format'), 'defaultMethod':'pdf', 'defaultWithColors':"no", 'defaultWhichComments':'all'}} ; |
15 gCurrentAction = null ; |
15 gCurrentAction = null ; |
16 |
16 |
17 _populateMethod = function(withColors) { |
17 _populateMethod = function(withColors) { |
18 var val = $("#p_method").val(); |
18 var val = $("#p_method").val(); |
19 |
19 |
20 $("#p_method").html(""); |
20 $("#p_method").html(""); |
21 |
21 |
22 for (var i = 0, ilen = gFormats.length ; i < ilen ; i++) { |
22 for (var i = 0, ilen = gFormats.length ; i < ilen ; i++) { |
23 var actions = gFormats[i]['actions'] ; |
23 var actions = gFormats[i]['actions'] ; |
24 for (var j = 0, jlen = gFormats.length ; j < jlen ; j++) { |
24 for (var j = 0, jlen = gFormats.length ; j < jlen ; j++) { |
25 if (actions[j] == gCurrentAction) |
25 if (actions[j] == gCurrentAction) |
26 $("<option value='" + gFormats[i]['extension'] + "'>" + gFormats[i]['label'] + "</option>").appendTo("#p_method"); |
26 $("<option value='" + gFormats[i]['extension'] + "'>" + gFormats[i]['label'] + "</option>").appendTo("#p_method"); |
27 } |
27 } |
28 } |
28 } |
29 if (val) |
29 if (val) |
30 $("#p_method").val(val); |
30 $("#p_method").val(val); |
31 else |
31 else |
32 $("#p_method").val(gActions[gCurrentAction]['defaultMethod']); |
32 $("#p_method").val(gActions[gCurrentAction]['defaultMethod']); |
33 |
33 |
34 } ; |
34 } ; |
35 |
35 |
36 _populateMarkersColorsChoice = function(withColors) { |
36 _populateMarkersColorsChoice = function(withColors) { |
37 var val = $("#p_color").val(); |
37 var val = $("#p_color").val(); |
38 |
38 |
39 $("#p_color").html(""); |
39 $("#p_color").html(""); |
40 |
40 |
41 $("<option value='0'>" + gettext("using markers only, no background colors") + "</option>").appendTo("#p_color"); |
41 $("<option value='0'>" + gettext("using markers only, no background colors") + "</option>").appendTo("#p_color"); |
42 $("<option value='1'>" + gettext("using markers and background colors") + "</option>").appendTo("#p_color"); |
42 $("<option value='1'>" + gettext("using markers and background colors") + "</option>").appendTo("#p_color"); |
43 |
43 |
44 if (val) |
44 if (val) |
45 $("#p_color").val(val); |
45 $("#p_color").val(val); |
46 else |
46 else |
47 $("#p_color").val(gActions[gCurrentAction]['defaultWithColors']); |
47 $("#p_color").val(gActions[gCurrentAction]['defaultWithColors']); |
48 } ; |
48 } ; |
49 |
49 |
50 _populateWhichComments = function() { |
50 _populateWhichComments = function() { |
51 var val = $("#p_comments").val(); |
51 var val = $("#p_comments").val(); |
52 |
52 |
53 $("#p_comments").html(""); |
53 $("#p_comments").html(""); |
54 var all = interpolate(gettext("all (%(nb_comments)s)"), {'nb_comments':frames['text_view_comments'].gDb.getCommentsNb(true)}, true) ; |
54 var all = interpolate(gettext("all (%(nb_comments)s)"), {'nb_comments':frames['text_view_comments'].gDb.getCommentsNb(true)}, true) ; |
55 var currents = interpolate(gettext("current filtered ones (%(nb_comments)s)"), {'nb_comments':frames['text_view_comments'].gDb.getCommentsNb(false)}, true) ; |
55 var currents = interpolate(gettext("current filtered ones (%(nb_comments)s)"), {'nb_comments':frames['text_view_comments'].gDb.getCommentsNb(false)}, true) ; |
56 $("<option value='all' >" + all +"</option>").appendTo($("#p_comments")) ; |
56 $("<option value='all' >" + all +"</option>").appendTo($("#p_comments")) ; |
57 $("<option value='none' >" + gettext("none (0)") + "</option>").appendTo($("#p_comments")) ; |
57 $("<option value='none' >" + gettext("none (0)") + "</option>").appendTo($("#p_comments")) ; |
58 $("<option value='filtered' >" + currents + "</option>").appendTo($("#p_comments")) ; |
58 $("<option value='filtered' >" + currents + "</option>").appendTo($("#p_comments")) ; |
59 |
59 |
60 if (val) |
60 if (val) |
61 $("#p_comments").val(val); |
61 $("#p_comments").val(val); |
62 else |
62 else |
63 $("#p_comments").val(gActions[gCurrentAction]['defaultWhichComments']); |
63 $("#p_comments").val(gActions[gCurrentAction]['defaultWhichComments']); |
64 } ; |
64 } ; |
65 |
65 |
66 _manageMarkersColorsChoice = function() { |
66 _manageMarkersColorsChoice = function() { |
67 var method = $("#p_method").val(); |
67 var method = $("#p_method").val(); |
68 var which = $("#p_comments").val(); |
68 var which = $("#p_comments").val(); |
69 |
69 |
70 var disableMarkersColorsChoice ; |
70 var disableMarkersColorsChoice ; |
71 if (gCurrentAction == 'print') |
71 if (gCurrentAction == 'print') |
72 disableMarkersColorsChoice = ((which == 'none') || (method == 'markdown') || (method == 'html')) ; |
72 disableMarkersColorsChoice = ((which == 'none') || (method == 'markdown') || (method == 'html')) ; |
73 if (gCurrentAction == 'export') |
73 if (gCurrentAction == 'export') |
74 disableMarkersColorsChoice = ((which == 'none') || (method == 'markdown')) ; |
74 disableMarkersColorsChoice = ((which == 'none') || (method == 'markdown')) ; |
75 |
75 |
76 if (disableMarkersColorsChoice) |
76 if (disableMarkersColorsChoice) |
77 $("#p_color").val('no'); |
77 $("#p_color").val('no'); |
78 |
78 |
79 $("#p_color").attr("disabled", disableMarkersColorsChoice); |
79 $("#p_color").attr("disabled", disableMarkersColorsChoice); |
80 |
80 |
81 } ; |
81 } ; |
82 |
82 |
83 _initPrintDialog = function() { |
83 _initPrintDialog = function() { |
84 $('#p_comments').add($('#p_method')).change(function() { |
84 $('#p_comments').add($('#p_method')).change(function() { |
85 _manageMarkersColorsChoice() ; |
85 _manageMarkersColorsChoice() ; |
86 _prepareOpenInNewWindow() ; |
86 _prepareOpenInNewWindow() ; |
87 }) ; |
87 }) ; |
88 |
88 |
89 var buttons = {} ; |
89 var buttons = {} ; |
90 buttons[gettext('Go !')] = function() { |
90 buttons[gettext('Go !')] = function() { |
91 var whichComments = $("#p_comments").val() ; |
91 var whichComments = $("#p_comments").val() ; |
92 var withColor = $("#p_color").val() ; |
92 var withColor = $("#p_color").val() ; |
93 var format = $("#p_method").val() ; |
93 var format = $("#p_method").val() ; |
94 var download = (gCurrentAction == "export") ? "1" : (format == "html") ? "0" : "1" ; |
94 var download = (gCurrentAction == "export") ? "1" : (format == "html") ? "0" : "1" ; |
95 var targetUrl = $("#print_export_form").attr('target_action').replace(/FoRmAt/,format).replace(/DoWnLoAd/, download).replace(/WhIcHCoMmEnT/, whichComments).replace(/WiThCoLoR/, withColor) ; |
95 var targetUrl = $("#print_export_form").attr('target_action').replace(/FoRmAt/,format).replace(/DoWnLoAd/, download).replace(/WhIcHCoMmEnT/, whichComments).replace(/WiThCoLoR/, withColor) ; |
96 $("#print_export_form").attr('action', targetUrl) ; |
96 $("#print_export_form").attr('action', targetUrl) ; |
97 |
97 |
98 document['print_export_form'].submit(); |
98 document['print_export_form'].submit(); |
99 $(this).dialog('close'); |
99 $(this).dialog('close'); |
100 } ; |
100 } ; |
101 buttons[gettext('Cancel')] = function() { |
101 buttons[gettext('Cancel')] = function() { |
102 $(this).dialog('close'); |
102 $(this).dialog('close'); |
103 } ; |
103 } ; |
104 |
104 |
105 |
105 |
106 $("#dialog_print_export").dialog({ |
106 $("#dialog_print_export").dialog({ |
107 bgiframe: true, |
107 bgiframe: true, |
108 autoOpen: false, |
108 autoOpen: false, |
109 width: 450, |
109 width: 450, |
110 /* height: 300, |
110 /* height: 300, |
111 autoResize: false,*/ |
111 autoResize: false,*/ |
112 modal: true, |
112 modal: true, |
113 buttons: buttons, |
113 buttons: buttons, |
114 close: function() { |
114 close: function() { |
115 ; // empty |
115 ; // empty |
116 } |
116 } |
117 }); |
117 }); |
118 } |
118 } |
119 |
119 |
120 openPrintDialog = function() { |
120 openPrintDialog = function() { |
121 _openPrintExportDialog('print') ; |
121 _openPrintExportDialog('print') ; |
122 } |
122 } |
123 |
123 |
124 openExportDialog = function() { |
124 openExportDialog = function() { |
125 _openPrintExportDialog('export') ; |
125 _openPrintExportDialog('export') ; |
126 } |
126 } |
127 |
127 |
128 _prepareOpenInNewWindow = function() { |
128 _prepareOpenInNewWindow = function() { |
129 var method = $("#p_method").val(); |
129 var method = $("#p_method").val(); |
130 if ((method == "html") && (gCurrentAction == 'print')) |
130 if ((method == "html") && (gCurrentAction == 'print')) |
131 $("#print_export_form").attr("target", "_blank") ; |
131 $("#print_export_form").attr("target", "_blank") ; |
132 else |
132 else |
133 $("#print_export_form").removeAttr("target") ; |
133 $("#print_export_form").removeAttr("target") ; |
134 } |
134 } |
135 |
135 |
136 _openPrintExportDialog = function(action) { |
136 _openPrintExportDialog = function(action) { |
137 gCurrentAction = action ; |
137 gCurrentAction = action ; |
138 $("#ui-dialog-title-dialog_print_export").html(gActions[gCurrentAction]['dialogTitle']) ; |
138 $("#ui-dialog-title-dialog_print_export").html(gActions[gCurrentAction]['dialogTitle']) ; |
139 $("#how").html(gActions[gCurrentAction]['chooseFormatLabel']) ; |
139 $("#how").html(gActions[gCurrentAction]['chooseFormatLabel']) ; |
140 $("#print_export_action").val(action) ; // TODO check this still usefull |
140 $("#print_export_action").val(action) ; // TODO check this still usefull |
141 |
141 |
142 |
142 |
143 _populateWhichComments() ; |
143 _populateWhichComments() ; |
144 _populateMarkersColorsChoice() ; |
144 _populateMarkersColorsChoice() ; |
145 _populateMethod() ; |
145 _populateMethod() ; |
146 |
146 |
147 _manageMarkersColorsChoice() ; |
147 _manageMarkersColorsChoice() ; |
148 _prepareOpenInNewWindow() ; |
148 _prepareOpenInNewWindow() ; |
149 |
149 |
150 $('#dialog_print_export').dialog('open'); |
150 $('#dialog_print_export').dialog('open'); |
151 } |
151 } |
152 |
152 |
153 /* |
153 /* |
154 tips.text(t).effect("highlight",{},1500); |
154 tips.text(t).effect("highlight",{},1500); |
155 */ |
155 */ |