Sha256: 9b5aea94d562abb85c86a351b51ae8b4df76938b9fa639936f13ffb7b0e530ba
Contents?: true
Size: 1.99 KB
Versions: 20
Compression:
Stored size: 1.99 KB
Contents
# -*- encoding : utf-8 -*- module KirguduBase module Controllers module ContainerItemsSortingActions def self.included(base) base.class_eval do include InstanceMethods end end module InstanceMethods 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 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 end end end end
Version data entries
20 entries across 20 versions & 1 rubygems