diff options
| -rw-r--r-- | app/controllers/referentials_controller.rb | 8 | ||||
| -rw-r--r-- | app/models/referential.rb | 23 | ||||
| -rw-r--r-- | app/views/referentials/_form.html.slim | 2 |
3 files changed, 32 insertions, 1 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index 4ffb6ad65..3ae59f975 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -7,6 +7,7 @@ class ReferentialsController < BreadcrumbController respond_to :js, :only => :show def new + @referential = Referential.new_from(Referential.find(params[:from])) if params[:from] new! do @referential.data_format = current_organisation.data_format end @@ -56,7 +57,11 @@ class ReferentialsController < BreadcrumbController end def create_resource(referential) - referential.organisation = current_organisation + if referential.created_from + referential.clone_association referential.created_from + else + referential.organisation = current_organisation + end super end @@ -74,6 +79,7 @@ class ReferentialsController < BreadcrumbController :projection_type, :data_format, :archived_at, + :created_from_id, referential_metadata_attributes: [:referential_source_id, :line_ids => []] ) end diff --git a/app/models/referential.rb b/app/models/referential.rb index 9612b1022..da5791914 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -29,6 +29,7 @@ class Referential < ActiveRecord::Base belongs_to :line_referential validates_presence_of :line_referential + belongs_to :created_from, class_name: 'Referential' has_many :lines, through: :line_referential has_many :companies, through: :line_referential has_many :group_of_lines, through: :line_referential @@ -112,6 +113,28 @@ class Referential < ActiveRecord::Base self end + def self.new_from from + Referential.new({ + name: "Copie de #{from.name}", + slug: "#{from.slug}_clone", + prefix: from.prefix, + time_zone: from.time_zone, + bounds: from.bounds, + organisation: from.organisation, + line_referential: from.line_referential, + stop_area_referential: from.stop_area_referential, + workbench: from.workbench, + created_from: from, + }) + end + + def clone_association from + self.organisation = from.organisation + self.line_referential = from.line_referential + self.stop_area_referential = from.stop_area_referential + self.workbench = from.workbench + end + def self.available_srids [ [ "RGF 93 Lambert 93 (2154)", 2154 ], diff --git a/app/views/referentials/_form.html.slim b/app/views/referentials/_form.html.slim index dd426f426..c1d9fc84d 100644 --- a/app/views/referentials/_form.html.slim +++ b/app/views/referentials/_form.html.slim @@ -15,6 +15,8 @@ = form.input :upper_corner, input_html: { title: t("formtastic.titles.referential.upper_corner") } = form.input :lower_corner, input_html: { title: t("formtastic.titles.referential.lower_corner") } = form.input :data_format, label: true, include_blank: false + - if @referential.created_from + = form.input :created_from = form.inputs for: [:referential_metadata, @referential.referential_metadata] do |meta| = meta.inputs :referential_source |
