diff --git a/app/controllers/admin/spaces_controller.rb b/app/controllers/admin/spaces_controller.rb index 61bc34c..e0c3a39 100644 --- a/app/controllers/admin/spaces_controller.rb +++ b/app/controllers/admin/spaces_controller.rb @@ -8,12 +8,27 @@ class Admin::SpacesController < OrbitAdminController @building = Building.new end + def edit + uid = params[:id].split("-").last + @building = Building.find_by(:uid => uid) rescue nil + end + def create building = Building.new(building_params) building.save redirect_to admin_spaces_path end + def update + uid = params[:id].split("-").last + building = Building.find_by(:uid => uid) rescue nil + if !building.nil? + building.update_attributes(building_params) + building.save + end + redirect_to admin_spaces_path + end + def floors uid = params[:space_id].split("-").last @building = Building.find_by(:uid => uid) rescue nil diff --git a/app/controllers/spaces_controller.rb b/app/controllers/spaces_controller.rb index 3d4e479..3c7fc8f 100644 --- a/app/controllers/spaces_controller.rb +++ b/app/controllers/spaces_controller.rb @@ -1,13 +1,15 @@ class SpacesController < ApplicationController def index - buildings = Building.all.collect do |building| + page = Page.where(:module => OrbitHelper.this_module_app.key).first + buildings = Building.filter_by_categories.collect do |building| floors = building.floors.desc(:title).collect do |floor| image = (!floor.frontend_image.thumb.url.nil? ? floor.frontend_image.thumb.url : "/assets/default-floor.jpg") + link = floor.layout.nil? ? (floor.floor_units.empty? ? "#" : "/#{I18n.locale.to_s}#{page.url}/#{floor.floor_units.first.to_param}?method=unit") : OrbitHelper.url_to_show(floor.to_param) { "floor-title" => floor.title, "floor-image" => image, "alt-title" => floor.title, - "link_to_show" => OrbitHelper.url_to_show(floor.to_param) + "link_to_show" => link } end { diff --git a/app/models/building.rb b/app/models/building.rb index 3948135..eadb93c 100644 --- a/app/models/building.rb +++ b/app/models/building.rb @@ -1,6 +1,7 @@ class Building include Mongoid::Document include Mongoid::Timestamps + include OrbitCategory::Categorizable include Slug field :title, as: :slug_title, localize: true diff --git a/app/views/admin/spaces/_building.html.erb b/app/views/admin/spaces/_building.html.erb index 12700e4..1738c7b 100644 --- a/app/views/admin/spaces/_building.html.erb +++ b/app/views/admin/spaces/_building.html.erb @@ -5,6 +5,6 @@
<%= building.title %>
\ No newline at end of file diff --git a/app/views/admin/spaces/_form.html.erb b/app/views/admin/spaces/_form.html.erb index feee94a..8bd5f61 100644 --- a/app/views/admin/spaces/_form.html.erb +++ b/app/views/admin/spaces/_form.html.erb @@ -20,11 +20,20 @@