2014-05-30 20:32:37 +08:00
|
|
|
class ContestnotificationsController < ApplicationController
|
|
|
|
# GET /contestnotifications
|
|
|
|
# GET /contestnotifications.json
|
2014-06-03 15:27:04 +08:00
|
|
|
layout 'base_newcontest'
|
|
|
|
default_search_scope :contestnotifications
|
2014-06-03 18:24:55 +08:00
|
|
|
# model_object Contestnotifications
|
2014-06-03 21:52:16 +08:00
|
|
|
# before_filter :find_model_object_contest, :except => [:new, :create, :index]
|
2014-06-05 10:28:36 +08:00
|
|
|
before_filter :find_contest_from_association, :except => [:new, :create, :index]
|
2014-06-03 21:52:16 +08:00
|
|
|
# before_filter :find_contest_by_contest_id, :only => [:new, :create]
|
|
|
|
before_filter :find_contest
|
|
|
|
before_filter :find_author
|
|
|
|
# before_filter :authorize, :except => [:index]
|
2014-06-03 18:24:55 +08:00
|
|
|
before_filter :find_optional_contest, :only => [:index]
|
2014-05-30 20:32:37 +08:00
|
|
|
accept_rss_auth :index
|
2014-06-03 21:52:16 +08:00
|
|
|
accept_api_auth :index
|
2014-06-03 18:24:55 +08:00
|
|
|
|
2014-06-03 21:52:16 +08:00
|
|
|
def find_author
|
2014-06-03 18:24:55 +08:00
|
|
|
@user = @contest.author
|
2014-06-03 21:52:16 +08:00
|
|
|
render_404 if @user.nil?
|
|
|
|
end
|
|
|
|
def find_contest
|
|
|
|
@contest = Contest.find(params[:contest_id])
|
|
|
|
render_404 if @contest.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
2014-05-30 20:32:37 +08:00
|
|
|
# @contestnotifications = Contestnotification.all
|
2014-06-03 21:52:16 +08:00
|
|
|
#
|
2014-05-30 20:32:37 +08:00
|
|
|
# respond_to do |format|
|
2014-06-03 21:52:16 +08:00
|
|
|
# format.html # index.html.erb
|
|
|
|
# format.json { render json: @contestnotifications }
|
2014-05-30 20:32:37 +08:00
|
|
|
# end
|
2014-06-03 21:52:16 +08:00
|
|
|
|
2014-05-30 20:32:37 +08:00
|
|
|
### begin ###
|
|
|
|
case params[:format]
|
2014-06-03 21:52:16 +08:00
|
|
|
when 'xml', 'json'
|
|
|
|
@offset, @limit = api_offset_and_limit
|
|
|
|
else
|
|
|
|
@limit = 10
|
2014-05-30 20:32:37 +08:00
|
|
|
end
|
|
|
|
|
2014-06-04 20:29:15 +08:00
|
|
|
scope = @contest ? @contest.contestnotifications.visible : Contestnotifications.visible
|
2014-05-30 20:32:37 +08:00
|
|
|
|
2014-06-03 15:27:04 +08:00
|
|
|
@contestnotifications_count = scope.count
|
|
|
|
@contestnotifications_pages = Paginator.new @contestnotifications_count, @limit, params['page']
|
|
|
|
@offset ||= @contestnotifications_pages.offset
|
2014-06-03 09:27:07 +08:00
|
|
|
@contestnotificationss = scope.all(:include => [:author, :contest],
|
2014-06-03 18:24:55 +08:00
|
|
|
:order => "#{Contestnotification.table_name}.created_at DESC",
|
2014-05-30 20:32:37 +08:00
|
|
|
:offset => @offset,
|
2014-06-03 21:52:16 +08:00
|
|
|
:limit => @limit)
|
|
|
|
|
2014-05-30 20:32:37 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
2014-06-03 15:27:04 +08:00
|
|
|
@contestnotification = Contestnotification.new # for adding news inline
|
|
|
|
render :layout => 'base_newcontest'
|
2014-05-30 20:32:37 +08:00
|
|
|
}
|
|
|
|
format.api
|
2014-06-03 09:27:07 +08:00
|
|
|
format.atom { render_feed(@contestnotificationss, :title => (@contest ? @contest.name : Setting.app_title) + ": #{l(:label_contest_notification)}") }
|
2014-05-30 20:32:37 +08:00
|
|
|
end
|
2014-06-03 21:52:16 +08:00
|
|
|
### end ###
|
2014-05-30 20:32:37 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# GET /contestnotifications/1
|
|
|
|
# GET /contestnotifications/1.json
|
|
|
|
def show
|
2014-06-05 16:27:33 +08:00
|
|
|
# @contestnotification = Contestnotification.find(params[:id])
|
2014-06-03 21:52:16 +08:00
|
|
|
#
|
2014-05-30 20:32:37 +08:00
|
|
|
# respond_to do |format|
|
2014-06-03 21:52:16 +08:00
|
|
|
# format.html # show.html.erb
|
|
|
|
# format.json { render json: @contestnotification }
|
2014-05-30 20:32:37 +08:00
|
|
|
# end
|
2014-06-05 10:28:36 +08:00
|
|
|
@notificationcomments = @contestnotifications.notificationcomments
|
|
|
|
@notificationcomments.reverse! if User.current.wants_notificationcomments_in_reverse_order?
|
2014-06-03 15:27:04 +08:00
|
|
|
render :layout => 'base_newcontest'
|
2014-05-30 20:32:37 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# GET /contestnotifications/new
|
|
|
|
# GET /contestnotifications/new.json
|
|
|
|
def new
|
2014-06-04 20:29:15 +08:00
|
|
|
# @contestnotification = Contestnotification.new
|
|
|
|
#
|
|
|
|
# respond_to do |format|
|
|
|
|
# format.html # new.html.erb
|
|
|
|
# format.json { render json: @contestnotification }
|
|
|
|
# end
|
|
|
|
@contestnotification = Contestnotification.new(:contest => @contest, :author => User.current)
|
|
|
|
render :layout => 'base_newcontest'
|
2014-05-30 20:32:37 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# GET /contestnotifications/1/edit
|
|
|
|
def edit
|
|
|
|
# @contestnotification = Contestnotification.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
# POST /contestnotifications
|
|
|
|
# POST /contestnotifications.json
|
|
|
|
def create
|
|
|
|
# @contestnotification = Contestnotification.new(params[:contestnotification])
|
2014-06-03 21:52:16 +08:00
|
|
|
#
|
2014-05-30 20:32:37 +08:00
|
|
|
# respond_to do |format|
|
2014-06-03 21:52:16 +08:00
|
|
|
# if @contestnotification.save
|
|
|
|
# format.html { redirect_to @contestnotification, notice: 'Contestnotification was successfully created.' }
|
|
|
|
# format.json { render json: @contestnotification, status: :created, location: @contestnotification }
|
|
|
|
# else
|
|
|
|
# format.html { render action: "new" }
|
|
|
|
# format.json { render json: @contestnotification.errors, status: :unprocessable_entity }
|
2014-05-30 20:32:37 +08:00
|
|
|
# end
|
2014-06-03 21:52:16 +08:00
|
|
|
# end
|
2014-06-04 20:29:15 +08:00
|
|
|
@contestnotification = Contestnotification.new(:contest => @contest, :author => User.current)
|
|
|
|
@contestnotification.safe_attributes = params[:contestnotification]
|
|
|
|
@contestnotification.save_attachments(params[:attachments])
|
|
|
|
if @contestnotification.save
|
|
|
|
render_attachment_warning_if_needed(@contestnotification)
|
2014-05-30 20:32:37 +08:00
|
|
|
flash[:notice] = l(:notice_successful_create)
|
2014-06-04 20:29:15 +08:00
|
|
|
redirect_to contest_contestnotifications_path(@contest)
|
2014-05-30 20:32:37 +08:00
|
|
|
else
|
2014-06-04 20:29:15 +08:00
|
|
|
layout_file = 'base_newcontest'
|
2014-05-30 20:32:37 +08:00
|
|
|
render :action => 'new', :layout => layout_file
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /contestnotifications/1
|
|
|
|
# PUT /contestnotifications/1.json
|
|
|
|
def update
|
|
|
|
# @contestnotification = Contestnotification.find(params[:id])
|
2014-06-03 21:52:16 +08:00
|
|
|
#
|
2014-05-30 20:32:37 +08:00
|
|
|
# respond_to do |format|
|
2014-06-03 21:52:16 +08:00
|
|
|
# if @contestnotification.update_attributes(params[:contestnotification])
|
|
|
|
# format.html { redirect_to @contestnotification, notice: 'Contestnotification was successfully updated.' }
|
|
|
|
# format.json { head :no_content }
|
|
|
|
# else
|
|
|
|
# format.html { render action: "edit" }
|
|
|
|
# format.json { render json: @contestnotification.errors, status: :unprocessable_entity }
|
|
|
|
# end
|
2014-05-30 20:32:37 +08:00
|
|
|
# end
|
2014-06-05 15:45:17 +08:00
|
|
|
@contestnotification.safe_attributes = params[:contestnotification]
|
|
|
|
@contestnotification.save_attachments(params[:attachments])
|
|
|
|
if @contestnotification.save
|
|
|
|
render_attachment_warning_if_needed(@contestnotification)
|
2014-05-30 20:32:37 +08:00
|
|
|
flash[:notice] = l(:notice_successful_update)
|
2014-06-05 15:45:17 +08:00
|
|
|
redirect_to contest_contestnotification_path(@contestnotification)
|
2014-05-30 20:32:37 +08:00
|
|
|
else
|
|
|
|
render :action => 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# DELETE /contestnotifications/1
|
|
|
|
# DELETE /contestnotifications/1.json
|
|
|
|
def destroy
|
|
|
|
# @contestnotification = Contestnotification.find(params[:id])
|
|
|
|
# @contestnotification.destroy
|
2014-06-03 21:52:16 +08:00
|
|
|
#
|
2014-05-30 20:32:37 +08:00
|
|
|
# respond_to do |format|
|
2014-06-03 21:52:16 +08:00
|
|
|
# format.html { redirect_to contestnotifications_url }
|
|
|
|
# format.json { head :no_content }
|
2014-05-30 20:32:37 +08:00
|
|
|
# end
|
2014-06-03 09:27:07 +08:00
|
|
|
@contestnotifications.destroy
|
2014-06-05 15:45:17 +08:00
|
|
|
redirect_to contest_contestnotifications_path(@contest)
|
2014-05-30 20:32:37 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_optional_contest
|
2014-06-03 18:24:55 +08:00
|
|
|
return true unless params[:id]
|
|
|
|
@contest = Contest.find(params[:id])
|
2014-06-03 21:52:16 +08:00
|
|
|
# authorize
|
2014-05-30 20:32:37 +08:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
2014-06-03 21:52:16 +08:00
|
|
|
|
2014-05-30 20:32:37 +08:00
|
|
|
end
|