Adding helper to show or hide elements based on permissions. #1138

This commit is contained in:
Eric Davis
2008-06-04 15:44:44 -07:00
parent 23c6ee6e92
commit 203ad5c90e
5 changed files with 34 additions and 7 deletions

View File

@@ -15,4 +15,8 @@ module DeliverablesHelper
content_tag(:span, label) +
h(data))
end
def allowed_management?
return User.current.allowed_to?(:manage_budget, @project)
end
end

View File

@@ -1,10 +1,10 @@
<% css = cycle('odd','even') %>
<tr id="deliverable-<%= deliverable.id %>" class="deliverable <%= css %>">
<%= content_tag(:td, deliverable.id) %>
<%= content_tag(:td, h(deliverable.score.to_i), :class => 'score') %>
<%= content_tag(:td, h(deliverable.score.to_i), :class => 'score') if allowed_management? %>
<%= content_tag(:td, h(deliverable.subject), :class => 'subject') %>
<%= content_tag(:td, number_to_currency(deliverable.budget, :precision => 0), :class => 'budget') %>
<%= content_tag(:td, number_to_currency(deliverable.spent, :precision => 0), :class => 'spent') %>
<%= content_tag(:td, number_to_currency(deliverable.spent, :precision => 0), :class => 'spent') if allowed_management? %>
<%= content_tag(:td, format_date(deliverable.due), :class => 'due_date') %>
<%= content_tag(:td, progress_bar(deliverable.progress, :width => '100%', :class => 'dont_ratio')) %>
<%= content_tag(:td, link_to_function("Details", "$('deliverable-details-#{deliverable.id}').toggle();"), :class => 'actions') %>
@@ -27,8 +27,9 @@
<td colspan="4">
<%= content_tag(:p,link_to("Assigned Issues", :action => 'issues', :id => @project.id, :deliverable_id => deliverable.id)) -%>
<%= content_tag(:p,link_to("Edit", :action => 'edit', :id => @project.id, :deliverable_id => deliverable.id)) -%>
<%= content_tag(:p,link_to("Delete", { :action => 'destroy', :id => @project.id, :deliverable_id => deliverable.id}, :confirm => l(:text_are_you_sure))) -%>
<%= content_tag(:p,link_to("Edit", :action => 'edit', :id => @project.id, :deliverable_id => deliverable.id)) if allowed_management? -%>
<%= content_tag(:p,link_to("Delete", { :action => 'destroy', :id => @project.id, :deliverable_id => deliverable.id}, :confirm => l(:text_are_you_sure))) if allowed_management? %>
<% if allowed_management? %>
<div>
<% form_for :deliverable, deliverable, :url => { :action => "bulk_assign_issues", :id => @project.id, :deliverable_id => deliverable.id} do |f| %>
@@ -37,5 +38,6 @@
<%= submit_tag(l(:button_change)) %>
<% end %>
</div>
<% end %>
</td>
</tr>

View File

@@ -1,10 +1,10 @@
<table id="deliverable-list" class="list deliverables">
<thead><tr>
<%= sort_header_tag("#{Deliverable.table_name}.id", :caption => '#', :default_order => 'desc') %>
<%= sort_header_tag("score", :caption => 'Score', :default_order => 'desc') %>
<%= sort_header_tag("score", :caption => 'Score', :default_order => 'desc') if allowed_management? %>
<%= sort_header_tag("#{Deliverable.table_name}.subject", :caption => 'Subject') %>
<%= sort_header_tag("#{Deliverable.table_name}.budget", :caption => 'Budget') %>
<%= sort_header_tag("spent", :caption => 'Spent') %>
<%= sort_header_tag("spent", :caption => 'Spent') if allowed_management? %>
<%= sort_header_tag("#{Deliverable.table_name}.due", :caption => 'Due') %>
<%= sort_header_tag("progress", :caption => 'Progress') %>
<%= content_tag('th', "Actions") %>

View File

@@ -1,3 +1,3 @@
<h3>Budget</h3>
<%= link_to l(:label_issue_view_all), { :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 } %><br />
<%= link_to_function "New Deliverable", "$('new-deliverable').toggle();" %><br />
<%= link_to_function "New Deliverable", "$('new-deliverable').toggle();" if allowed_management? %><br />

View File

@@ -1,35 +1,55 @@
<div id="budget-summary">
<h2>Budget</h1>
<% if allowed_management? %>
<p>
Project Budget: <%= h number_to_currency(@budget.budget, :precision => 0) %>
</p>
<% end %>
<% if allowed_management? %>
<p>
Budget Spent: <%= h number_to_currency(@budget.spent, :precision => 0) %>
</p>
<% end %>
<% if allowed_management? %>
<p>
Budget Remaining: <%= h number_to_currency(@budget.left, :precision => 0) %>
</p>
<% end %>
<p>
Progress: <%= h @budget.progress %>
</p>
<% if allowed_management? %>
<p>
Budget Score: <%= h @budget.score %>
</p>
<% end %>
<% if allowed_management? %>
<p>
Overruns: <%= h number_to_currency(@budget.overruns, :precision => 0) %>
</p>
<% end %>
<p>
Next Due Date: <%= h distance_of_time_in_words_to_now(@budget.next_due_date) if @budget.next_due_date %>
</p>
<p>
Completion: <%= h distance_of_time_in_words_to_now(@budget.final_due_date) if @budget.final_due_date %>
</p>
<% if allowed_management? %>
<p>
Profit: <%= h number_to_currency(@budget.profit, :precision => 0) %>
</p>
<% end %>
</div>
<% if allowed_management? %>
<div id="new-deliverable" style="display:none;">
<h2>New Deliverable</h2>
<% remote_form_for :deliverable, @deliverable, :url => {:controller => 'deliverables', :action => 'create', :id => @project },
@@ -38,6 +58,7 @@
<%= render :partial => 'form', :locals => { :mode => :create, :f => f } %>
<% end %>
</div>
<% end %>
<div id="budget-list">
<% if @deliverables.empty? %>