lib/scrivito/controller_actions.rb in scrivito_sdk-0.30.0 vs lib/scrivito/controller_actions.rb in scrivito_sdk-0.40.0.rc1
- old
+ new
@@ -40,19 +40,21 @@
widget = load_widget
render text: Scrivito::WidgetTag.new(view_context, widget).render, layout: false
end
def widget_details
+ assert_dialog_layout
widget = load_widget
template_path = "#{widget.obj_class_name.underscore}/details"
- render template_path, layout: false, locals: {widget: widget}
+ render template_path, layout: 'scrivito_dialog', locals: {widget: widget}
end
def details_page
+ assert_dialog_layout
@scrivito_resource = editing_context.selected_workspace.objs
.find_including_deleted(params[:resource_id])
- render text: '', layout: true
+ render text: '', layout: 'scrivito_dialog'
end
module ClassMethods
#
# This method indicates if this controller should be used automatically when an +Obj+ is
@@ -77,19 +79,26 @@
def editing_context
request.env[EditingContextMiddleware::ENVKEY] || EditingContext.new
end
+ delegate :comparison, to: :editing_context
+
def load_object
CmsEnv.new(request.env).load
loaded_obj = request.env[CmsEnv::OBJ_ENV_KEY]
raise loaded_obj if loaded_obj.is_a?(StandardError)
@obj = loaded_obj
end
def load_widget
- @obj.widget_from_pool(params[:widget_id])
+ if widget = @obj.widget_from_pool(params[:widget_id])
+ widget
+ elsif comparison.active? # The "diff" mode.
+ @obj.in_revision(editing_context.selected_workspace.base_revision)
+ .widget_from_pool(params[:widget_id])
+ end
end
#
# Deliver a binary +Obj+ by redirecting to its {BasicObj#binary Obj#binary}'s url.
# Will respond with 404 if the +Obj+ has no +blob+.
@@ -100,9 +109,21 @@
if url = @obj.binary_url
redirect_to CmsRouting.match_protocol(url, request)
else
render text: 'Empty Blob', status: 404
end
+ end
+
+ def assert_dialog_layout
+ view_context.lookup_context.find('layouts/scrivito_dialog')
+ rescue ActionView::MissingTemplate
+ raise %{
+ Missing the Scrivito dialog layout!
+
+ Scrivito requires a special view layout in order to render the details dialog.
+ Normally the install generator places it in `app/views/layouts/scrivito_dialog.html.erb`.
+ If upgrading Scrivito, please re-run the install generator: `rails g scrivito:install`.
+ }
end
end
end