Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class StoriesController < ApplicationController
- before_filter :set_type, :except => [:feed, :legacy]
- before_filter :set_legacy_type, :only => :legacy
- skip_before_filter :login_required, :only => :feed
- before_filter :check_permission, :except => :feed
- before_filter :check_write_permission, :only => [:new, :create, :edit, :update]
- before_filter :admin_required, :only => :destroy
- uses_tiny_mce :only => [:new, :create, :edit, :update], :options => {
- :theme => 'advanced',
- :theme_advanced_toolbar_location => 'top',
- :theme_advanced_statusbar_location => 'bottom',
- :theme_advanced_buttons1 => %w{ bold italic underline strikethrough | justifyleft justifycenter justifyright justifyfull | formatselect fontselect fontsizeselect },
- :theme_advanced_resizing => true,
- :theme_advanced_resize_horizontal => false,
- :plugins => %w{ table fullscreen }
- }
- def search
- @stories= Stories.search(params[:keyword])
- format.html {render :partial=>'index'}
- end
- cache_sweeper :story_sweeper, :only => [:create, :update, :destroy]
- # GET /stories
- # GET /stories.xml
- def feed
- @project = Project.find(params[:project_id])
- @type = @project.types.find(params[:type_id])
- @stories = @type.stories(:order => 'updated_at desc')
- if @type.allow_feed
- respond_to do |format|
- format.atom
- end
- else
- render(:text => "Can't show feeds for this type")
- end
- end
- def legacy
- @stories = @type.stories.paginate :page => params[:page], :per_page => 30, :order => 'updated_at desc'
- respond_to do |format|
- format.html { render :action => 'index'}
- end
- end
- def index
- @stories = @type.paginated_stories(params)
- respond_to do |format|
- format.html # index.html.erb
- format.xml { render :xml => @stories.to_xml(
- :include => [:sources, :authors, :images, :fyles, :tags, :category],
- :methods => :comments_count,
- :except => [:case_id, :txtSource, :subtypeID, :issue_id, :blnActive, :parcel_id, :blnHostedContent, :state_id, :blnTopStory, :industry_id, :siteID, :typeID]
- ) }
- end
- end
- def sort
- @stories = @type.paginated_stories(params)
- respond_to do |format|
- format.js { render :partial => 'stories' }
- end
- end
- # GET /stories/1
- # GET /stories/1.xml
- def show
- @story = @type.stories.find_by_permalink(params[:id]) || @type.stories.find(params[:id])
- respond_to do |format|
- format.html # show.html.erb
- format.xml { render :xml => @story.to_xml(
- :include => [:sources, :authors, :images, :fyles, :tags, :category],
- :except => [:case_id, :txtSource, :subtypeID, :issue_id, :blnActive, :parcel_id, :blnHostedContent, :state_id, :blnTopStory, :industry_id, :siteID, :typeID]
- ) }
- end
- end
- # GET /stories/new
- # GET /stories/new.xml
- def new
- store_location
- @story = @type.stories.build
- respond_to do |format|
- format.html # new.html.erb
- format.xml { render :xml => @story }
- end
- end
- # GET /stories/1/edit
- def edit
- store_location
- @story = @type.stories.find_by_permalink(params[:id]) || @type.stories.find(params[:id])
- end
- # POST /stories
- # POST /stories.xml
- def create
- @story = @type.stories.build(params[:story])
- respond_to do |format|
- if @story.save
- flash[:notice] = 'Story was successfully created.'
- format.html { redirect_to([@project, @type, @story]) }
- format.xml { render :xml => @story, :status => :created, :location => @story }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @story.errors, :status => :unprocessable_entity }
- end
- end
- end
- # PUT /stories/1
- # PUT /stories/1.xml
- def update
- params[:author_ids] ||= []
- params[:source_ids] ||= []
- params[:tag_ids] ||= []
- params[:image_ids] ||= []
- params[:fyle_ids] ||= []
- params[:legacy_file_ids] ||= []
- @story = @type.stories.find_by_permalink(params[:id]) || @type.stories.find(params[:id])
- Author.unlink_authors(@story.id, params[:author_ids]) unless params[:author_ids].empty?
- Source.unlink_sources(@story.id, params[:source_ids]) unless params[:source_ids].empty?
- Tag.unlink_tags(@story.id, params[:tag_ids]) unless params[:tag_ids].empty?
- Image.destroy_pics(@story.id, params[:image_ids]) unless params[:image_ids].empty?
- Fyle.destroy_fyles(@story.id, params[:fyle_ids]) unless params[:fyle_ids].empty?
- LegacyFile.destroy_pics(@story.id, params[:legacy_file_ids]) unless params[:legacy_file_ids].empty?
- LegacyFile.disable_pics(@story.id, params[:disable_legacy_file_ids])
- respond_to do |format|
- if @story.update_attributes(params[:story])
- flash[:notice] = 'Story was successfully updated.'
- format.html { redirect_to([@project, @type, @story]) }
- format.xml { head :ok }
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @story.errors, :status => :unprocessable_entity }
- end
- end
- end
- # DELETE /stories/1
- # DELETE /stories/1.xml
- def destroy
- @story = @type.stories.find_by_permalink(params[:id]) || @type.stories.find(params[:id])
- @story.destroy
- respond_to do |format|
- format.html { redirect_to(project_type_stories_url(@project, @type)) }
- format.xml { head :ok }
- end
- end
- protected
- def set_type
- @project = current_user.admin ? Project.find(params[:project_id]) : current_user.projects.find(params[:project_id])
- @type = @project.types.find(params[:type_id])
- end
- def set_legacy_type
- @project = current_user.admin ? Project.find_by_name("1871Transition Project") : current_user.projects.find_by_name("1871Transition Project")
- @type = SlugTypeid.find_by_typeid(params[:typeID])
- end
- def check_permission
- current_user.has_projects || access_denied
- end
- end
Add Comment
Please, Sign In to add comment