80 lines
1.8 KiB
Ruby
80 lines
1.8 KiB
Ruby
|
class Admin::SpacesController < OrbitAdminController
|
||
|
|
||
|
def index
|
||
|
@buildings = Building.all
|
||
|
end
|
||
|
|
||
|
def new
|
||
|
@building = Building.new
|
||
|
end
|
||
|
|
||
|
def create
|
||
|
building = Building.new(building_params)
|
||
|
building.save
|
||
|
redirect_to admin_spaces_path
|
||
|
end
|
||
|
|
||
|
def floors
|
||
|
uid = params[:space_id].split("-").last
|
||
|
@building = Building.find_by(:uid => uid) rescue nil
|
||
|
@table_fields = [:title, :action]
|
||
|
end
|
||
|
|
||
|
def add_floor
|
||
|
building = Building.find(params[:building_id])
|
||
|
floor = Floor.new(floor_params)
|
||
|
floor.building = building
|
||
|
floor.save
|
||
|
redirect_to "/admin/spaces/#{building.to_param}/floors"
|
||
|
end
|
||
|
|
||
|
def update_floor
|
||
|
floor = Floor.find(params[:floor_id]) rescue nil
|
||
|
floor.update_attributes(floor_params)
|
||
|
floor.save
|
||
|
redirect_to "/admin/spaces/#{floor.building.to_param}/floors"
|
||
|
|
||
|
end
|
||
|
|
||
|
def floor_layout
|
||
|
@floor = Floor.find_by(:uid => params[:floor_id].split("-").last)
|
||
|
end
|
||
|
|
||
|
def delete_floor
|
||
|
floor = Floor.find_by(:uid => params[:floor_id].split("-").last)
|
||
|
floor.destroy
|
||
|
render :json => {"success" => true}.to_json
|
||
|
end
|
||
|
|
||
|
def add_floor_unit
|
||
|
@floor_unit = FloorUnit.new
|
||
|
@floor = Floor.find_by(:uid => params[:floor_id].split("-").last)
|
||
|
end
|
||
|
|
||
|
def create_floor_unit
|
||
|
floor_unit = FloorUnit.new(floor_unit_params)
|
||
|
floor_unit.save
|
||
|
respond_to do |format|
|
||
|
format.html {redirect_to "/admin/spaces/#{floor_unit.floor.building.to_param}/#{floor_unit.floor.to_param}/units"}
|
||
|
format.js {render :json => {"success" => true, "unit" => {"id" => floor_unit.id.to_s, "title" => floor_unit.title}}.to_json}
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def units
|
||
|
@floor = Floor.find_by(:uid => params[:floor_id].split("-").last)
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def floor_params
|
||
|
params.require(:floor).permit!
|
||
|
end
|
||
|
|
||
|
def building_params
|
||
|
params.require(:building).permit!
|
||
|
end
|
||
|
|
||
|
def floor_unit_params
|
||
|
params.require(:floor_unit).permit!
|
||
|
end
|
||
|
end
|