Class: Refinery::Admin::ResourcesController

Inherits:
Refinery::AdminController show all
Defined in:
resources/app/controllers/refinery/admin/resources_controller.rb

Instance Method Summary collapse

Methods included from BaseController

#admin?, included, #refinery_admin_root_path, #searching?

Methods included from Refinery::ApplicationController

#admin?, #current_refinery_user, #error_404, #from_dialog?, #home_page?, included, #local_request?

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'resources/app/controllers/refinery/admin/resources_controller.rb', line 18

def create
  @resources = Resource.create_resources(resource_params)
  @resource = @resources.detect { |r| !r.valid? }

  if params[:insert]
    if @resources.all?(&:valid?)
      @resource_id = @resources.detect(&:persisted?).id
      @resource = nil

      self.insert
    end
  else
    if @resources.all?(&:valid?)
      flash.notice = t('created', :scope => 'refinery.crudify', :what => "'#{@resources.map(&:title).join("', '")}'")
      if from_dialog?
        @dialog_successful = true
        render '/refinery/admin/dialog_success', layout: true
      else
        redirect_to refinery.admin_resources_path
      end
    else
      self.new # important for dialogs
      render 'new'
    end
  end
end

#insertObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'resources/app/controllers/refinery/admin/resources_controller.rb', line 45

def insert
  self.new if @resource.nil?
  @url_override = refinery.admin_resources_path(request.query_parameters.merge(insert: true))

  if params[:conditions].present?
    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"
  end

  find_all_resources(({extra_condition[0] => extra_condition[1]} if extra_condition.present?))
  search_all_resources if searching?

  paginate_resources

  @resource_area_selected = from_dialog?

  if params[:visual_editor]
    render '/refinery/admin/pages_dialogs/link_to' 
  else 
    render 'insert' 
  end
end

#newObject



12
13
14
15
16
# File 'resources/app/controllers/refinery/admin/resources_controller.rb', line 12

def new
  @resource = Resource.new if @resource.nil?

  @url_override = refinery.admin_resources_path(:dialog => from_dialog?)
end