aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinhui2016-10-24 15:24:02 +0200
committerXinhui2016-10-24 15:24:02 +0200
commit45c6a1a9d775546e5543bf7bfb2dffd485bf1f0a (patch)
tree210ab85be8c71940fc65a2264de10e67d3508f71
parent2df352163e6987c93273df27e46ad6b07cff8a68 (diff)
downloadchouette-core-45c6a1a9d775546e5543bf7bfb2dffd485bf1f0a.tar.bz2
Referential new_from method
Refs #1863
-rw-r--r--app/controllers/referentials_controller.rb8
-rw-r--r--app/models/referential.rb23
-rw-r--r--app/views/referentials/_form.html.slim2
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