Class: Binda::StructuresController

Inherits:
ApplicationController show all
Defined in:
app/controllers/binda/structures_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

#add_field_groupObject



66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/binda/structures_controller.rb', line 66

def add_field_group
  # We set some default values in order to be able to save the field setting
  # (if field setting isn't save it makes impossible to sort the order)
  @field_group = FieldGroup.new(
    name: "#{I18n.t('binda.field_group.new')}",
    structure_id: @structure.id
  )
  @field_group.save!
  render 'binda/structures/_form_new_field_group_item', layout: false
end

#createObject



22
23
24
25
26
27
28
29
30
# File 'app/controllers/binda/structures_controller.rb', line 22

def create
  @structure = Structure.new(structure_params)

  if @structure.save
    redirect_to structure_path( @structure.slug ), notice: "#{ @structure.name.capitalize } structure was successfully created."
  else
    render :new
  end
end

#destroyObject



41
42
43
44
# File 'app/controllers/binda/structures_controller.rb', line 41

def destroy
  @structure.destroy
  redirect_to structures_url, notice: "#{ @structure.name.capitalize } structure was successfully destroyed."
end

#editObject



19
20
# File 'app/controllers/binda/structures_controller.rb', line 19

def edit
end

#fields_updateObject



46
47
48
# File 'app/controllers/binda/structures_controller.rb', line 46

def fields_update
  redirect_to :back, notice: "#{ @structure.name.capitalize } structure was successfully updated."
end

#indexObject



7
8
9
# File 'app/controllers/binda/structures_controller.rb', line 7

def index
  @structures = Structure.order('position').all.page params[:page]
end

#newObject



15
16
17
# File 'app/controllers/binda/structures_controller.rb', line 15

def new
  @structure = Structure.new
end

#showObject



11
12
13
# File 'app/controllers/binda/structures_controller.rb', line 11

def show
  redirect_to action: :edit
end

#sortObject



50
51
52
53
54
55
# File 'app/controllers/binda/structures_controller.rb', line 50

def sort
  params[:structure].each_with_index do |id, i|
    Structure.find( id ).update({ position: i })
  end
  render js: "$('##{params[:id]}').sortable('option', 'disabled', false); $('.popup-warning').addClass('popup-warning--hidden'); $('.sortable').removeClass('sortable--disabled')"
end

#sort_field_groupsObject



61
62
63
64
# File 'app/controllers/binda/structures_controller.rb', line 61

def sort_field_groups
  sort_field_group_by(params["form--list-item"])
  render json: { id: "##{params[:id]}" }, status: 200
end

#sort_indexObject



57
58
59
# File 'app/controllers/binda/structures_controller.rb', line 57

def sort_index
  @structures = Structure.order('position').all.page params[:page]
end

#updateObject



32
33
34
35
36
37
38
39
# File 'app/controllers/binda/structures_controller.rb', line 32

def update
  # Update the other ones
  if @structure.update(structure_params)
    redirect_to structure_path( @structure.slug ), notice: "#{ @structure.name.capitalize } structure was successfully updated."
  else
    render :edit
  end
end