diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-10-28 13:44:04 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-10-28 13:44:04 +0100 |
commit | 5bac47e9b5ac37235d7bf282b13f6855c793a86f (patch) | |
tree | 2edc69f087051aa8691d03d9dc2e9e90a04cc065 | |
parent | 67ccea36c7762c4e236e821cad6c03f8f22237a4 (diff) | |
download | Ishtar-5bac47e9b5ac37235d7bf282b13f6855c793a86f.tar.bz2 Ishtar-5bac47e9b5ac37235d7bf282b13f6855c793a86f.zip |
Don't validate the form when clicking on previous step (refs #1462, refs #1463)
If a field has been changed a confirmation dialog appear.
-rw-r--r-- | archaeological_operations/wizards.py | 6 | ||||
-rw-r--r-- | ishtar_common/templates/ishtar/wizard/default_wizard.html | 18 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 27 |
3 files changed, 34 insertions, 17 deletions
diff --git a/archaeological_operations/wizards.py b/archaeological_operations/wizards.py index 48f7aeb65..f20999f18 100644 --- a/archaeological_operations/wizards.py +++ b/archaeological_operations/wizards.py @@ -179,12 +179,12 @@ class OperationWizard(Wizard): # add all parcel from available in the archaelogical file if not post_data.get('add_all_parcels'): - return super(Wizard, self).post(*args, **kwargs) + return super(OperationWizard, self).post(*args, **kwargs) general_form_key = 'general-' + self.url_name file_id = self.session_get_value(general_form_key, "associated_file") if not file_id: - return super(Wizard, self).post(*args, **kwargs) + return super(OperationWizard, self).post(*args, **kwargs) parcel_form_key = "parcels-" + self.url_name idx = -1 # remove non relevant deleted keys @@ -196,7 +196,7 @@ class OperationWizard(Wizard): post_data["%s-%d-parcel" % (parcel_form_key, idx)] = parcel_pk post_data[parcel_form_key+'-TOTAL_FORMS'] = idx + 1 request.POST = post_data - return super(Wizard, self).post(*args, **kwargs) + return super(OperationWizard, self).post(*args, **kwargs) class OperationModificationWizard(OperationWizard): modification = True diff --git a/ishtar_common/templates/ishtar/wizard/default_wizard.html b/ishtar_common/templates/ishtar/wizard/default_wizard.html index 28b9850d7..6b4bce709 100644 --- a/ishtar_common/templates/ishtar/wizard/default_wizard.html +++ b/ishtar_common/templates/ishtar/wizard/default_wizard.html @@ -9,11 +9,11 @@ <form action="." method="post" name='wizard'{% if wizard.form.file_upload %} enctype="multipart/form-data"{% endif %}>{% csrf_token %} <ul id='form_path'> {% for step in previous_steps %} - <li>» <button name="form_prev_step" value="{{forloop.counter0}}">{{step.form_label}}</button></li> + <li>» <button class='change_step' name="form_prev_step" value="{{forloop.counter0}}">{{step.form_label}}</button></li> {% endfor %} <li class='current'>» <a href='#'>{{current_step.form_label}}</a></li> {% for step in next_steps %} - <li>» <button name="form_prev_step" value="{{forloop.counter|add:previous_step_counter}}">{{step.form_label}}</button></li> + <li>» <button class='change_step' name="form_prev_step" value="{{forloop.counter|add:previous_step_counter}}">{{step.form_label}}</button></li> {% endfor %} </ul> {% endblock %} @@ -44,4 +44,18 @@ </div> </form> {% endblock %} +<script language="javascript" type="text/javascript"> +var form_changed = false; +$(document).ready(function(){ + $('form :input').change(function(){form_changed=true;}); + $('.change_step').click(function(){ + if(!form_changed || + confirm("{% trans "The form has changed if you don't validate it all your changes will be lost." %}")){ + return true; + } + return false; + }); + +}); +</script> {% endblock %} diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index f0302d70f..89f005a0a 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -534,18 +534,21 @@ class Wizard(NamedUrlWizardView): return super(Wizard, self).render_next_step(form, **kwargs) def post(self, *args, **kwargs): - """Convert numerical step number to step name""" - request = self.request - post_data = request.POST.copy() - if request.POST.has_key('form_prev_step'): - try: - step_number = int(request.POST['form_prev_step']) - post_data['wizard_goto_step'] = self.get_form_list().keys( - )[step_number] - except ValueError: - pass - request.POST = post_data - return super(Wizard, self).post(*args, **kwargs) + # manage previous (or next) step + form_prev_step = self.request.POST.get('form_prev_step', None) + if not form_prev_step: + return super(Wizard, self).post(*args, **kwargs) + try: + # convert numerical step number to step name + step_number = int(self.request.POST['form_prev_step']) + wizard_goto_step = self.get_form_list().keys()[step_number] + except (ValueError, IndexError): + return super(Wizard, self).post(*args, **kwargs) + self.storage.current_step = wizard_goto_step + form = self.get_form( + data=self.storage.get_step_data(self.steps.current), + files=self.storage.get_step_files(self.steps.current)) + return self.render(form) def session_has_key(self, form_key, key=None, multi=None): """Check if the session has value of a specific form and (if provided) |