Class: Cortex::ContentItemsController

Inherits:
AdminController show all
Includes:
ContentItemHelper, Decoratable, PopupHelper
Defined in:
app/controllers/cortex/content_items_controller.rb

Instance Method Summary collapse

Methods included from PopupHelper

#media_asset_field, #media_content_items, #media_content_type, #media_image_content_items, #media_index

Methods included from ContentItemHelper

#clean_error_messages, #content_item_params, #content_item_reload, #content_type, #create_content_item, #field_item_param_data, #field_items_attributes_params, #index_parameters, #params_lookup, #permit_attribute_params, #permit_param, #render_create_content_item_error, #render_update_content_item_error, #sanitize_parameters, #update_content_item

Instance Method Details

#createObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/cortex/content_items_controller.rb', line 61

def create
  create_content_item
    .with_step_args(
      execute_content_item_state_change: [state: params[:content_item][:state]]
    )
    .call(id: params[:id], content_type: content_type,
          content_item_params: content_item_params, current_user: current_user) do |m|
    m.success do |content_item|
      flash[:success] = "#{content_type.name} successfully created"
      redirect_to content_type_content_items_path
    end

    m.failure :persist_content_item do |errors|
      flash[:warning] = clean_error_messages(errors.full_messages)
      render_create_content_item_error
    end

    m.failure do |error|
      flash[:warning] = ['Unknown System Error']
      render_update_content_item_error
    end
  end
end

#editObject



27
28
29
30
31
32
33
34
35
# File 'app/controllers/cortex/content_items_controller.rb', line 27

def edit
  @content_item = content_type.content_items.find_by_tenant(current_user.active_tenant).find_by_id(params[:id])
  @wizard = wizard_decorator(@content_item.content_type)

  title = @content_item.field_items.find {|field_item| field_item.field.name == 'Title'}.data['text'] # TODO: refactor this hardcoded Field reference
  add_breadcrumb content_type.name.pluralize, :content_type_content_items_path
  add_breadcrumb title
  add_breadcrumb 'Edit'
end

#indexObject



9
10
11
12
13
# File 'app/controllers/cortex/content_items_controller.rb', line 9

def index
  @index = index_decorator(content_type)
  @content_items = content_type.content_items.find_by_tenant(current_user.active_tenant)
  add_breadcrumb content_type.name.pluralize
end

#newObject



15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/cortex/content_items_controller.rb', line 15

def new
  @content_item = content_type.content_items.new
  content_type.fields.each do |field|
    # TODO: Should this hit the Plugin Transaction Layer?
    @content_item.field_items << FieldItem.new(field: field)
  end
  @wizard = wizard_decorator(@content_item.content_type)

  add_breadcrumb content_type.name.pluralize, :content_type_content_items_path
  add_breadcrumb 'New'
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/cortex/content_items_controller.rb', line 37

def update
  update_content_item
    .with_step_args(
      execute_content_item_state_change: [state: params[:content_item][:state]]
    )
    .call(id: params[:id], content_type: content_type,
          content_item_params: content_item_params, current_user: current_user) do |m|
    m.success do |content_item|
      flash[:success] = "#{content_type.name} successfully updated"
      redirect_to content_type_content_items_path
    end

    m.failure :persist_content_item do |errors|
      flash[:warning] = clean_error_messages(errors.full_messages)
      render_update_content_item_error
    end

    m.failure do |error|
      flash[:warning] = ['Unknown System Error']
      render_update_content_item_error
    end
  end
end