Class: Binda::FieldGroupsController
Instance Method Summary
collapse
#after_sign_in_path_for, #after_sign_out_path_for, #set_locale
Instance Method Details
#add_field_setting ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'app/controllers/binda/field_groups_controller.rb', line 70
def add_field_setting
@field_setting = FieldSetting.new(
name: "#{I18n.t('binda.field_setting.new')}",
field_group_id: @field_group.id,
field_type: 'string',
ancestry: params[:ancestry]
)
@field_setting.save!
render 'binda/field_groups/_form_new_item', layout: false
end
|
#create ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'app/controllers/binda/field_groups_controller.rb', line 23
def create
@field_group = @structure.field_groups.build(field_group_params)
if @field_group.save
reset_field_settings_cache
redirect_to structure_field_group_path( @structure.slug, @field_group.slug ), notice: 'Field group was successfully created.'
else
redirect_to new_structure_field_group_path( @structure.slug ), flash: { alert: @field_group.errors }
end
end
|
#destroy ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'app/controllers/binda/field_groups_controller.rb', line 48
def destroy
@field_group.destroy!
reset_field_settings_cache
if params[:isAjax]
render json: { target_id: params[:target_id] }, status: 200
else
redirect_to structure_path( @structure.slug ), notice: 'Field group was successfully destroyed along with all dependents.'
end
end
|
#edit ⇒ Object
20
21
|
# File 'app/controllers/binda/field_groups_controller.rb', line 20
def edit
end
|
#index ⇒ Object
8
9
10
|
# File 'app/controllers/binda/field_groups_controller.rb', line 8
def index
redirect_to structure_field_group_path( @structure.slug )
end
|
#new ⇒ Object
16
17
18
|
# File 'app/controllers/binda/field_groups_controller.rb', line 16
def new
@field_group = @structure.field_groups.build()
end
|
#show ⇒ Object
12
13
14
|
# File 'app/controllers/binda/field_groups_controller.rb', line 12
def show
redirect_to action: :edit
end
|
#sort ⇒ Object
58
59
60
61
62
63
|
# File 'app/controllers/binda/field_groups_controller.rb', line 58
def sort
params[:field_group].each_with_index do |id, i|
FieldGroup.find( id ).update_column('position', i+1) end
render json: { id: "##{params[:id]}" }, status: 200
end
|
#sort_field_settings ⇒ Object
65
66
67
68
|
# File 'app/controllers/binda/field_groups_controller.rb', line 65
def sort_field_settings
sort_field_setting_by(params["form--list-item"])
render json: { id: "##{params[:id]}" }, status: 200
end
|
#update ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/controllers/binda/field_groups_controller.rb', line 34
def update
add_new_choices
check_if_needs_to_update_choices
if @field_group.update(field_group_params)
reset_field_settings_cache
redirect_to structure_field_group_path( @structure.slug, @field_group.slug ), notice: 'Field group was successfully updated.'
else
redirect_to edit_structure_field_group_path( @structure.slug, @field_group.slug ), flash: { alert: @field_group.errors }
end
end
|