Class: Scrivito::ObjsController

Inherits:
WebserviceController show all
Defined in:
app/controllers/scrivito/objs_controller.rb

Instance Method Summary collapse

Instance Method Details

#binary_no_cacheObject



83
84
85
86
87
88
# File 'app/controllers/scrivito/objs_controller.rb', line 83

def binary_no_cache
  in_selected_workspace do
    binary = current_obj[params[:attribute_name]]
    @no_cache_url = binary.no_cache_url
  end
end

#conflicting_workspacesObject



78
79
80
81
# File 'app/controllers/scrivito/objs_controller.rb', line 78

def conflicting_workspaces
  @workspaces = selected_workspace.conflict_warning_for(params[:id])
  render :workspaces
end

#createObject



28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/scrivito/objs_controller.rb', line 28

def create
  params_parser = ObjCreateParamsParser.new(request.host, request.port)
  @obj = Obj.create(params_parser.parse(params[:obj]), scrivito_user: scrivito_user)
  render :obj
rescue ObjClassNotFound => e
  raise ClientError.new(
    "You've tried to create a CMS object based on the \"#{e.message}\" class, which is "\
    "either missing or not suitable for the object."
  )
end

#destroyObject



50
51
52
53
54
55
56
# File 'app/controllers/scrivito/objs_controller.rb', line 50

def destroy
  in_selected_workspace do
    parent = current_obj.parent
    @redirect_to = parent ? scrivito_path(parent) : "/"
    current_obj.destroy
  end
end

#detailsObject



39
40
41
42
# File 'app/controllers/scrivito/objs_controller.rb', line 39

def details
  assert_dialog_layout
  render current_obj.details_view_path, layout: 'scrivito_dialog', formats: :html
end

#page_class_selectionObject



106
107
108
109
110
# File 'app/controllers/scrivito/objs_controller.rb', line 106

def page_class_selection
  @page_class_markup = valid_page_classes.map do |page_class_name|
    build_selection_option(page_class_name)
  end
end

#restoreObject



68
69
70
71
# File 'app/controllers/scrivito/objs_controller.rb', line 68

def restore
  in_selected_workspace { Obj.restore(params[:id]) }
  render_empty_json
end

#restore_widgetObject



73
74
75
76
# File 'app/controllers/scrivito/objs_controller.rb', line 73

def restore_widget
  in_selected_workspace { current_obj.restore_widget(params[:widget_id]) }
  render_empty_json
end

#revertObject



58
59
60
61
# File 'app/controllers/scrivito/objs_controller.rb', line 58

def revert
  in_selected_workspace { current_obj.revert }
  render_empty_json
end

#revert_widgetObject



63
64
65
66
# File 'app/controllers/scrivito/objs_controller.rb', line 63

def revert_widget
  in_selected_workspace { current_widget.revert }
  render_empty_json
end

#searchObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/controllers/scrivito/objs_controller.rb', line 120

def search
  in_selected_workspace do
    @query = MultiJson.decode(params[:query]).with_indifferent_access
    @enumerator = ObjSearchBuilder.new(@query).build

    if params[:query_action] == 'size'
      return render action: 'search/size'
    end

    unless @formatter = fetch_formatter(@query[:format])
      return render action: 'search/missing_formatter', status: :not_found
    end

    if facet_params = params[:facet]
      attribute, options = MultiJson.decode(facet_params).values_at('attribute', 'options')
      @facets = @enumerator.facet(attribute, options || {})
      return render action: 'search/facet'
    end

    @batch = @enumerator.fetch_batch(params[:continuation])
    render :search
  end
end

#showObject



20
21
22
# File 'app/controllers/scrivito/objs_controller.rb', line 20

def show
  in_selected_workspace { render }
end

#transfer_modificationsObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/scrivito/objs_controller.rb', line 90

def transfer_modifications
  in_selected_workspace do
    begin
      obj = Obj.find_including_deleted(params[:id])
      workspace = Workspace.find(params[:workspace_id])
      authorize_workspace_access(:write, workspace) do
        obj.transfer_modifications_to(workspace)
      end
    rescue TransferModificationsModifiedError
      @error_reason = :modified
    rescue TransferModificationsConflictError
      @error_reason = :conflict
    end
  end
end

#updateObject



44
45
46
47
48
# File 'app/controllers/scrivito/objs_controller.rb', line 44

def update
  params_parser = ObjUpdateParamsParser.new(request.host, request.port,
    current_obj: current_obj, scrivito_user: scrivito_user)
  current_obj.update(params_parser.parse(params[:obj]))
end

#widgetObject



24
25
26
# File 'app/controllers/scrivito/objs_controller.rb', line 24

def widget
  in_selected_workspace { render }
end

#widget_class_selectionObject



112
113
114
115
116
117
118
# File 'app/controllers/scrivito/objs_controller.rb', line 112

def widget_class_selection
  load_obj

  @widgets_classes = valid_widget_classes.map do |widget_class_name|
    build_selection_option(widget_class_name)
  end
end