Class: Binda::FieldSettingsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/binda/field_settings_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #after_sign_out_path_for, #set_locale

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
# File 'app/controllers/binda/field_settings_controller.rb', line 24

def create
  @field_setting = @field_group.field_settings.build(field_setting_params)

  if @field_setting.save
    redirect_to structure_field_group_field_setting_path( @structure, @field_group, @field_setting ), notice: 'Field setting was successfully created.'
  else
    redirect_to new_structure_field_group_field_setting_path( @structure, @field_group ), flash: { alert: @field_setting.errors }
  end
end

#destroyObject



42
43
44
45
46
47
48
49
50
# File 'app/controllers/binda/field_settings_controller.rb', line 42

def destroy
  @field_setting.destroy!
  FieldSetting.reset_field_settings_array
  if params[:isAjax]
    render json: { target_id: params[:target_id] }, status: 200
  else
    redirect_to structure_field_group_path( @structure, @field_group ), notice: 'Field setting and all dependent content were successfully destroyed.'
  end
end

#editObject



21
22
# File 'app/controllers/binda/field_settings_controller.rb', line 21

def edit
end

#indexObject



9
10
11
# File 'app/controllers/binda/field_settings_controller.rb', line 9

def index
  @field_settings = @field_group.field_settings.order('position').all
end

#newObject



17
18
19
# File 'app/controllers/binda/field_settings_controller.rb', line 17

def new
  @field_setting = @field_group.field_settings.build()
end

#showObject



13
14
15
# File 'app/controllers/binda/field_settings_controller.rb', line 13

def show
  redirect_to action: :edit
end

#sortObject



52
53
54
55
56
57
# File 'app/controllers/binda/field_settings_controller.rb', line 52

def sort
  params[:field_setting].each_with_index do |id, i|
    FieldSetting.find( id ).update_column('position', i+1) # use update_column to skip callbacks (which leads to huge useless memory consumption)
  end
  render json: { id: "##{params[:id]}" }, status: 200
end

#updateObject



34
35
36
37
38
39
40
# File 'app/controllers/binda/field_settings_controller.rb', line 34

def update
  if @field_setting.update(field_setting_params)
    redirect_to structure_field_group_field_setting_path( @structure, @field_group, @field_setting ), notice: 'Field setting was successfully updated.'
  else
    redirect_to edit_structure_field_group_field_setting_path( @structure, @field_group, @field_setting ), flash: { alert: @field_setting.errors }
  end
end