Module: KirguduBase::Controllers::ContainerItemsSortingActions::InstanceMethods

Defined in:
app/helpers/kirgudu_base/controllers/container_items_sorting_actions.rb

Instance Method Summary collapse

Instance Method Details

#sorting_items_indexObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/helpers/kirgudu_base/controllers/container_items_sorting_actions.rb', line 14

def sorting_items_index
  @container= get_managing_container_class.find(params[get_managing_parent_id_key])
  @items = get_managing_item_class.where(container_id: @container.id).order(:sort_position)


  views_path = get_managing_views_path if self.respond_to?(:get_managing_views_path)
  unless views_path
    views_path = "/shared/manage_items/"
  end

  respond_to do |format|
    format.html { render_html1("#{views_path}managing_items_sort_index") }
    format.json { render json: @products }
  end
end

#sorting_items_processObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/helpers/kirgudu_base/controllers/container_items_sorting_actions.rb', line 30

def sorting_items_process
  container = get_managing_container_class.find(params[get_managing_parent_id_key])
  unless container
    render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('set_not_found'), message: I18n.t("#{self.to_i18n}.sorting.messages.set_not_found", id: params[:id])}
    return
  end

  result_is_ok = false
  if params[:items]
    begin
      ActiveRecord::Base.transaction do
        params[:items].each_with_index do |id, index|
          item = get_managing_item_class.where(container_id: container.id, entry_id: id).first
          if item
            item.sort_position = index + 1
            if item.respond_to?(:updated_by)
              item.updated_by = @current_user.id
            end
            item.save
          end
        end
        result_is_ok = true
      end
    end
  end
  if result_is_ok == true
    render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('management_ok'), message: I18n.t("#{self.to_i18n}.sorting.messages.management_ok")}
  else
    render json: {status: ::ChupakabraTools::SetManagementResult.id_by_tag('management_error'), message: I18n.t("#{self.to_i18n}.sorting.messages.management_error")}
  end
end