contestnotification_edit function
This commit is contained in:
parent
8618b73a8c
commit
362570e34b
|
@ -4,8 +4,8 @@ class ContestnotificationsController < ApplicationController
|
||||||
layout 'base_newcontest'
|
layout 'base_newcontest'
|
||||||
default_search_scope :contestnotifications
|
default_search_scope :contestnotifications
|
||||||
model_object Contestnotification
|
model_object Contestnotification
|
||||||
before_filter :find_model_object, :except => [:new, :create, :index]
|
# before_filter :find_model_object, :except => [:new, :create, :index]
|
||||||
before_filter :find_contest_from_association, :except => [:new, :create, :index]
|
# before_filter :find_contest_from_association, :except => [:new, :create, :index]
|
||||||
before_filter :find_contest_by_contest_id, :only => [:new, :create]
|
before_filter :find_contest_by_contest_id, :only => [:new, :create]
|
||||||
before_filter :find_contest
|
before_filter :find_contest
|
||||||
before_filter :find_author
|
before_filter :find_author
|
||||||
|
@ -14,6 +14,8 @@ class ContestnotificationsController < ApplicationController
|
||||||
accept_rss_auth :index
|
accept_rss_auth :index
|
||||||
accept_api_auth :index
|
accept_api_auth :index
|
||||||
|
|
||||||
|
before_filter :access_edit_destroy, only: [:edit ,:update, :destroy]
|
||||||
|
|
||||||
def find_author
|
def find_author
|
||||||
@user = @contest.author
|
@user = @contest.author
|
||||||
render_404 if @user.nil?
|
render_404 if @user.nil?
|
||||||
|
@ -93,7 +95,7 @@ class ContestnotificationsController < ApplicationController
|
||||||
|
|
||||||
# GET /contestnotifications/1/edit
|
# GET /contestnotifications/1/edit
|
||||||
def edit
|
def edit
|
||||||
# @contestnotification = Contestnotification.find(params[:id])
|
@contestnotification = Contestnotification.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /contestnotifications
|
# POST /contestnotifications
|
||||||
|
@ -137,12 +139,13 @@ class ContestnotificationsController < ApplicationController
|
||||||
# format.json { render json: @contestnotification.errors, status: :unprocessable_entity }
|
# format.json { render json: @contestnotification.errors, status: :unprocessable_entity }
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
@contestnotification = Contestnotification.find(params[:id])
|
||||||
@contestnotification.safe_attributes = params[:contestnotification]
|
@contestnotification.safe_attributes = params[:contestnotification]
|
||||||
@contestnotification.save_attachments(params[:attachments])
|
@contestnotification.save_attachments(params[:attachments])
|
||||||
if @contestnotification.save
|
if @contestnotification.save
|
||||||
render_attachment_warning_if_needed(@contestnotification)
|
render_attachment_warning_if_needed(@contestnotification)
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to contest_contestnotification_path(@contestnotification)
|
redirect_to contest_contestnotification_path(@contestnotification.contest, @contestnotification)
|
||||||
else
|
else
|
||||||
render :action => 'edit'
|
render :action => 'edit'
|
||||||
end
|
end
|
||||||
|
@ -172,4 +175,12 @@ class ContestnotificationsController < ApplicationController
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def access_edit_destroy
|
||||||
|
if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
render_403
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class PreviewsController < ApplicationController
|
class PreviewsController < ApplicationController
|
||||||
before_filter :find_project, :find_attachments, :find_contest
|
before_filter :find_project, :find_attachments, :find_contest, except: [:contestnotification]
|
||||||
|
|
||||||
def issue
|
def issue
|
||||||
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
|
@issue = @project.issues.find_by_id(params[:id]) unless params[:id].blank?
|
||||||
|
@ -42,6 +42,12 @@ class PreviewsController < ApplicationController
|
||||||
render :partial => 'common/preview'
|
render :partial => 'common/preview'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def contestnotification
|
||||||
|
@previewed = Contestnotification.find(params[:id])
|
||||||
|
@text = (params[:contestnotification] ? params[:contestnotification][:description] : nil)
|
||||||
|
render :partial => 'common/preview'
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def find_project
|
def find_project
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<h3><%=l(:label_news)%></h3>
|
<h3><%=l(:label_news)%></h3>
|
||||||
|
|
||||||
<%= labelled_form_for @contestnotifications, :html => { :id => 'contestnotifications-form', :multipart => true, :method => :put } do |f| %>
|
<%= labelled_form_for @contestnotification, url: contest_contestnotification_path, :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(:project_id => @contest, :id => @contestnotifications), 'contestnotifications-form' %>
|
<%= preview_link preview_contestnotifications_path(id: @contestnotification), 'contestnotifications-form' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div id="preview" class="wiki"></div>
|
<div id="preview" class="wiki"></div>
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,10 @@
|
||||||
<td colspan="2" valign="top">
|
<td colspan="2" valign="top">
|
||||||
<strong><%= link_to_user(contestnotifications.author) if contestnotifications.respond_to?(:author) %></strong><span style="margin-left: 4px;" class="font_lighter">
|
<strong><%= link_to_user(contestnotifications.author) if contestnotifications.respond_to?(:author) %></strong><span style="margin-left: 4px;" class="font_lighter">
|
||||||
<%= l(:label_project_notice) %></span><span><%= link_to h(contestnotifications.title), contest_contestnotification_path(@contest, contestnotifications) %></span>
|
<%= l(:label_project_notice) %></span><span><%= link_to h(contestnotifications.title), contest_contestnotification_path(@contest, contestnotifications) %></span>
|
||||||
<span style="float: right"><%= delete_link contest_contestnotification_path(@contest, contestnotifications) if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?) %> </span>
|
<span style="float: right">
|
||||||
|
<%= link_to l(:button_edit), edit_contest_contestnotification_path(@contest, contestnotifications) if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?) %>
|
||||||
|
<%= delete_link contest_contestnotification_path(@contest, contestnotifications) if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?) %>
|
||||||
|
</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
|
||||||
<div class="contextual">
|
<div class="contextual">
|
||||||
<%#= link_to(l(:button_edit),
|
<%= link_to(l(:button_edit),
|
||||||
edit_contest_contestnotification_path(@contest, @contestnotification),
|
edit_contest_contestnotification_path(@contest, @contestnotification),
|
||||||
:class => 'icon icon-edit',
|
:class => 'icon icon-edit',
|
||||||
:accesskey => accesskey(:edit),
|
:accesskey => accesskey(:edit),
|
||||||
:onclick => '$("#edit-contestnotifications").show(); return true;') if User.current %>
|
:onclick => '$("#edit-contestnotifications").show(); return true;') if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?)%>
|
||||||
<%= delete_link contest_contestnotification_path(@contest, @contestnotification) if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?) %>
|
<%= delete_link contest_contestnotification_path(@contest, @contestnotification) if (User.current.admin? && User.current.logged? )||(User.current == @contest.author && User.current.logged?) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -73,11 +73,11 @@ RedmineApp::Application.routes.draw do
|
||||||
#resources :contestnotifications, :only => [:index, :show, :edit, :update, :destroy]
|
#resources :contestnotifications, :only => [:index, :show, :edit, :update, :destroy]
|
||||||
# match '/contestnotifications/:id/notificationcomments', :to => 'notificationcomments#create', :via => :post
|
# match '/contestnotifications/:id/notificationcomments', :to => 'notificationcomments#create', :via => :post
|
||||||
# match '/contestnotifications/:id/notificationcomments/:notificationcomment_id', :to => 'notificationcomments#destroy', :via => :delete
|
# match '/contestnotifications/:id/notificationcomments/:notificationcomment_id', :to => 'notificationcomments#destroy', :via => :delete
|
||||||
# match '/contestnotifications/preview', :controller => 'previews', :action => 'contestnotifications', :as => 'preview_contestnotifications', :via => [:get, :post, :put]
|
match '/contestnotifications/preview', :controller => 'previews', :action => 'contestnotification', :as => 'preview_contestnotifications', :via => [:get, :post, :put]
|
||||||
## new added by linchun #新竞赛相关
|
## new added by linchun #新竞赛相关
|
||||||
resources :contests, only: [:index] do
|
resources :contests, only: [:index] do
|
||||||
resources :contestnotifications do
|
resources :contestnotifications do
|
||||||
get 'preview', on: :collection
|
# get 'preview', on: :collection
|
||||||
resources :notificationcomments
|
resources :notificationcomments
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue