Class: Integral::Backend::ListsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/integral/backend/lists_controller.rb

Overview

List controller

Instance Method Summary collapse

Instance Method Details

#cloneObject

GET /:id/clone Clone a list



56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/integral/backend/lists_controller.rb', line 56

def clone
  title = params[:title].present? ? params[:title] : "#{@list.title} Copy"
  title = "#{title} #{SecureRandom.hex[1..5]}" if Integral::List.find_by_title(title).present?

  cloned_list = @list.dup(title)

  if cloned_list.save
    respond_successfully(notification_message('creation_success'), backend_list_path(cloned_list))
  else
    respond_failure(notification_message('creation_failure'), @list, :edit)
  end
end

#createObject

POST / List creation



37
38
39
40
41
42
43
44
45
# File 'app/controllers/integral/backend/lists_controller.rb', line 37

def create
  @list = List.new(list_params)

  if @list.save
    respond_successfully(notification_message('creation_success'), backend_list_path(@list))
  else
    respond_failure(notification_message('creation_failure'), @list, :new)
  end
end

#destroyObject

DELETE /:id



80
81
82
83
84
85
86
87
88
# File 'app/controllers/integral/backend/lists_controller.rb', line 80

def destroy
  if @list.destroy
    respond_successfully(notification_message('delete_success'), backend_lists_path)
  else
    error_message = @list.errors.full_messages.to_sentence
    flash[:error] = "#{notification_message('delete_failure')} - #{error_message}"
    redirect_to backend_lists_path
  end
end

#editObject

GET /:id/edit List edit form



49
50
51
52
# File 'app/controllers/integral/backend/lists_controller.rb', line 49

def edit
  add_breadcrumb @list.title, :backend_list_path
  add_breadcrumb I18n.t('integral.breadcrumbs.edit'), :edit_backend_list_path
end

#indexObject

GET / Lists all lists



11
12
13
14
15
16
17
18
# File 'app/controllers/integral/backend/lists_controller.rb', line 11

def index
  respond_to do |format|
    format.html
    format.json do
      render json: { content: render_to_string(partial: 'integral/backend/lists/grid', locals: { grid: @grid }) }
    end
  end
end

#newObject

GET /new List creation form



30
31
32
33
# File 'app/controllers/integral/backend/lists_controller.rb', line 30

def new
  add_breadcrumb I18n.t('integral.breadcrumbs.new'), :new_backend_list_path
  @list = List.new
end

#showObject

GET /:id



21
22
23
24
25
26
# File 'app/controllers/integral/backend/lists_controller.rb', line 21

def show
  @list = List.find(params[:id])
  @list.list_items.order(:priority)

  add_breadcrumb @list.title, :backend_list_path
end

#updateObject

PUT /:id Updating an list



71
72
73
74
75
76
77
# File 'app/controllers/integral/backend/lists_controller.rb', line 71

def update
  if @list.update(list_params)
    respond_successfully(notification_message('edit_success'), backend_list_path(@list))
  else
    respond_failure(notification_message('edit_failure'), @list, :show)
  end
end