diff --git a/app/controllers/my_profile/profile_members_controller.rb b/app/controllers/my_profile/profile_members_controller.rb index 8f29751..0223918 100644 --- a/app/controllers/my_profile/profile_members_controller.rb +++ b/app/controllers/my_profile/profile_members_controller.rb @@ -1,5 +1,6 @@ class ProfileMembersController < MyProfileController protect 'manage_memberships', :profile + no_design_blocks def index @members = profile.members @@ -43,7 +44,7 @@ class ProfileMembersController < MyProfileController else flash[:notice] = 'Failed to unassociate member' end - redirect_to :aciton => 'index' + render :layout => false end def unassociate @@ -56,7 +57,23 @@ class ProfileMembersController < MyProfileController flash[:notice] = 'Failed to unassociate member' end end - redirect_to :action => 'index' + render :layout => false + end + + def add_members + end + + def add_member + if profile.enterprise? + member = Person.find_by_identifier(params[:id]) + member.define_roles(Profile::Roles.all_roles(environment), profile) + end + render :layout => false + end + + def find_users + @users_found = Person.find_by_contents(params[:query]) + render :layout => false end end diff --git a/app/views/profile_members/_find_users.rhtml b/app/views/profile_members/_find_users.rhtml new file mode 120000 index 0000000..aa4a9e4 --- /dev/null +++ b/app/views/profile_members/_find_users.rhtml @@ -0,0 +1 @@ +find_users.rhtml \ No newline at end of file diff --git a/app/views/profile_members/_members_list.rhtml b/app/views/profile_members/_members_list.rhtml new file mode 100644 index 0000000..06baca8 --- /dev/null +++ b/app/views/profile_members/_members_list.rhtml @@ -0,0 +1,24 @@ +

<%= _('Current Members') %>

+ + + + + + + <% profile.members.each do |m| %> + + + + + <% end %> +
<%= _('Member') %><%= _('Actions') %>
<%= link_to_profile m.short_name, m.identifier, :title => m.name %> +
+ <%= button_without_text :edit, _('Edit'), :action => 'change_role', :id => m %> + <%= button_to_remote_without_text :remove, _('Remove'), + :update => 'members-list', + :loading => '$("members-list").addClassName("loading")', + :success => "$('tr-#{m.identifier}').show()", + :complete => '$("members-list").removeClassName("loading")', + :url => {:action => 'unassociate', :id => m} %> +
+
diff --git a/app/views/profile_members/add_member.rhtml b/app/views/profile_members/add_member.rhtml new file mode 120000 index 0000000..12e1b0b --- /dev/null +++ b/app/views/profile_members/add_member.rhtml @@ -0,0 +1 @@ +_members_list.rhtml \ No newline at end of file diff --git a/app/views/profile_members/add_members.rhtml b/app/views/profile_members/add_members.rhtml new file mode 100644 index 0000000..ec84364 --- /dev/null +++ b/app/views/profile_members/add_members.rhtml @@ -0,0 +1,25 @@ +

<%= _('Add members to %s') % profile.name %>

+ +<% form_remote_tag :url => {:action => 'find_users', :profile => profile.identifier}, :update => 'users-list', :loading => '$("users-list").addClassName("loading")', :complete => '$("users-list").removeClassName("loading")' do %> + <%= text_field_tag('query') %> + <%= submit_tag(_('Search')) %> +<% end %> + +<%= observe_field('query', :url => {:action => 'find_users', :profile => profile.identifier}, :update => 'users-list', :frequency => 1, :with => 'query', :condition => '$("query").value.length > 2', :loading => '$("users-list").addClassName("loading")', :complete => '$("users-list").removeClassName("loading")') %> + +
+ <%= render :partial => 'find_users' %> +
+ +
+ <%= render :partial => 'members_list' %> +
+<%= drop_receiving_element('members-list', + :url => {:action => 'add_member', :profile => profile.identifier}, + :before => '$("tr-" + element.id).hide()', + :loading => '$("members-list").addClassName("loading")', + :update => 'members-list', + :success => '$("tr-" + element.id).hide(); $(element.id).show();', + :complete => '$("members-list").removeClassName("loading")') %> + +
diff --git a/app/views/profile_members/find_users.rhtml b/app/views/profile_members/find_users.rhtml new file mode 100644 index 0000000..01aa587 --- /dev/null +++ b/app/views/profile_members/find_users.rhtml @@ -0,0 +1,28 @@ +

