diff options
author | Azul <azul@leap.se> | 2012-12-07 10:00:21 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2012-12-07 10:01:32 +0100 |
commit | af101adb7c66201e175642ff0ef99988b42d2df2 (patch) | |
tree | 5fb26703a80fc7f0f8954ce7a808d78003098ab9 /users/app | |
parent | bc2ead40468f0d9372372f73260d83d30e93bc9a (diff) |
refactored views to ease adding of email form
Diffstat (limited to 'users/app')
-rw-r--r-- | users/app/helpers/users_helper.rb | 20 | ||||
-rw-r--r-- | users/app/models/user.rb | 1 | ||||
-rw-r--r-- | users/app/views/users/_email_field.html.haml | 1 | ||||
-rw-r--r-- | users/app/views/users/_email_forward_field.html.haml | 1 | ||||
-rw-r--r-- | users/app/views/users/_form.html.haml | 8 | ||||
-rw-r--r-- | users/app/views/users/_legend_and_submit.html.haml | 10 | ||||
-rw-r--r-- | users/app/views/users/_login_field.html.haml | 1 | ||||
-rw-r--r-- | users/app/views/users/_password_fields.html.haml | 2 | ||||
-rw-r--r-- | users/app/views/users/_signup.html.haml | 2 | ||||
-rw-r--r-- | users/app/views/users/edit.html.haml | 17 | ||||
-rw-r--r-- | users/app/views/users/new.html.haml | 2 |
11 files changed, 55 insertions, 10 deletions
diff --git a/users/app/helpers/users_helper.rb b/users/app/helpers/users_helper.rb index 2310a24..dec8904 100644 --- a/users/app/helpers/users_helper.rb +++ b/users/app/helpers/users_helper.rb @@ -1,2 +1,22 @@ module UsersHelper + + def user_form_with(partial, legend, locals) + user_form do |f| + locals.reverse_merge! :legend => legend, :f => f + render :partial => partial, + :layout => 'legend_and_submit', + :locals => locals + end + end + + def user_form + html_class = 'form-horizontal user form ' + html_class += (@user.new_record? ? 'new' : 'edit') + simple_form_for @user, + :validate => true, + :format => :json, + :html => {:class => html_class} do |f| + yield f + end + end end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 325c981..ae271ce 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -2,6 +2,7 @@ class User < CouchRest::Model::Base property :login, String, :accessible => true property :email, String, :accessible => true + property :email_forward, String, :accessible => true property :password_verifier, String, :accessible => true property :password_salt, String, :accessible => true diff --git a/users/app/views/users/_email_field.html.haml b/users/app/views/users/_email_field.html.haml new file mode 100644 index 0000000..36bbeca --- /dev/null +++ b/users/app/views/users/_email_field.html.haml @@ -0,0 +1 @@ += f.input :email diff --git a/users/app/views/users/_email_forward_field.html.haml b/users/app/views/users/_email_forward_field.html.haml new file mode 100644 index 0000000..049428f --- /dev/null +++ b/users/app/views/users/_email_forward_field.html.haml @@ -0,0 +1 @@ += f.input :email_forward diff --git a/users/app/views/users/_form.html.haml b/users/app/views/users/_form.html.haml index 39e26a6..cb51175 100644 --- a/users/app/views/users/_form.html.haml +++ b/users/app/views/users/_form.html.haml @@ -3,13 +3,9 @@ = simple_form_for @user, :validate => true, :format => :json, :html => html do |f| %legend = t(only || :signup_message) - - if !only || only == :change_login - = f.input :login, :input_html => { :id => :srp_username } - - if !only || only == :change_password - = f.input :password, :required => true, :validate => true, :input_html => { :id => :srp_password } - = f.input :password_confirmation, :required => true, :input_html => { :id => :srp_password_confirmation } + = yield .pull-right - = f.button :submit, :class => 'btn-primary' + = f.button :submit - unless only = link_to t(:cancel), root_url, :class => :btn .clearfix diff --git a/users/app/views/users/_legend_and_submit.html.haml b/users/app/views/users/_legend_and_submit.html.haml new file mode 100644 index 0000000..cc172e9 --- /dev/null +++ b/users/app/views/users/_legend_and_submit.html.haml @@ -0,0 +1,10 @@ +%legend + = t(legend) += yield +.pull-right + - if local_assigns[:with_cancel] + = f.button :submit, :class => 'btn-primary' + = link_to t(:cancel), root_url, :class => :btn + - else + = f.button :submit +.clearfix diff --git a/users/app/views/users/_login_field.html.haml b/users/app/views/users/_login_field.html.haml new file mode 100644 index 0000000..8ab36c3 --- /dev/null +++ b/users/app/views/users/_login_field.html.haml @@ -0,0 +1 @@ += f.input :login, :input_html => { :id => :srp_username } diff --git a/users/app/views/users/_password_fields.html.haml b/users/app/views/users/_password_fields.html.haml new file mode 100644 index 0000000..c2e6a69 --- /dev/null +++ b/users/app/views/users/_password_fields.html.haml @@ -0,0 +1,2 @@ += f.input :password, :required => true, :validate => true, :input_html => { :id => :srp_password } += f.input :password_confirmation, :required => true, :input_html => { :id => :srp_password_confirmation } diff --git a/users/app/views/users/_signup.html.haml b/users/app/views/users/_signup.html.haml new file mode 100644 index 0000000..51bfaef --- /dev/null +++ b/users/app/views/users/_signup.html.haml @@ -0,0 +1,2 @@ += render :partial => 'login_field', :locals => local_assigns += render :partial => 'password_fields', :locals => local_assigns diff --git a/users/app/views/users/edit.html.haml b/users/app/views/users/edit.html.haml index 25da71a..4192959 100644 --- a/users/app/views/users/edit.html.haml +++ b/users/app/views/users/edit.html.haml @@ -1,5 +1,16 @@ .span8.offset2 %h2=t :settings - = render :partial => 'form', :locals => {:only => :change_login} - = render :partial => 'form', :locals => {:only => :change_password} - = render 'cancel_account' if @user == current_user + %ul.nav.nav-tabs + %li.active + %a{:href => '#account', 'data-toggle' => 'tab'}Account + %li + %a{:href => '#email', 'data-toggle' => 'tab'}Email + + .tab-content + .tab-pane.active#account + = user_form_with 'login_field', :change_login + = user_form_with 'password_fields', :change_password + = render 'cancel_account' if @user == current_user + .tab-pane#email + = user_form_with 'email_field', :set_email_address + = user_form_with 'email_forward_field', :forward_email diff --git a/users/app/views/users/new.html.haml b/users/app/views/users/new.html.haml index c1c4208..81588b1 100644 --- a/users/app/views/users/new.html.haml +++ b/users/app/views/users/new.html.haml @@ -1,3 +1,3 @@ .span8.offset2 %h2=t :signup - = render 'form' + = user_form_with 'signup', :signup_message, :with_cancel => true |