diff options
Diffstat (limited to 'app/controllers/referentials_controller.rb')
| -rw-r--r-- | app/controllers/referentials_controller.rb | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index afd376092..c8984076a 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -7,17 +7,19 @@ class ReferentialsController < BreadcrumbController respond_to :js, :only => :show def new - if params[:from] - source_referential = Referential.find(params[:from]) - @referential = Referential.new_from(source_referential) + new! do + build_referenial end + end - new! do - @referential.data_format = current_organisation.data_format - @referential.workbench_id ||= params[:workbench_id] + def create + create! do |format| + build_referenial - if @referential.in_workbench? - @referential.init_metadatas default_date_range: Range.new(Date.today, Date.today.advance(months: 1)) + if !!@referential.created_from_id + format.html { redirect_to workbench_path(@referential.workbench) } + else + build_breadcrumb :new end end end @@ -25,7 +27,7 @@ class ReferentialsController < BreadcrumbController def show resource.switch show! do |format| - @referential = @referential.decorate + @referential = @referential.decorate(context: { current_workbench_id: params[:current_workbench_id] } ) @reflines = lines_collection.paginate(page: params[:page], per_page: 10) @reflines = ModelDecorator.decorate( @reflines, @@ -123,6 +125,21 @@ class ReferentialsController < BreadcrumbController super end + def build_referenial + if params[:from] + source_referential = Referential.find(params[:from]) + @referential = Referential.new_from(source_referential, current_functional_scope) + @referential.workbench_id = params[:current_workbench_id] + end + + @referential.data_format = current_organisation.data_format + @referential.workbench_id ||= params[:workbench_id] + + if @referential.in_workbench? + @referential.init_metadatas default_date_range: Range.new(Date.today, Date.today.advance(months: 1)) + end + end + private def sort_column sortable_columns = Chouette::Line.column_names + ['networks.name', 'companies.name'] |
