This commit is contained in:
wanglinchun 2014-06-05 15:23:58 +08:00
parent f1555bf134
commit 0255a61d2f
3 changed files with 28 additions and 7 deletions

View File

@ -47,6 +47,10 @@ module ApplicationHelper
User.current.allowed_to?({:controller => controller, :action => action}, @project) User.current.allowed_to?({:controller => controller, :action => action}, @project)
end end
def authorize_for_contest(controller, action)
User.current.allowed_to?({:controller => controller, :action => action}, @contest)
end
# Display a link if user is authorized # Display a link if user is authorized
# #
# @param [String] name Anchor text (passed to link_to) # @param [String] name Anchor text (passed to link_to)
@ -57,6 +61,9 @@ module ApplicationHelper
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action]) link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
end end
def link_to_if_authorized_contest(name, options = {}, html_options = nil, *parameters_for_method_reference)
link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for_contest(options[:controller] || params[:controller], options[:action])
end
# Displays a link to user's account page if active # Displays a link to user's account page if active
def link_to_user(user, options={}) def link_to_user(user, options={})
if user.is_a?(User) if user.is_a?(User)

View File

@ -0,0 +1,14 @@
api.array :contestnotifications, api_meta(:total_count => @contestnotifications_count, :offset => @offset, :limit => @limit) do
@contestnotificationss.each do |contestnotifications|
api.contestnotifications do
api.id contestnotifications.id
api.contest(:id => contestnotifications.contest_id, :name => contestnotifications.contest.name) unless contestnotifications.contest.nil?
api.author(:id => contestnotifications.author_id, :name => contestnotifications.author.name) unless contestnotifications.author.nil?
api.title contestnotifications.title
api.summary contestnotifications.summary
api.description contestnotifications.description
api.created_at contestnotifications.created_at
end
end
end

View File

@ -38,23 +38,23 @@
<div class="contextual"> <div class="contextual">
<%= watcher_link(@contestnotifications, User.current) %> <%= watcher_link(@contestnotifications, User.current) %>
<%= link_to(l(:button_edit), <%= link_to(l(:button_edit),
edit_news_path(@news), edit_contest_contestnotification_path(@contestnotifications),
:class => 'icon icon-edit', :class => 'icon icon-edit',
:accesskey => accesskey(:edit), :accesskey => accesskey(:edit),
:onclick => '$("#edit-news").show(); return false;') if User.current.allowed_to?(:manage_contestnotification, @contest) %> :onclick => '$("#edit-contestnotifications").show(); return false;') if User.current.allowed_to?(:manage_contestnotifications, @contest) %>
<%= delete_link news_path(@contestnotifications) if User.current.allowed_to?(:manage_contestnotification, @contest) %> <%= delete_link contest_contestnotification_path(@contestnotifications) if User.current.allowed_to?(:manage_contestnotifications, @contest) %>
</div> </div>
<h3><strong><%=h @contestnotifications.title %></strong></h3> <h3><strong><%=h @contestnotifications.title %></strong></h3>
<% if authorize_for('contestnotifications', 'edit') %> <% if authorize_for_contest('contestnotifications', 'edit') %>
<div id="edit-news" style="display:none;"> <div id="edit-contestnotifications" style="display:none;">
<%= labelled_form_for :contestnotifications, @contestnotifications, :url => contestnotifications_path(@contestnotifications), <%= labelled_form_for :contestnotifications, @contestnotifications, :url => contest_contestnotification_path(@contestnotifications),
:html => { :id => 'contestnotifications-form', :multipart => true, :method => :put } do |f| %> :html => { :id => 'contestnotifications-form', :multipart => true, :method => :put } do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %> <%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %> <%= submit_tag l(:button_save) %>
<%= preview_link preview_contestnotifications_path(:contest_id => @contest, :id => @contestnotifications), 'contestnotifications-form',target='preview',{:class => ''} %> | <%= preview_link preview_contestnotifications_path(:contest_id => @contest, :id => @contestnotifications), 'contestnotifications-form',target='preview',{:class => ''} %> |
<%= link_to l(:button_cancel), "#", :onclick => '$("#edit-news").hide(); return false;' %> <%= link_to l(:button_cancel), "#", :onclick => '$("#edit-contestnotifications").hide(); return false;' %>
<% end %> <% end %>
<div id="preview" class="wiki"></div> <div id="preview" class="wiki"></div>
</div> </div>