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