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