Sha256: 325f997ad904c4dbf001b60858c4fb6c93fe5b906f79a317a33df0668c3d3484

Contents?: true

Size: 1.92 KB

Versions: 4

Compression:

Stored size: 1.92 KB

Contents

class Admin::ResourcesController < Admin::BaseController
  
  crudify :resource, :order => "updated_at DESC"
  
	def new
		@resource = Resource.new
		
    @url_override = admin_resources_url(:dialog => from_dialog?)
	end
	
	def create
    @resource = Resource.create params[:resource]
		
		unless params[:insert]
  		if @resource.valid?
  		  flash[:notice] = "'#{@resource.title}' was successfully created."
  			unless from_dialog?
  				redirect_to :action => 'index'
  			else
  				render :text => "<script type='text/javascript'>parent.window.location = '#{admin_resources_url}';</script>"
  			end
  		else
  			render :action => 'new'
  		end
		else
		  @resource_id = @resource.id
		  @resource = nil
		  self.insert
		end
  end
  
  def insert
    self.new if @resource.nil?
    @dialog = from_dialog?
    @thickbox = !params[:thickbox].blank?
    @field = params[:field]
    @update_resource = params[:update_resource]
    @update_text = params[:update_text]
    @thumbnail = params[:thumbnail]
    @callback = params[:callback]
		@conditions = params[:conditions]
		@current_link = params[:current_link]
    @url_override = admin_resources_url(:dialog => @dialog, :insert => true)

		unless params[:conditions].blank?
			extra_condition = params[:conditions].split(',')
			
			extra_condition[1] = true if extra_condition[1] == "true"
			extra_condition[1] = false if extra_condition[1] == "false"
			extra_condition[1] = nil if extra_condition[1] == "nil"
	    paginate_resources({extra_condition[0].to_sym => extra_condition[1]})
		else
			paginate_resources
		end
    render :action => "insert"
  end
  
protected

	def paginate_resources(conditions={})
	  @resources = Resource.paginate 	:page => (@paginate_page_number ||= params[:page]),
	                           	      :conditions => conditions,
	                           	      :order => 'created_at DESC',
	                           	      :per_page => Resource.per_page(from_dialog?)
	end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
refinerycms-0.9.5.9 vendor/plugins/resources/app/controllers/admin/resources_controller.rb
refinerycms-0.9.5.8 vendor/plugins/resources/app/controllers/admin/resources_controller.rb
refinerycms-0.9.5.7 vendor/plugins/resources/app/controllers/admin/resources_controller.rb
refinerycms-0.9.5.6 vendor/plugins/resources/app/controllers/admin/resources_controller.rb