app/controllers/scrivito/objs_controller.rb in scrivito_sdk-0.30.0 vs app/controllers/scrivito/objs_controller.rb in scrivito_sdk-0.40.0.rc1

- old
+ new

@@ -6,10 +6,11 @@ :destroy, :destroy_widget, :duplicate, :mark_resolved, :restore, + :restore_widget, :revert, :revert_widget, :update, ] @@ -21,22 +22,23 @@ :update, :widget_class_selection, ] def create - obj_params = obj_params_parser.parse(nil, params[:obj]) - @obj = selected_workspace.task_unaware_api_request(:post, '/objs', obj: obj_params) + params_parser = ObjCreateParamsParser.new(request.host, request.port) + @obj = Obj.create(params_parser.parse(params[:obj])) + render :obj end def details - @markup = render_to_string(current_obj.details_view_path, layout: false, formats: :html) + assert_dialog_layout + render current_obj.details_view_path, layout: 'scrivito_dialog', formats: :html end def update - obj_params = obj_params_parser.parse(current_obj, params[:obj]) - @api_response = selected_workspace - .task_unaware_api_request(:put, "/objs/#{params[:id]}", obj: obj_params) + params_parser = ObjUpdateParamsParser.new(current_obj, request.host, request.port) + current_obj.update(params_parser.parse(params[:obj])) end def destroy in_selected_workspace { current_obj.destroy } render_empty_json @@ -60,22 +62,28 @@ def restore in_selected_workspace { Obj.restore(params[:id]) } render_empty_json end + def restore_widget + in_selected_workspace { current_obj.restore_widget(params[:widget_id]) } + render_empty_json + end + def mark_resolved in_selected_workspace { current_obj.mark_resolved } render_empty_json end def copy - @attributes = copy_obj(current_obj, params[:parent_path]) + @obj = copy_obj(current_obj, params[:parent_path]) + render :obj end def duplicate - @attributes = copy_obj(current_obj, current_obj.parent_path) - render :copy + @obj = copy_obj(current_obj, current_obj.parent_path) + render :obj end def page_class_selection @page_class_markup = valid_page_classes.map do |page_class_name| begin @@ -165,20 +173,13 @@ raise ScrivitoError, "widget with ID '#{params[:widget_id]}' not found" end @widget end - def copy_obj(obj, target_path) + def copy_obj(obj, parent_path) id = SecureRandom.hex(8) - copied_obj = obj.copy(_id: id, _path: "#{target_path}/#{id}") - dumped_last_changed = CmsRestApi::AttributeSerializer.convert_time(copied_obj[:_last_changed]) - { - _id: copied_obj[:_id], - _last_changed: dumped_last_changed, - _obj_class: copied_obj[:_obj_class_name], - _path: copied_obj[:_path], - } + obj.copy(_id: id, _path: parent_path && "#{parent_path}/#{id}") end def fetch_formatter(name) name ? Configuration.obj_formats[name] : proc { |obj, _| obj.id } end @@ -199,10 +200,18 @@ def widget_classes_from_obj current_obj.valid_widget_classes_for(params[:field_name]) end - def obj_params_parser - ObjParamsParser.new(request.host, request.port) + 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