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
|