Class: Cms::ContentBlockController

Inherits:
BaseController show all
Includes:
ContentRenderingSupport, PublishWorkflow
Defined in:
app/controllers/cms/content_block_controller.rb

Instance Method Summary collapse

Methods included from ContentRenderingSupport

#handle_access_denied_on_page, #handle_draft_not_found, #handle_not_found_on_page, #handle_server_error_on_page, #show_content_as_page

Methods inherited from BaseController

allow_guests_to

Methods inherited from ApplicationController

#no_browser_caching

Instance Method Details

#bulk_updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/cms/content_block_controller.rb', line 25

def bulk_update
  ids    = params[:content_id] || []
  models = ids.collect do |id|
    model_class.find(id.to_i)
  end
  if params[:commit] == 'Delete'
    deleted        = models.select do |m|
      m.destroy
    end
    flash[:notice] = "Deleted #{deleted.size} records."
  else
    # Need to do these one at a time since the code logic is more complex than single UPDATE.
    published = models.select do |m|
      m.publish!
    end

    flash[:notice] = "Published #{published.size} records."
  end

  redirect_to action: :index
end

#createObject



84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/cms/content_block_controller.rb', line 84

def create
  return render_not_implemented if readonly?

  if create_block
    after_create_on_success
  else
    after_create_on_failure
  end
rescue Exception => @exception
  raise @exception if @exception.is_a?(Cms::Errors::AccessDenied)
  after_create_on_error
end

#destroyObject



125
126
127
128
129
130
131
132
133
134
# File 'app/controllers/cms/content_block_controller.rb', line 125

def destroy
  return render_not_implemented if readonly?

  do_command("deleted") { @block.destroy }
  respond_to do |format|
    format.html { redirect_to_first params[:_redirect_to], engine_aware_path(@block.class) }
    format.json { render :json => { :success => true } }
  end

end

#editObject



97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/controllers/cms/content_block_controller.rb', line 97

def edit
  load_block_draft

  if readonly?
    url = [params[:_redirect_to], engine_aware_path(@block)].map(&:presence).compact.first
    if url
      return redirect_to url, alert: 'Read only models cannot be edited'
    else
      return render_not_implemented
    end
  end
end

#indexObject



21
22
23
# File 'app/controllers/cms/content_block_controller.rb', line 21

def index
  load_blocks
end

#inlineObject

Getting the content for the editing frame.



64
65
66
67
# File 'app/controllers/cms/content_block_controller.rb', line 64

def inline
  load_block_draft
  render_block_in_main_container
end

#newObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/cms/content_block_controller.rb', line 69

def new
  build_block

  if readonly?
    url = [params[:_redirect_to], engine_aware_path(@block, nil)].map(&:presence).compact.first
    if url
      return redirect_to url, alert: 'Read only models cannot be created'
    else
      return render_not_implemented
    end
  end

  set_default_category
end

#new_button_pathObject



170
171
172
# File 'app/controllers/cms/content_block_controller.rb', line 170

def new_button_path
  new_engine_aware_path(content_type) unless readonly?
end

#publishObject

Additional CMS Action



138
139
140
141
142
143
# File 'app/controllers/cms/content_block_controller.rb', line 138

def publish
  return render_not_implemented if readonly?

  do_command("published") { @block.publish! }
  redirect_to_first params[:_redirect_to], engine_aware_path(@block, nil)
end

#revert_toObject



145
146
147
148
149
150
151
152
# File 'app/controllers/cms/content_block_controller.rb', line 145

def revert_to
  return render_not_implemented if readonly?

  do_command("reverted to version #{params[:version]}") do
    revert_block(params[:version])
  end
  redirect_to_first params[:_redirect_to], engine_aware_path(@block, nil)
end

#showObject

Getting content by its id (i.e. /products/:id) Logged in editors will get the editing frame.



58
59
60
61
# File 'app/controllers/cms/content_block_controller.rb', line 58

def show
  load_block_draft
  render_editing_frame_or_block_in_main_container
end

#show_via_slugObject

Getting content by its path (i.e. /products/:slug)



48
49
50
51
52
53
54
# File 'app/controllers/cms/content_block_controller.rb', line 48

def show_via_slug
  @block = model_class.with_slug(params[:slug])
  unless @block
    raise Cms::Errors::ContentNotFound.new("No Content at #{model_class.calculate_path(params[:slug])}")
  end
  render_block_in_main_container
end

#updateObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/controllers/cms/content_block_controller.rb', line 110

def update
  return render_not_implemented if readonly?

  if update_block
    after_update_on_success
  else
    after_update_on_failure
  end
rescue ActiveRecord::StaleObjectError => @exception
  after_update_on_edit_conflict
rescue Exception => @exception
  raise @exception if @exception.is_a?(Cms::Errors::AccessDenied)
  after_update_on_error
end

#versionObject



154
155
156
157
158
159
160
161
162
# File 'app/controllers/cms/content_block_controller.rb', line 154

def version
  return render_not_implemented unless versioned?

  load_block
  if params[:version]
    @block = @block.as_of_version(params[:version])
  end
  render "show_in_isolation"
end

#versionsObject



164
165
166
167
168
# File 'app/controllers/cms/content_block_controller.rb', line 164

def versions
  return render_not_implemented unless versioned?

  load_block
end