You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							165 lines
						
					
					
						
							5.7 KiB
						
					
					
				
			
		
		
	
	
							165 lines
						
					
					
						
							5.7 KiB
						
					
					
				| class ContestnotificationsController < ApplicationController
 | |
|   # GET /contestnotifications
 | |
|   # GET /contestnotifications.json
 | |
|   layout 'base_newcontest'
 | |
|   default_search_scope :contestnotifications
 | |
|   # model_object Contestnotifications
 | |
|   before_filter :find_model_object_contest, :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 :authorize, :except => [:index]
 | |
|   before_filter :find_optional_contest, :only => [:index]
 | |
|   accept_rss_auth :index
 | |
|   accept_api_auth :index  
 | |
|   
 | |
| 
 | |
|   
 | |
|   def index
 | |
|     @user = @contest.author
 | |
|     # @contestnotifications = Contestnotification.all
 | |
| # 
 | |
|     # respond_to do |format|
 | |
|       # format.html # index.html.erb
 | |
|       # format.json { render json: @contestnotifications }
 | |
|     # end
 | |
|     
 | |
|     ### begin ###
 | |
|     case params[:format]
 | |
|     when 'xml', 'json'
 | |
|       @offset, @limit = api_offset_and_limit
 | |
|     else
 | |
|       @limit =  10
 | |
|     end
 | |
| 
 | |
|     scope = @contest ? @contest.contestnotifications.visible : Contestnotification.visible
 | |
| 
 | |
|     @contestnotifications_count = scope.count
 | |
|     @contestnotifications_pages = Paginator.new @contestnotifications_count, @limit, params['page']
 | |
|     @offset ||= @contestnotifications_pages.offset
 | |
|     @contestnotificationss = scope.all(:include => [:author, :contest],
 | |
|                                        :order => "#{Contestnotification.table_name}.created_at DESC",
 | |
|                                        :offset => @offset,
 | |
|                                        :limit => @limit)  
 | |
|                                       
 | |
|     respond_to do |format|
 | |
|       format.html {
 | |
|         @contestnotification = Contestnotification.new # for adding news inline
 | |
|         render :layout => 'base_newcontest'
 | |
|       }
 | |
|       format.api
 | |
|       format.atom { render_feed(@contestnotificationss, :title => (@contest ? @contest.name : Setting.app_title) + ": #{l(:label_contest_notification)}") }
 | |
|     end
 | |
|   ### end ###
 | |
|   end
 | |
| 
 | |
|   # GET /contestnotifications/1
 | |
|   # GET /contestnotifications/1.json
 | |
|   def show
 | |
|     # @contestnotification = Contestnotification.find(params[:id])
 | |
| # 
 | |
|     # respond_to do |format|
 | |
|       # format.html # show.html.erb
 | |
|       # format.json { render json: @contestnotification }
 | |
|     # end
 | |
|     @comments = @contestnotifications.comments
 | |
|     @comments.reverse! if User.current.wants_comments_in_reverse_order?    
 | |
|     render :layout => 'base_newcontest'
 | |
| 
 | |
|   end
 | |
| 
 | |
|   # GET /contestnotifications/new
 | |
|   # GET /contestnotifications/new.json
 | |
|   def new
 | |
|     @contestnotification = Contestnotification.new
 | |
| 
 | |
|     respond_to do |format|
 | |
|       format.html # new.html.erb
 | |
|       format.json { render json: @contestnotification }
 | |
|     end
 | |
|     # @contestnotifications = Contestnotifications.new(:contest => @contest, :author => User.current)
 | |
|     # render :layout => 'base_contest'
 | |
|   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])
 | |
| # 
 | |
|     # respond_to do |format|
 | |
|       # 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 }
 | |
|       # end
 | |
|     # end
 | |
|     @contestnotifications = Contestnotifications.new(:contest => @contest, :author => User.current) 
 | |
|     @contestnotifications.safe_attributes = params[:contestnotifications]
 | |
|     @news.save_attachments(params[:attachments])
 | |
|     if @contestnotifications.save
 | |
|       render_attachment_warning_if_needed(@contestnotifications)
 | |
|       flash[:notice] = l(:notice_successful_create)
 | |
|       redirect_to project_news_index_path(@contest)
 | |
|     else
 | |
|       layout_file = 'base_contest' 
 | |
|       render :action => 'new', :layout => layout_file
 | |
|     end
 | |
|   end
 | |
| 
 | |
|   # PUT /contestnotifications/1
 | |
|   # PUT /contestnotifications/1.json
 | |
|   def update
 | |
|     # @contestnotification = Contestnotification.find(params[:id])
 | |
| # 
 | |
|     # respond_to do |format|
 | |
|       # 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
 | |
|     # end
 | |
|     @contestnotifications.safe_attributes = params[:contestnotifications]
 | |
|     @contestnotifications.save_attachments(params[:attachments])
 | |
|     if @contestnotifications.save
 | |
|       render_attachment_warning_if_needed(@contestnotifications)
 | |
|       flash[:notice] = l(:notice_successful_update)
 | |
|       redirect_to contestnotification_path(@contestnotifications)
 | |
|     else
 | |
|       render :action => 'edit'
 | |
|     end
 | |
|   end
 | |
| 
 | |
|   # DELETE /contestnotifications/1
 | |
|   # DELETE /contestnotifications/1.json
 | |
|   def destroy
 | |
|     # @contestnotification = Contestnotification.find(params[:id])
 | |
|     # @contestnotification.destroy
 | |
| # 
 | |
|     # respond_to do |format|
 | |
|       # format.html { redirect_to contestnotifications_url }
 | |
|       # format.json { head :no_content }
 | |
|     # end
 | |
|     @contestnotifications.destroy
 | |
|     redirect_to contest_contestnotification_index_path(@contest)
 | |
|   end
 | |
| 
 | |
|   private
 | |
| 
 | |
|   def find_optional_contest
 | |
|     return true unless params[:id]
 | |
|     @contest = Contest.find(params[:id])
 | |
|     # authorize
 | |
|   rescue ActiveRecord::RecordNotFound
 | |
|     render_404
 | |
|   end
 | |
|  
 | |
| end
 |