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