kopia lustrzana https://github.com/hholzgra/maposmatic/
Fix paper_width_mm/paper_height_mm handling
Introduce two hidden fields in MapRenderingJobForm to store paper_width_mm and paper_height_mm. Those two fields are updated by the JS code when the selected paper size changes. They are then sent to the server as part of the wizard form and then stored in the database. It allows to fix the handling of paper sizes for "Best fit" renderings. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@enix.org> Signed-off-by: Maxime Petazzoni <maxime.petazzoni@bulix.org>stable
rodzic
7a2e752476
commit
370787ad97
|
@ -67,6 +67,8 @@ class MapRenderingJobForm(forms.ModelForm):
|
|||
papersize = forms.ChoiceField(choices=(), widget=forms.RadioSelect)
|
||||
paperorientation = forms.ChoiceField(choices=ORIENTATION,
|
||||
widget=forms.RadioSelect)
|
||||
paper_width_mm = forms.IntegerField(widget=forms.HiddenInput)
|
||||
paper_height_mm = forms.IntegerField(widget=forms.HiddenInput)
|
||||
maptitle = forms.CharField(max_length=256, required=False)
|
||||
bbox = widgets.AreaField(label=_("Area"),
|
||||
fields=(forms.FloatField(), forms.FloatField(),
|
||||
|
@ -119,14 +121,9 @@ class MapRenderingJobForm(forms.ModelForm):
|
|||
city = cleaned_data.get("administrative_city")
|
||||
title = cleaned_data.get("maptitle")
|
||||
|
||||
for p in renderers.Renderer.PAPER_SIZES:
|
||||
if p[0] == cleaned_data.get("papersize"):
|
||||
w, h = p[2], p[1]
|
||||
if cleaned_data.get("paperorientation") == 'landscape':
|
||||
w, h = p[2], p[1]
|
||||
cleaned_data["paper_width_mm"] = w
|
||||
cleaned_data["paper_height_mm"] = h
|
||||
break
|
||||
if cleaned_data.get("paperorientation") == 'landscape':
|
||||
cleaned_data["paper_width_mm"], cleaned_data["paper_height_mm"] = \
|
||||
cleaned_data.get("paper_height_mm"), cleaned_data.get("paper_width_mm")
|
||||
|
||||
if title == '':
|
||||
msg = _(u"Map title required")
|
||||
|
|
|
@ -61,15 +61,18 @@ function getPaperDef(paperlist, paper)
|
|||
return null;
|
||||
}
|
||||
|
||||
/* This function updates the landscape/portrait selectors according to
|
||||
* the portraitOk/landscapeOk booleans telling whether portrait and
|
||||
* landscape are possible. */
|
||||
function filterAllowedOrientations(portraitOk, landscapeOk)
|
||||
/* This function :
|
||||
* - updates the landscape/portrait selectors according to the
|
||||
* portraitOk/landscapeOk booleans telling whether portrait and
|
||||
* landscape are possible.
|
||||
* - updates the hidden fields paper_width_mm and paper_height_mm
|
||||
*/
|
||||
function handlePaperSizeClick(width_mm, height_mm, portrait_ok, landscape_ok)
|
||||
{
|
||||
landscape = $("input[value='landscape']");
|
||||
portrait = $("input[value='portrait']");
|
||||
|
||||
if (landscapeOk) {
|
||||
if (landscape_ok) {
|
||||
landscape.attr("disabled", "");
|
||||
landscape.attr("checked", "checked");
|
||||
landscape.parent().parent().removeClass("disabled");
|
||||
|
@ -79,9 +82,9 @@ function filterAllowedOrientations(portraitOk, landscapeOk)
|
|||
landscape.parent().parent().addClass("disabled");
|
||||
}
|
||||
|
||||
if (portraitOk) {
|
||||
if (portrait_ok) {
|
||||
portrait.attr("disabled", "");
|
||||
if (! landscapeOk)
|
||||
if (! landscape_ok)
|
||||
portrait.attr("checked", "checked");
|
||||
portrait.parent().parent().removeClass("disabled");
|
||||
}
|
||||
|
@ -89,12 +92,15 @@ function filterAllowedOrientations(portraitOk, landscapeOk)
|
|||
portrait.attr("disabled", "disabled");
|
||||
portrait.parent().parent().addClass("disabled");
|
||||
}
|
||||
|
||||
$("#id_paper_width_mm").val(width_mm);
|
||||
$("#id_paper_height_mm").val(height_mm);
|
||||
}
|
||||
|
||||
function bindPaperClickCallback(fn, portraitOk, landscapeOk)
|
||||
function bindPaperClickCallback(fn, width_mm, height_mm, portrait_ok, landscape_ok)
|
||||
{
|
||||
return (function(e) {
|
||||
fn(portraitOk, landscapeOk);
|
||||
fn(width_mm, height_mm, portrait_ok, landscape_ok);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -109,7 +115,8 @@ function filterAllowedPaper(paperlist)
|
|||
paperDef = getPaperDef(paperlist, paper);
|
||||
if (paperDef != null) {
|
||||
$('label', item).bind('click',
|
||||
bindPaperClickCallback(filterAllowedOrientations,
|
||||
bindPaperClickCallback(handlePaperSizeClick,
|
||||
paperDef[1], paperDef[2],
|
||||
paperDef[3], paperDef[4]));
|
||||
$(item).show();
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@
|
|||
<td id="papersizeselection">{{ form.papersize }}</td>
|
||||
<td id="paperorientationselection">{{ form.paperorientation }}</td></tr>
|
||||
</table>
|
||||
{{ form.paper_width_mm }}{{ form.paper_height_mm }}
|
||||
</div>
|
||||
|
||||
<div id="step-stylesheet" class="wizardstep">
|
||||
|
|
Ładowanie…
Reference in New Issue