rework users page, add role assignment

This commit is contained in:
Stella Rouzi 2014-07-20 19:40:16 +03:00
parent 9998e00ae3
commit 80d48ed7d8
13 changed files with 118 additions and 72 deletions

View file

@ -0,0 +1,11 @@
= semantic_form_for(user, url: add_role_admin_user_path(user), remote: true) do |f|
.pull-left
= f.action :submit, as: :button, label: 'Add Role', button_html: {value: 'Save', class: 'btn btn-success'}
%br
%br
= f.fields_for :roles, Role.new do |role|
= role.input :name, label: 'Select role', collection: Role::LABELS
= role.label 'Select Conference'
%br
= role.input :resource, label: false, collection: Conference.all.map { |c| [c.short_title, c.id] }
%br

View file

@ -1,8 +1,13 @@
= semantic_form_for [:admin, @user] do |f|
= f.inputs "Basic Information" do
= f.inputs 'Basic Information' do
= f.input :name, :as => :string
= f.input :email
= f.input :affiliation, :as => :string
= f.input :biography, :input_html => {:rows => 10}
= f.actions do
= f.action :submit, :button_html => {:class => "btn btn-primary"}
= f.input :affiliation, as: :string
= f.input :biography, input_html: { rows: 5, "onkeyup" => "word_count(this, 'biography-count', 150)" }
You have used
%span#biography-count #{@user.biography_word_count}
words. Biographies are limited to 150 words.
%br
%br
= f.actions do
= f.action :submit, button_html: { class: 'btn btn-primary' }

View file

@ -1,12 +0,0 @@
- if current_user == user
You cannot modify your own role!
%br
%button{:class=> "btn btn-danger", "data-dismiss"=> "modal", "aria-hidden"=>"true"}
Cancel
- else
= "Give #{user.name} (#{user.email}) the following roles:"
= semantic_form_for(user, :url => admin_user_path(user), :method => :put) do |f|
= f.input :roles, :label => false, collection: @roles
%button{:class=> "btn btn-danger", "data-dismiss"=> "modal", "aria-hidden"=>"true"}
Cancel
= f.action :submit, :as => :button, :button_html => {:value => "Save", :class => "btn btn-primary"}

View file

@ -0,0 +1,10 @@
- user ||= @user
.roles{ id: 'current_roles' }
= semantic_form_for(user, url: admin_user_path(user)) do |f|
= f.action :submit, as: :button, label: 'Update Roles', button_html: {value: 'Save', class: 'btn btn-primary'}
= f.inputs "Roles for #{@user.name}" do
- user.roles.each do |role|
%br
= hidden_field_tag "user[role_ids][]", nil
= check_box_tag "user[role_ids][]", role.id, user.roles.include?(role), id: dom_id(role)
= label_tag dom_id(role), "#{ role.name.capitalize } for #{ role.resource_type.constantize.find(role.resource_id).short_title }"

View file

@ -0,0 +1 @@
$('#current_roles').html("<%= escape_javascript(render partial: 'user_roles').html_safe %>");

View file

@ -0,0 +1,19 @@
.row
.col-md-12
.tabbable
%ul.nav.nav-tabs
%li.active
= link_to 'User', '#user-content', 'data-toggle'=>'tab'
%li= link_to 'Roles', '#roles-content', 'data-toggle'=>'tab'
.tab-content
#user-content.tab-pane.active
= render partial: 'form'
#roles-content.tab-pane
.row
.col-md-6
%br
= render partial: 'user_roles', locals: { user: @user }
.col-md-6
%br
= render partial: 'add_roles', locals: { user: @user }

View file

@ -40,26 +40,17 @@
%td
= user.registrations.count
%td
.modal.fade{:id => "user-role-selection-#{user.id}", "role" => "dialog", "aria-hidden" => "true"}
.modal-dialog
.modal-content
.modal-header
%button{"type"=>"button", :class=>"close", "data-dismiss"=>"modal", "aria-hidden"=>"true"}
×
%h3{:id => "role-selector-header-#{user.id}"}
Modifying Roles
.modal-body
= render partial: 'roles', locals: { user: user }
- if can? :update, Role
=link_to "#{user.roles.map { |role| role.name }.join ', '}", "#", "data-toggle" => "modal", "data-target" => "#user-role-selection-#{user.id}",id: "user-modify-role-#{user.id}"
= link_to "#{ user.roles.present? ? (user.roles.map { |role| "#{ role.name.titleize }(#{ role.resource_type.constantize.find(role.resource_id).short_title })" }.join ', ') : 'Add Role'}", "#", "data-toggle" => "modal", "data-target" => "#user-role-selection-#{user.id}",id: "user-modify-role-#{user.id}"
- else
= user.roles.map { |role| role.name }.join ', '
- if can? :update, user
%td
= link_to "Edit", edit_admin_user_path(user)
= user.roles.map { |role| "#{ role.name.capitalize } for #{ role.resource_type.constantize.find(role.resource_id).short_title }" }.join ', '
- if can? :show, user
%td
= link_to "View", admin_user_path(user)
= link_to "View", admin_user_path(user), class: 'btn btn-success'
- if can? :update, user
%td
= link_to "Edit", edit_admin_user_path(user), class: 'btn btn-primary'
- if can? :destroy, user
%td
- if current_user.id == user.id or user.role_ids.include? 3

View file

@ -1,7 +1,11 @@
%table.table
- @show_attributes.each do |attr|
%tr
%td
%td{style: 'width:20%'}
%b
= attr.capitalize.gsub('_', ' ')
%td= @user.send(attr)
- if attr == 'roles'
%td
= @user.send(attr).map { |role| "#{ role.name.capitalize } of #{ role.resource_type.constantize.find(role.resource_id).short_title }"}.join(', ')
- else
%td= @user.send(attr)