<%= _('Users') %>

+ + + <% @users_found.each do |user| %> + > + + + + <% end if @users_found %> +
<%= _('Name') %>
+
+ <%= image_tag('/images/grip-clue.png') %> + <%= profile_image(user, :icon) %> + <%= [link_to_profile(user.short_name + " (#{user.identifier})", user.identifier, :title => user.name), + (user.sex ? gettext(user.sex.capitalize) : _('Sex not informed')), + user.location.empty? ? nil : user.location ].compact.join(' — ') %> +
+ <%= draggable_element(user.identifier, :revert => true) %> +
+ <%= button_to_remote_without_text(:add, _('Add member'), + { :loading => '$("members-list").addClassName("loading")', + :update => 'members-list', + :url => {:action => 'add_member', :profile => profile.identifier, :id => user.identifier}, + :success => "$('tr-#{user.identifier}').hide()", + :complete => '$("members-list").removeClassName("loading")'}) %> + + +
diff --git a/app/views/profile_members/index.rhtml b/app/views/profile_members/index.rhtml index 29c842d..e01b3bd 100644 --- a/app/views/profile_members/index.rhtml +++ b/app/views/profile_members/index.rhtml @@ -1,23 +1,8 @@ -

<%= _('Listing Members') %>

- -<%= link_to _('Affiliate yourself'), :action => 'add_role', :person => current_user.person, :role => @member_role if @member_role %> - - - - - - - <% @members.each do |m| %> - - - - - <% end %> -
<%= _('Member') %><%= _('Actions') %>
<%= m.name %> - <%= button_without_text :edit, _('Edit'), :action => 'change_role', :id => m %> - <%= button_without_text :delete, _('Remove'), :action => 'unassociate', :id => m %> -
+
+ <%= render :partial => 'members_list' %> +
<% button_bar do %> <%= button :back, _('Back'), :controller => 'profile_editor' %> + <%= button :add, _('Add members'), :action => 'add_members' if profile.enterprise? %> <% end %> diff --git a/app/views/profile_members/unassociate.rhtml b/app/views/profile_members/unassociate.rhtml new file mode 120000 index 0000000..12e1b0b --- /dev/null +++ b/app/views/profile_members/unassociate.rhtml @@ -0,0 +1 @@ +_members_list.rhtml \ No newline at end of file diff --git a/public/designs/icons/tango/style.css b/public/designs/icons/tango/style.css index 8a57295..264de25 100644 --- a/public/designs/icons/tango/style.css +++ b/public/designs/icons/tango/style.css @@ -17,6 +17,7 @@ .icon-back { background-image: url(Tango/16x16/actions/back.png) } .icon-next { background-image: url(Tango/16x16/actions/go-next.png) } .icon-add { background-image: url(Tango/16x16/actions/add.png) } +.icon-remove { background-image: url(Tango/16x16/actions/gtk-remove.png) } .icon-more { background-image: url(Tango/16x16/actions/add.png) } .icon-up { background-image: url(Tango/16x16/actions/go-up.png) } .icon-down { background-image: url(Tango/16x16/actions/go-down.png) } diff --git a/public/images/grip-clue.png b/public/images/grip-clue.png new file mode 100644 index 0000000..05daab5 Binary files /dev/null and b/public/images/grip-clue.png differ diff --git a/public/stylesheets/controller_profile_members.css b/public/stylesheets/controller_profile_members.css new file mode 100644 index 0000000..fd795df --- /dev/null +++ b/public/stylesheets/controller_profile_members.css @@ -0,0 +1,54 @@ +.no-boxes { + margin: 30px +} + +#users-list { + float: left; + width: 60%; +} + +.msie6 #users-list { + position: relative; +} + +#users-list a.icon-add{ + float: right; +} + +.msie #users-list a.icon-add{ + display: block; +} + +.draggable-user { + xwidth: 170px; + cursor: move; +} + +#members-list.add-members { + float: right; + width: 30%; + text-align: center; +} + +.members-buttons-cell { + width: 60px; +} + +.msie .members-buttons-cell a { + position: relative; + display: block; + float: left; +} + +.msie6 .button-bar a { + position: relative; +} + +.loading { + cursor: progress; + background: transparent url(../images/loading.gif) no-repeat scroll center 50px; +} + +table { + text-align: left; +} diff --git a/test/functional/profile_members_controller_test.rb b/test/functional/profile_members_controller_test.rb index d14de83..116f5c7 100644 --- a/test/functional/profile_members_controller_test.rb +++ b/test/functional/profile_members_controller_test.rb @@ -90,8 +90,8 @@ class ProfileMembersControllerTest < Test::Unit::TestCase login_as :admin_user get :unassociate, :profile => com.identifier, :id => member - assert_response :redirect - assert_redirected_to :action => 'index' + assert_response :success + assert_equal nil, @response.layout member.reload com.reload assert_not_includes com.members, member @@ -112,4 +112,100 @@ class ProfileMembersControllerTest < Test::Unit::TestCase assert_not_includes assigns(:roles), role end + should 'enterprises have a add members button' do + ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') + u = create_user_with_permission('test_user', 'manage_memberships', ent) + login_as :test_user + + get :index, :profile => ent.identifier + assert_tag :tag => 'a', :attributes => {:href => /add_members/} + end + + should 'not display add members button for communities' do + com = Community.create!(:name => 'Test Com', :identifier => 'test_com') + u = create_user_with_permission('test_user', 'manage_memberships', com) + login_as :test_user + + get :index, :profile => com.identifier + assert_no_tag :tag => 'a', :attributes => {:href => /add_members/} + end + + should 'have a add_members page' do + ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') + u = create_user_with_permission('test_user', 'manage_memberships', ent) + login_as :test_user + + assert_nothing_raised do + get :add_members, :profile => ent.identifier + end + + end + + should 'list current members when adding new members' do + ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') + p = create_user_with_permission('test_user', 'manage_memberships', ent) + login_as :test_user + + get :add_members, :profile => ent.identifier + ent.reload + assert_includes ent.members, p + end + + should 'add member to profile' do + ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') + p = create_user_with_permission('test_user', 'manage_memberships', ent) + login_as :test_user + + u = create_user('member_wannabe').person + post :add_member, :profile => ent.identifier, :id => u.identifier + ent.reload + + assert_includes ent.members, p + assert_includes ent.members, u + end + + should 'add member with all roles' do + ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') + p = create_user_with_permission('test_user', 'manage_memberships', ent) + login_as :test_user + + u = create_user('member_wannabe').person + post :add_member, :profile => ent.identifier, :id => u.identifier + + assert_equivalent Profile::Roles.all_roles(ent.environment).compact, u.role_assignments.find_all_by_resource_id(ent.id).map(&:role).compact + end + + should 'not add member to community' do + com = Community.create!(:name => 'Test Com', :identifier => 'test_com') + p = create_user_with_permission('test_user', 'manage_memberships', com) + login_as :test_user + + u = create_user('member_wannabe').person + post :add_member, :profile => com.identifier, :id => u.identifier + com.reload + + assert_not_includes com.members, u + end + + should 'find users' do + ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') + user = create_user('test_user').person + u = create_user_with_permission('ent_user', 'manage_memberships', ent) + login_as :ent_user + + get :find_users, :profile => ent.identifier, :query => 'test*' + + assert_includes assigns(:users_found), user + end + + should 'not appear add button for member in add members page' do + ent = Enterprise.create!(:name => 'Test Ent', :identifier => 'test_ent') + p = create_user_with_permission('test_user', 'manage_memberships', ent) + login_as :test_user + + get :find_users, :profile => ent.identifier, :query => 'test*' + + assert_tag :tag => 'tr', :attributes => {:id => 'tr-test_user', :style => 'display:none'} + end + end -- libgit2 0.21.2