# GET /roles/apply_template_form?criteria
def apply_template_form
@permission_templates = Internal.permission_templates.selectAllPermissionTemplates().sort_by {|t| t.name.downcase}.collect {|pt| [pt.name, pt.key]}
+ @names = params[:names]
+ @keys = params[:keys]
+ @qualifiers = params[:qualifiers] || 'TRK'
+ @results_count = params[:results_count].to_i || 0
- params['qualifiers'] ||= 'TRK'
- params['pageSize'] = -1
-
- query_result = Internal.component_api.find(params)
- components = query_result.components().to_a
-
- @projects_ids = components.collect{|component| component.getId()}
- @qualifier = params[:qualifiers]
-
- render :partial => 'apply_template_form',
- :locals => {:project_name => components.size == 1 ? components[0].name : nil,
- :empty => @projects_ids.nil? || @projects_ids.size == 0}
+ render :partial => 'apply_template_form'
end
# POST /roles/apply_template?criteria
def apply_template
verify_post_request
require_parameters :template_key
+
+ params['pageSize'] = -1
+ components = Internal.component_api.find(params).components().to_a
+
+ params['components'] = components.collect{|component| component.getId()}.join(',')
Internal.permissions.applyPermissionTemplate(params)
+
redirect_to :action => 'projects'
end
<form id="apply-template-form" method="post" action="<%= ApplicationController.root_context -%>/roles/apply_template">
- <% unless empty %>
- <input type="hidden" name="components" id="apply-template-components" value="<%= @projects_ids.join(',') %>"/>
+ <% unless @results_count == 0 %>
+ <input type="hidden" name="names" id="apply-template-names" value="<%= @names %>"/>
+ <input type="hidden" name="keys" id="apply-template-keys" value="<%= @keys %>"/>
+ <input type="hidden" name="qualifiers" id="apply-template-qualifiers" value="<%= @qualifiers %>"/>
<% end %>
<fieldset>
<div class="modal-head">
- <% if project_name %>
- <h2><%= message('projects_role.apply_template_to_xxx', :params => project_name) -%></h2>
+ <% if @results_count == 1 %>
+ <h2><%= message('projects_role.apply_template_to_xxx', :params => @names) -%></h2>
<% else %>
<h2><%= message('projects_role.apply_template') -%></h2>
<% end %>
</div>
<div class="modal-body">
<div class="modal-error"/>
- <% if empty %>
+ <% if @results_count == 0 %>
<div class="info">
<img src="<%= ApplicationController.root_context -%>/images/information.png" style="vertical-align: text-bottom"/>
<%= message 'projects_role.no_projects' -%>
<div class="modal-field">
<%= label_tag 'template_key', 'Permission Template' %>
<%= select_tag('template_key', options_for_select(@permission_templates, -1), :style => 'width: 250px;') %>
- <% unless project_name %>
- <span style="float:right" class="note">(<%= "#{@projects_ids.size} #{message('qualifier.' + @qualifier)}s" %>)</span><br/>
+ <% unless @results_count == 1 %>
+ <span style="float:right" class="note">(<%= "#{@results_count} #{message('qualifier.' + @qualifiers)}s" %>)</span><br/>
<% end %>
</div>
<% end %>
</div>
<div class="modal-foot">
- <% unless empty %>
+ <% unless @results_count == 0 %>
<span id="apply-template-loading-image" class="loading-image hidden"><%= image_tag 'loading.gif' %></span>
<input type="submit" value="<%= message('apply') -%>" id="apply-template-submit" class="apply-template" onclick="return displayLoadingImage()" />
<% end %>
<ul class="operations">
<li class="last">
<%= link_to message('projects_role.bulk_change'), {:action => :apply_template_form, :names => @components_names,
- :keys => @components_keys, :qualifiers => @components_qualifiers},
+ :keys => @components_keys, :qualifiers => @components_qualifiers,
+ :results_count => @query_result.paging.total},
:id => 'apply-template-modal', :class => 'open-modal link-action' %>
</li>
</ul>
</td>
<% end %>
<td align="right">
- <%= link_to message('projects_role.apply_template'), {:action => :apply_template_form, :names => project.name},
+ <%= link_to message('projects_role.apply_template'), {:action => :apply_template_form, :names => project.name, :results_count => 1},
:id => "apply-template-#{u project.kee}", :class => 'open-modal link-action' %>
</td>
</tr>