From c99fe892358d9f9276a42a060e6269a509463969 Mon Sep 17 00:00:00 2001 From: nilsding Date: Wed, 14 Jan 2015 07:07:40 +0100 Subject: [PATCH] added group memberships modal --- app/models/user.rb | 6 ++++++ app/views/user/_actions.html.haml | 3 +++ .../user/_modal_group_memberships.html.haml | 16 ++++++++++++++++ app/views/user/groups.html.haml | 2 ++ app/views/user/show.html.haml | 2 ++ app/views/user/show_follow.html.haml | 2 ++ 6 files changed, 31 insertions(+) create mode 100644 app/views/user/_modal_group_memberships.html.haml diff --git a/app/models/user.rb b/app/models/user.rb index 30f8cf81..3cdeb36f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -94,6 +94,12 @@ class User < ActiveRecord::Base friends.include? target_user end + # @param group [Group] + # @return [Boolean] true if +self+ is a member of +group+ + def member_of?(group) + group_memberships.pluck(:group_id).include? group.id + end + # answers a question # @param question [Question] the question to answer # @param content [String] the answer content diff --git a/app/views/user/_actions.html.haml b/app/views/user/_actions.html.haml index 2ede6102..c00c8ed7 100644 --- a/app/views/user/_actions.html.haml +++ b/app/views/user/_actions.html.haml @@ -20,6 +20,9 @@ %a{href: '#', name: 'user-action', data: { action: :block, type: type, target: user.screen_name }} %i.fa.fa-minus-circle Block + %li + %a{href: '#', data: { target: "#modal-group-memberships", toggle: :modal }} + Manage group memberships %li %a{href: '#', data: { action: 'report-user', target: user.screen_name }} %i.fa.fa-exclamation-triangle diff --git a/app/views/user/_modal_group_memberships.html.haml b/app/views/user/_modal_group_memberships.html.haml new file mode 100644 index 00000000..6b16e64f --- /dev/null +++ b/app/views/user/_modal_group_memberships.html.haml @@ -0,0 +1,16 @@ +#modal-group-memberships.modal.fade{"aria-hidden" => "true", "aria-labelledby" => "modal-group-memberships-label", :role => "dialog", :tabindex => "-1"} + .modal-dialog + .modal-content + .modal-header + %button.close{"data-dismiss" => "modal", :type => "button"} + %span{"aria-hidden" => "true"} × + %span.sr-only Close + %h4#modal-group-memberships-label.modal-title Manage group memberships + .modal-body + - current_user.groups.each do |group| + %label + %input{type: :checkbox, name: 'gm-group-check', data: { group_name: group.name }, checked: @user.member_of?(group)} + = group.display_name + .modal-footer + %button.btn.btn-default{"data-dismiss" => "modal", :type => "button"} Cancel + %button.btn.btn-primary{name: 'gm-save', :type => "button"} Save \ No newline at end of file diff --git a/app/views/user/groups.html.haml b/app/views/user/groups.html.haml index eae13ff7..39a5999a 100644 --- a/app/views/user/groups.html.haml +++ b/app/views/user/groups.html.haml @@ -15,3 +15,5 @@ = group.display_name .visible-xs= render 'shared/links' +- if user_signed_in? + = render 'user/modal_group_memberships' \ No newline at end of file diff --git a/app/views/user/show.html.haml b/app/views/user/show.html.haml index 45cd880e..087ecc93 100644 --- a/app/views/user/show.html.haml +++ b/app/views/user/show.html.haml @@ -15,3 +15,5 @@ %button#load-more-btn.btn.btn-default{type: :button, data: { current_page: @answers.current_page }} Load more .visible-xs= render 'shared/links' +- if user_signed_in? + = render 'user/modal_group_memberships' diff --git a/app/views/user/show_follow.html.haml b/app/views/user/show_follow.html.haml index c6063b0d..54899d40 100644 --- a/app/views/user/show_follow.html.haml +++ b/app/views/user/show_follow.html.haml @@ -17,3 +17,5 @@ %button#load-more-btn.btn.btn-default{type: :button, data: { current_page: @users.current_page }} Load more .visible-xs= render 'shared/links' +- if user_signed_in? + = render 'user/modal_group_memberships' \ No newline at end of file