From 342196b935471015d29d6cb9c51a36d24eba54b4 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Fri, 6 Apr 2012 15:31:45 +0200 Subject: [PATCH] In the creation wizard (for account creation), added step title and counter. fixes #216 --- admin/views.py | 15 +++++++++------ lib/formutils.py | 9 ++++++--- static/js/creation_wizard.js | 1 + templates/admin/newaccount.html | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/admin/views.py b/admin/views.py index 6cc2463da..0b0580665 100644 --- a/admin/views.py +++ b/admin/views.py @@ -293,19 +293,21 @@ def newaccount(request, tplname='admin/newaccount.html'): submit_label=_("Create") ) cwizard = CreationWizard(create_account) - cwizard.add_step(AccountFormGeneralPwd, - buttons=[dict(classes="btn-inverse next", label=_("Next"))], + cwizard.add_step(AccountFormGeneralPwd, _("General"), + [dict(classes="btn-inverse next", label=_("Next"))], new_args=[request.user]) - cwizard.add_step(AccountFormMail, - buttons=[dict(classes="btn-primary submit", label=_("Create")), - dict(classes="btn-inverse prev", label=_("Previous"))]) + cwizard.add_step(AccountFormMail, _("Mail"), + [dict(classes="btn-primary submit", label=_("Create")), + dict(classes="btn-inverse prev", label=_("Previous"))]) if request.method == "POST": retcode, data = cwizard.validate_step(request) if retcode == -1: raise AdminError(data) if retcode == 1: - return ajax_simple_response(dict(status="ok")) + return ajax_simple_response(dict( + status="ok", title=cwizard.get_title(data + 1) + )) if retcode == 2: messages.info(request, _("Account created")) return ajax_simple_response(dict(status="ok")) @@ -314,6 +316,7 @@ def newaccount(request, tplname='admin/newaccount.html'): cwizard.create_forms() ctx.update(steps=cwizard.steps) + ctx.update(subtitle="1. %s" % cwizard.steps[0]['title']) return _render(request, tplname, ctx) @login_required diff --git a/lib/formutils.py b/lib/formutils.py index a193a6f4f..3d6c77e25 100644 --- a/lib/formutils.py +++ b/lib/formutils.py @@ -11,8 +11,8 @@ class CreationWizard(object): self.steps = [] self.done_cb = done_cb - def add_step(self, cls, buttons, new_args=None): - self.steps += [dict(cls=cls, buttons=buttons, new_args=new_args)] + def add_step(self, cls, title, buttons, new_args=None): + self.steps += [dict(cls=cls, title=title, buttons=buttons, new_args=new_args)] def create_forms(self, data=None): for step in self.steps: @@ -37,9 +37,12 @@ class CreationWizard(object): if stepid == len(self.steps) - 1: self.done_cb(self.steps) return 2, None - return 1, None + return 1, stepid return 0, stepid + def get_title(self, stepid): + return "%d. %s" % (stepid + 1, self.steps[stepid]["title"]) + class DynamicForm(object): def _create_field(self, typ, name, value=None, pos=None): diff --git a/static/js/creation_wizard.js b/static/js/creation_wizard.js index 458cb6221..68e5db07f 100644 --- a/static/js/creation_wizard.js +++ b/static/js/creation_wizard.js @@ -22,6 +22,7 @@ $.post($form.attr("action"), data, $.proxy(function(resp) { if (resp.status == "ok") { if (!last) { + $(".modal-header").find("small").html(resp.title); this.$element.carousel('next'); } else { $("#modalbox").modal('hide').remove(); diff --git a/templates/admin/newaccount.html b/templates/admin/newaccount.html index 2722d9dac..3e7d05790 100644 --- a/templates/admin/newaccount.html +++ b/templates/admin/newaccount.html @@ -1,7 +1,7 @@ {% load i18n libextras %}