|
|
|
@ -9,15 +9,10 @@ class BoardsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def show
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
board = @course.course_board
|
|
|
|
|
new_board = Board.new(board_params)
|
|
|
|
|
new_board.course_id = @course.id
|
|
|
|
@ -25,30 +20,28 @@ class BoardsController < ApplicationController
|
|
|
|
|
new_board.parent_id = board.try(:id)
|
|
|
|
|
new_board.position = board.children.count + 1
|
|
|
|
|
new_board.save!
|
|
|
|
|
normal_status(0, "添加成功")
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger_error(e.message)
|
|
|
|
|
tip_exception(e.message)
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
normal_status(0, "添加成功")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 子目录的拖动
|
|
|
|
|
def move_category
|
|
|
|
|
tip_exception("移动失败") if params[:position].blank?
|
|
|
|
|
unless params[:position].to_i == @board.position
|
|
|
|
|
return normal_status(-1, "位置没有变化") if params[:position].to_i == @board.position
|
|
|
|
|
|
|
|
|
|
course_board = @course.course_board
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
if params[:position].to_i < @board.position
|
|
|
|
|
course_board.children.where("position < #{@board.position} and position >= ?", params[:position]).update_all("position = position + 1")
|
|
|
|
|
course_board.children.where("position < ? and position >= ?", @board.position, params[:position])
|
|
|
|
|
.update_all("position = position + 1")
|
|
|
|
|
else
|
|
|
|
|
course_board.children.where("position > #{@board.position} and position <= ?", params[:position]).update_all("position = position - 1")
|
|
|
|
|
course_board.children.where("position > ? and position <= ?", @board.position, params[:position])
|
|
|
|
|
.update_all("position = position - 1")
|
|
|
|
|
end
|
|
|
|
|
@board.update_attributes(position: params[:position])
|
|
|
|
|
normal_status(0, "移动成功")
|
|
|
|
|
else
|
|
|
|
|
normal_status(-1, "位置没有变化")
|
|
|
|
|
end
|
|
|
|
|
normal_status(0, "移动成功")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|