summaryrefslogtreecommitdiffstats
path: root/app/views
diff options
context:
space:
mode:
Diffstat (limited to 'app/views')
-rw-r--r--app/views/groups/_memberships.html.erb66
-rw-r--r--app/views/principal_memberships/_index.html.erb52
-rw-r--r--app/views/principal_memberships/_new_form.html.erb22
-rw-r--r--app/views/principal_memberships/_new_modal.html.erb9
-rw-r--r--app/views/principal_memberships/create.js.erb12
-rw-r--r--app/views/principal_memberships/destroy.js.erb1
-rw-r--r--app/views/principal_memberships/new.html.erb6
-rw-r--r--app/views/principal_memberships/new.js.erb13
-rw-r--r--app/views/principal_memberships/update.js.erb6
-rw-r--r--app/views/users/_memberships.html.erb69
10 files changed, 123 insertions, 133 deletions
diff --git a/app/views/groups/_memberships.html.erb b/app/views/groups/_memberships.html.erb
index ec275c594..1242bf6e8 100644
--- a/app/views/groups/_memberships.html.erb
+++ b/app/views/groups/_memberships.html.erb
@@ -1,65 +1 @@
-<% roles = Role.find_all_givable %>
-<% projects = Project.active.to_a %>
-
-<div class="splitcontentleft">
-<% if @group.memberships.any? %>
-<table class="list memberships">
- <thead><tr>
- <th><%= l(:label_project) %></th>
- <th><%= l(:label_role_plural) %></th>
- <th style="width:15%"></th>
- </tr></thead>
- <tbody>
- <% @group.memberships.each do |membership| %>
- <% next if membership.new_record? %>
- <tr id="member-<%= membership.id %>" class="<%= cycle 'odd', 'even' %> class">
- <td class="project"><%= link_to_project membership.project %></td>
- <td class="roles">
- <span id="member-<%= membership.id %>-roles"><%=h membership.roles.sort.collect(&:to_s).join(', ') %></span>
- <%= form_for(:membership, :remote => true,
- :url => { :action => 'edit_membership', :id => @group, :membership_id => membership },
- :html => { :id => "member-#{membership.id}-roles-form", :style => 'display:none;'}) do %>
- <p><% roles.each do |role| %>
- <label><%= check_box_tag 'membership[role_ids][]', role.id, membership.roles.include?(role), :id => nil %> <%=h role %></label><br />
- <% end %></p>
- <p><%= submit_tag l(:button_change) %>
- <%= link_to_function(
- l(:button_cancel),
- "$('#member-#{membership.id}-roles').show(); $('#member-#{membership.id}-roles-form').hide(); return false;"
- ) %></p>
- <% end %>
- </td>
- <td class="buttons">
- <%= link_to_function(
- l(:button_edit),
- "$('#member-#{membership.id}-roles').hide(); $('#member-#{membership.id}-roles-form').show(); return false;",
- :class => 'icon icon-edit'
- ) %>
- <%= delete_link({:controller => 'groups', :action => 'destroy_membership', :id => @group, :membership_id => membership},
- :remote => true,
- :method => :post) %>
- </td>
- </tr>
-<% end; reset_cycle %>
- </tbody>
-</table>
-<% else %>
-<p class="nodata"><%= l(:label_no_data) %></p>
-<% end %>
-</div>
-
-<div class="splitcontentright">
-<% if projects.any? %>
-<fieldset><legend><%=l(:label_project_new)%></legend>
-<%= form_for(:membership, :remote => true, :url => { :action => 'edit_membership', :id => @group }) do %>
-<%= label_tag "membership_project_id", l(:description_choose_project), :class => "hidden-for-sighted" %>
-<%= select_tag 'membership[project_id]', options_for_membership_project_select(@group, projects) %>
-<p><%= l(:label_role_plural) %>:
-<% roles.each do |role| %>
- <label><%= check_box_tag 'membership[role_ids][]', role.id, false, :id => nil %> <%=h role %></label>
-<% end %></p>
-<p><%= submit_tag l(:button_add) %></p>
-<% end %>
-</fieldset>
-<% end %>
-</div>
+<%= render_principal_memberships @group %>
diff --git a/app/views/principal_memberships/_index.html.erb b/app/views/principal_memberships/_index.html.erb
new file mode 100644
index 000000000..8203999ad
--- /dev/null
+++ b/app/views/principal_memberships/_index.html.erb
@@ -0,0 +1,52 @@
+<% roles = Role.find_all_givable %>
+
+<p><%= link_to l(:label_add_projects), new_principal_membership_path(principal), :remote => true, :class => "icon icon-add" %></p>
+
+<% if principal.memberships.any? %>
+<table class="list memberships">
+ <thead><tr>
+ <th><%= l(:label_project) %></th>
+ <th><%= l(:label_role_plural) %></th>
+ <th style="width:15%"></th>
+ <%= call_table_header_hook principal %>
+ </tr></thead>
+ <tbody>
+ <% principal.memberships.preload(:member_roles => :role).each do |membership| %>
+ <% next if membership.new_record? %>
+ <tr id="member-<%= membership.id %>" class="<%= cycle 'odd', 'even' %> class">
+ <td class="project name">
+ <%= link_to_project membership.project %>
+ </td>
+ <td class="roles">
+ <span id="member-<%= membership.id %>-roles"><%=h membership.roles.sort.collect(&:to_s).join(', ') %></span>
+ <%= form_for(:membership, :remote => true,
+ :url => principal_membership_path(principal, membership), :method => :put,
+ :html => {:id => "member-#{membership.id}-roles-form",
+ :style => 'display:none;'}) do %>
+ <p><% roles.each do |role| %>
+ <label><%= check_box_tag 'membership[role_ids][]', role.id, membership.roles.include?(role),
+ :disabled => membership.member_roles.detect {|mr| mr.role_id == role.id && !mr.inherited_from.nil?},
+ :id => nil %> <%=h role %></label><br />
+ <% end %></p>
+ <%= hidden_field_tag 'membership[role_ids][]', '' %>
+ <p><%= submit_tag l(:button_change) %>
+ <%= link_to_function l(:button_cancel),
+ "$('#member-#{membership.id}-roles').show(); $('#member-#{membership.id}-roles-form').hide(); return false;"
+ %></p>
+ <% end %>
+ </td>
+ <td class="buttons">
+ <%= link_to_function l(:button_edit),
+ "$('#member-#{membership.id}-roles').hide(); $('#member-#{membership.id}-roles-form').show(); return false;",
+ :class => 'icon icon-edit'
+ %>
+ <%= delete_link principal_membership_path(principal, membership), :remote => true if membership.deletable? %>
+ </td>
+ <%= call_table_row_hook principal, membership %>
+ </tr>
+ <% end; reset_cycle %>
+ </tbody>
+</table>
+<% else %>
+<p class="nodata"><%= l(:label_no_data) %></p>
+<% end %>
diff --git a/app/views/principal_memberships/_new_form.html.erb b/app/views/principal_memberships/_new_form.html.erb
new file mode 100644
index 000000000..bdd7df64c
--- /dev/null
+++ b/app/views/principal_memberships/_new_form.html.erb
@@ -0,0 +1,22 @@
+<fieldset class="box">
+ <legend><%= l(:label_project_plural) %></legend>
+ <div style="max-height:300px; overflow:auto;">
+ <div class="projects-selection">
+ <%= render_project_nested_lists(@projects) do |p| %>
+ <label>
+ <%= check_box_tag('membership[project_ids][]', p.id, false, :id => nil, :disabled => @principal.member_of?(p)) %> <%= p %>
+ </label>
+ <% end %>
+ </div>
+ </div>
+</fieldset>
+
+<fieldset class="box">
+ <legend><%= l(:label_role_plural) %></legend>
+ <% @roles.each do |role| %>
+ <label class="inline">
+ <%= check_box_tag 'membership[role_ids][]', role.id, false, :id => nil %>
+ <%=h role %>
+ </label>
+ <% end %>
+</fieldset>
diff --git a/app/views/principal_memberships/_new_modal.html.erb b/app/views/principal_memberships/_new_modal.html.erb
new file mode 100644
index 000000000..175e09330
--- /dev/null
+++ b/app/views/principal_memberships/_new_modal.html.erb
@@ -0,0 +1,9 @@
+<h3 class="title"><%= l(:label_add_projects) %></h3>
+
+<%= form_for :membership, :remote => true, :url => user_memberships_path(@principal), :method => :post do |f| %>
+ <%= render :partial => 'new_form' %>
+ <p class="buttons">
+ <%= submit_tag l(:button_add), :name => nil %>
+ <%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %>
+ </p>
+<% end %>
diff --git a/app/views/principal_memberships/create.js.erb b/app/views/principal_memberships/create.js.erb
new file mode 100644
index 000000000..17d7ee14d
--- /dev/null
+++ b/app/views/principal_memberships/create.js.erb
@@ -0,0 +1,12 @@
+$('#tab-content-memberships').html('<%= escape_javascript(render :partial => 'principal_memberships/index', :locals => {:principal => @principal}) %>');
+hideOnLoad();
+
+<% if @members.present? && @members.all? {|m| m.persisted? } %>
+ hideModal();
+ <% @members.each do |member| %>
+ $("#member-<%= member.id %>").effect("highlight");
+ <% end %>
+<% elsif @members.present? %>
+ <% errors = @members.collect {|m| m.errors.full_messages}.flatten.uniq.join(', ') %>
+ alert('<%= raw(escape_javascript(l(:notice_failed_to_save_members, :errors => errors))) %>');
+<% end %>
diff --git a/app/views/principal_memberships/destroy.js.erb b/app/views/principal_memberships/destroy.js.erb
new file mode 100644
index 000000000..c8564f459
--- /dev/null
+++ b/app/views/principal_memberships/destroy.js.erb
@@ -0,0 +1 @@
+$('#tab-content-memberships').html('<%= escape_javascript(render :partial => 'principal_memberships/index', :locals => {:principal => @principal}) %>');
diff --git a/app/views/principal_memberships/new.html.erb b/app/views/principal_memberships/new.html.erb
new file mode 100644
index 000000000..64d2ebe21
--- /dev/null
+++ b/app/views/principal_memberships/new.html.erb
@@ -0,0 +1,6 @@
+<h2><%= l(:label_add_projects) %></h2>
+
+<%= form_for :membership, :url => user_memberships_path(@principal), :method => :post do |f| %>
+ <%= render :partial => 'new_form' %>
+ <p><%= submit_tag l(:button_add), :name => nil %></p>
+<% end %>
diff --git a/app/views/principal_memberships/new.js.erb b/app/views/principal_memberships/new.js.erb
new file mode 100644
index 000000000..625eeaf68
--- /dev/null
+++ b/app/views/principal_memberships/new.js.erb
@@ -0,0 +1,13 @@
+$('#ajax-modal').html('<%= escape_javascript(render :partial => 'principal_memberships/new_modal') %>');
+showModal('ajax-modal', '700px');
+
+$('.projects-selection').on('click', 'input[type=checkbox]', function(e){
+ if (!$(this).is(':checked')) {
+ if ($(this).closest('li').find('ul input[type=checkbox]:not(:checked)').length > 0) {
+ $(this).closest('li').find('ul input[type=checkbox]:not(:checked)').attr('checked', 'checked');
+ e.preventDefault();
+ } else {
+ $(this).closest('li').find('ul input[type=checkbox]:checked').removeAttr('checked');
+ }
+ }
+});
diff --git a/app/views/principal_memberships/update.js.erb b/app/views/principal_memberships/update.js.erb
new file mode 100644
index 000000000..2986c4e55
--- /dev/null
+++ b/app/views/principal_memberships/update.js.erb
@@ -0,0 +1,6 @@
+<% if @membership.valid? %>
+ $('#tab-content-memberships').html('<%= escape_javascript(render :partial => 'principal_memberships/index', :locals => {:principal => @principal}) %>');
+ $("#member-<%= @membership.id %>").effect("highlight");
+<% else %>
+ alert('<%= raw(escape_javascript(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))) %>');
+<% end %>
diff --git a/app/views/users/_memberships.html.erb b/app/views/users/_memberships.html.erb
index cd4201727..75871d63e 100644
--- a/app/views/users/_memberships.html.erb
+++ b/app/views/users/_memberships.html.erb
@@ -1,68 +1 @@
-<% roles = Role.find_all_givable %>
-<% projects = Project.active.to_a %>
-
-<div class="splitcontentleft">
-<% if @user.memberships.any? %>
-<table class="list memberships">
- <thead><tr>
- <th><%= l(:label_project) %></th>
- <th><%= l(:label_role_plural) %></th>
- <th style="width:15%"></th>
- <%= call_hook(:view_users_memberships_table_header, :user => @user )%>
- </tr></thead>
- <tbody>
- <% @user.memberships.each do |membership| %>
- <% next if membership.new_record? %>
- <tr id="member-<%= membership.id %>" class="<%= cycle 'odd', 'even' %> class">
- <td class="project">
- <%= link_to_project membership.project %>
- </td>
- <td class="roles">
- <span id="member-<%= membership.id %>-roles"><%=h membership.roles.sort.collect(&:to_s).join(', ') %></span>
- <%= form_for(:membership, :remote => true,
- :url => user_membership_path(@user, membership), :method => :put,
- :html => {:id => "member-#{membership.id}-roles-form",
- :style => 'display:none;'}) do %>
- <p><% roles.each do |role| %>
- <label><%= check_box_tag 'membership[role_ids][]', role.id, membership.roles.include?(role),
- :disabled => membership.member_roles.detect {|mr| mr.role_id == role.id && !mr.inherited_from.nil?},
- :id => nil %> <%=h role %></label><br />
- <% end %></p>
- <%= hidden_field_tag 'membership[role_ids][]', '' %>
- <p><%= submit_tag l(:button_change) %>
- <%= link_to_function l(:button_cancel),
- "$('#member-#{membership.id}-roles').show(); $('#member-#{membership.id}-roles-form').hide(); return false;"
- %></p>
- <% end %>
- </td>
- <td class="buttons">
- <%= link_to_function l(:button_edit),
- "$('#member-#{membership.id}-roles').hide(); $('#member-#{membership.id}-roles-form').show(); return false;",
- :class => 'icon icon-edit'
- %>
- <%= delete_link user_membership_path(@user, membership), :remote => true if membership.deletable? %>
- </td>
- <%= call_hook(:view_users_memberships_table_row, :user => @user, :membership => membership, :roles => roles, :projects => projects )%>
- </tr>
- <% end; reset_cycle %>
- </tbody>
-</table>
-<% else %>
-<p class="nodata"><%= l(:label_no_data) %></p>
-<% end %>
-</div>
-
-<div class="splitcontentright">
-<% if projects.any? %>
-<fieldset><legend><%=l(:label_project_new)%></legend>
-<%= form_for(:membership, :remote => true, :url => user_memberships_path(@user)) do %>
-<%= select_tag 'membership[project_id]', options_for_membership_project_select(@user, projects) %>
-<p><%= l(:label_role_plural) %>:
-<% roles.each do |role| %>
- <label><%= check_box_tag 'membership[role_ids][]', role.id, false, :id => nil %> <%=h role %></label>
-<% end %></p>
-<p><%= submit_tag l(:button_add) %></p>
-<% end %>
-</fieldset>
-<% end %>
-</div>
+<%= render_principal_memberships @user %>