Guest User

Untitled

a guest
Jul 9th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. class StoriesController < ApplicationController
  2. before_filter :set_type, :except => [:feed, :legacy]
  3. before_filter :set_legacy_type, :only => :legacy
  4. skip_before_filter :login_required, :only => :feed
  5. before_filter :check_permission, :except => :feed
  6. before_filter :check_write_permission, :only => [:new, :create, :edit, :update]
  7. before_filter :admin_required, :only => :destroy
  8.  
  9. uses_tiny_mce :only => [:new, :create, :edit, :update], :options => {
  10. :theme => 'advanced',
  11. :theme_advanced_toolbar_location => 'top',
  12. :theme_advanced_statusbar_location => 'bottom',
  13. :theme_advanced_buttons1 => %w{ bold italic underline strikethrough | justifyleft justifycenter justifyright justifyfull | formatselect fontselect fontsizeselect },
  14. :theme_advanced_resizing => true,
  15. :theme_advanced_resize_horizontal => false,
  16. :plugins => %w{ table fullscreen }
  17. }
  18.  
  19. def search
  20. @stories= Stories.search(params[:keyword])
  21. format.html {render :partial=>'index'}
  22. end
  23.  
  24. cache_sweeper :story_sweeper, :only => [:create, :update, :destroy]
  25. # GET /stories
  26. # GET /stories.xml
  27.  
  28. def feed
  29. @project = Project.find(params[:project_id])
  30. @type = @project.types.find(params[:type_id])
  31. @stories = @type.stories(:order => 'updated_at desc')
  32.  
  33. if @type.allow_feed
  34. respond_to do |format|
  35. format.atom
  36. end
  37. else
  38. render(:text => "Can't show feeds for this type")
  39. end
  40. end
  41.  
  42. def legacy
  43. @stories = @type.stories.paginate :page => params[:page], :per_page => 30, :order => 'updated_at desc'
  44.  
  45. respond_to do |format|
  46. format.html { render :action => 'index'}
  47. end
  48. end
  49.  
  50. def index
  51. @stories = @type.paginated_stories(params)
  52.  
  53. respond_to do |format|
  54. format.html # index.html.erb
  55. format.xml { render :xml => @stories.to_xml(
  56. :include => [:sources, :authors, :images, :fyles, :tags, :category],
  57. :methods => :comments_count,
  58. :except => [:case_id, :txtSource, :subtypeID, :issue_id, :blnActive, :parcel_id, :blnHostedContent, :state_id, :blnTopStory, :industry_id, :siteID, :typeID]
  59. ) }
  60. end
  61. end
  62.  
  63. def sort
  64. @stories = @type.paginated_stories(params)
  65.  
  66. respond_to do |format|
  67. format.js { render :partial => 'stories' }
  68. end
  69. end
  70.  
  71. # GET /stories/1
  72. # GET /stories/1.xml
  73.  
  74. def show
  75. @story = @type.stories.find_by_permalink(params[:id]) || @type.stories.find(params[:id])
  76.  
  77. respond_to do |format|
  78. format.html # show.html.erb
  79. format.xml { render :xml => @story.to_xml(
  80. :include => [:sources, :authors, :images, :fyles, :tags, :category],
  81. :except => [:case_id, :txtSource, :subtypeID, :issue_id, :blnActive, :parcel_id, :blnHostedContent, :state_id, :blnTopStory, :industry_id, :siteID, :typeID]
  82. ) }
  83. end
  84. end
  85.  
  86. # GET /stories/new
  87. # GET /stories/new.xml
  88. def new
  89. store_location
  90. @story = @type.stories.build
  91.  
  92. respond_to do |format|
  93. format.html # new.html.erb
  94. format.xml { render :xml => @story }
  95. end
  96. end
  97.  
  98. # GET /stories/1/edit
  99. def edit
  100. store_location
  101. @story = @type.stories.find_by_permalink(params[:id]) || @type.stories.find(params[:id])
  102. end
  103.  
  104. # POST /stories
  105. # POST /stories.xml
  106. def create
  107. @story = @type.stories.build(params[:story])
  108.  
  109. respond_to do |format|
  110. if @story.save
  111. flash[:notice] = 'Story was successfully created.'
  112. format.html { redirect_to([@project, @type, @story]) }
  113. format.xml { render :xml => @story, :status => :created, :location => @story }
  114. else
  115. format.html { render :action => "new" }
  116. format.xml { render :xml => @story.errors, :status => :unprocessable_entity }
  117. end
  118. end
  119. end
  120.  
  121. # PUT /stories/1
  122. # PUT /stories/1.xml
  123. def update
  124. params[:author_ids] ||= []
  125. params[:source_ids] ||= []
  126. params[:tag_ids] ||= []
  127. params[:image_ids] ||= []
  128. params[:fyle_ids] ||= []
  129. params[:legacy_file_ids] ||= []
  130. @story = @type.stories.find_by_permalink(params[:id]) || @type.stories.find(params[:id])
  131. Author.unlink_authors(@story.id, params[:author_ids]) unless params[:author_ids].empty?
  132. Source.unlink_sources(@story.id, params[:source_ids]) unless params[:source_ids].empty?
  133. Tag.unlink_tags(@story.id, params[:tag_ids]) unless params[:tag_ids].empty?
  134. Image.destroy_pics(@story.id, params[:image_ids]) unless params[:image_ids].empty?
  135. Fyle.destroy_fyles(@story.id, params[:fyle_ids]) unless params[:fyle_ids].empty?
  136. LegacyFile.destroy_pics(@story.id, params[:legacy_file_ids]) unless params[:legacy_file_ids].empty?
  137. LegacyFile.disable_pics(@story.id, params[:disable_legacy_file_ids])
  138.  
  139. respond_to do |format|
  140. if @story.update_attributes(params[:story])
  141. flash[:notice] = 'Story was successfully updated.'
  142. format.html { redirect_to([@project, @type, @story]) }
  143. format.xml { head :ok }
  144. else
  145. format.html { render :action => "edit" }
  146. format.xml { render :xml => @story.errors, :status => :unprocessable_entity }
  147. end
  148. end
  149. end
  150.  
  151. # DELETE /stories/1
  152. # DELETE /stories/1.xml
  153. def destroy
  154. @story = @type.stories.find_by_permalink(params[:id]) || @type.stories.find(params[:id])
  155. @story.destroy
  156.  
  157. respond_to do |format|
  158. format.html { redirect_to(project_type_stories_url(@project, @type)) }
  159. format.xml { head :ok }
  160. end
  161. end
  162. protected
  163. def set_type
  164. @project = current_user.admin ? Project.find(params[:project_id]) : current_user.projects.find(params[:project_id])
  165. @type = @project.types.find(params[:type_id])
  166. end
  167. def set_legacy_type
  168. @project = current_user.admin ? Project.find_by_name("1871Transition Project") : current_user.projects.find_by_name("1871Transition Project")
  169. @type = SlugTypeid.find_by_typeid(params[:typeID])
  170. end
  171. def check_permission
  172. current_user.has_projects || access_denied
  173. end
  174. end
Add Comment
Please, Sign In to add comment