diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/exports_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/stop_area_copies_controller.rb | 39 | ||||
| -rw-r--r-- | app/models/stop_area_copy.rb | 50 | ||||
| -rw-r--r-- | app/views/exports/_export.erb | 4 | ||||
| -rw-r--r-- | app/views/stop_area_copies/_form.html.erb | 24 | ||||
| -rw-r--r-- | app/views/stop_area_copies/create.html.erb | 1 | ||||
| -rw-r--r-- | app/views/stop_area_copies/new.html.erb | 1 | ||||
| -rw-r--r-- | app/views/stop_areas/show.html.erb | 22 |
8 files changed, 132 insertions, 11 deletions
diff --git a/app/controllers/exports_controller.rb b/app/controllers/exports_controller.rb index 8805c8078..ed2ecd329 100644 --- a/app/controllers/exports_controller.rb +++ b/app/controllers/exports_controller.rb @@ -14,7 +14,7 @@ class ExportsController < ChouetteController def create create! do |success, failure| available_exports - success.html { flash[:notice] = I18n.t('exports.new.flash'); redirect_to referential_exports_path(@referential) } + success.html { flash[:notice] = I18n.t('exports.new.flash')+"<br/>"+I18n.t('exports.new.flash2'); redirect_to referential_exports_path(@referential) } end end diff --git a/app/controllers/stop_area_copies_controller.rb b/app/controllers/stop_area_copies_controller.rb new file mode 100644 index 000000000..01dfc5894 --- /dev/null +++ b/app/controllers/stop_area_copies_controller.rb @@ -0,0 +1,39 @@ +class StopAreaCopiesController < ChouetteController + belongs_to :referential do + belongs_to :stop_area, :parent_class => Chouette::StopArea + end + + actions :new, :create + respond_to :html, :only => :new + + def new + @stop_area_copy = StopAreaCopy.new(:source_id => parent.id, :hierarchy => params[:hierarchy]) + if @stop_area_copy.hierarchy == "child" + if parent.area_type.underscore == "stop_place" + @stop_area_copy.area_type="commercial_stop_point" + else + @stop_area_copy.area_type="boarding_position" + end + else + if parent.area_type.underscore == "stop_place" || parent.area_type.underscore == "commercial_stop_point" + @stop_area_copy.area_type="stop_place" + else + @stop_area_copy.area_type="commercial_stop_point" + end + end + new! + end +# TODO + def create + @stop_area_copy = StopAreaCopy.new(params[:stop_area_copy]) + if @stop_area_copy.save + redirect_to referential_stop_area_path( @referential,parent ), notice: I18n.t("stop_area_copies.new.success") + else + flash[:error] = I18n.t("stop_area_copies.errors.copy_aborted") + "<br>" + @stop_area_copy.errors.full_messages.join("<br>") + render :action => :new + end + end + + protected + +end diff --git a/app/models/stop_area_copy.rb b/app/models/stop_area_copy.rb new file mode 100644 index 000000000..fb661cf79 --- /dev/null +++ b/app/models/stop_area_copy.rb @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +class StopAreaCopy + include ActiveModel::Validations + include ActiveModel::Conversion + extend ActiveModel::Naming + + attr_accessor :source_id, :hierarchy, :area_type + + validates_presence_of :source_id, :hierarchy, :area_type + + def initialize(attributes = {}) + attributes.each { |name, value| send("#{name}=", value) } if attributes + end + + def persisted? + false + end + + def save + begin + if self.valid? + source = Chouette::StopArea.find self.source_id + copy = source.duplicate + copy.name = source.name + copy.area_type = self.area_type.camelcase + # TODO: check area_type validity + Chouette::StopArea.transaction do + if self.hierarchy == "child" + copy.parent_id = source.id + end + copy.save + if self.hierarchy == "parent" + source.parent_id = copy.id + source.save + end + end + true + else + false + end + rescue Exception => exception + Rails.logger.error(exception.message) + errors.add :base, I18n.t("stop_area_copy.errors.exception") + false + end + end + + +end diff --git a/app/views/exports/_export.erb b/app/views/exports/_export.erb index a307d856b..2bda5e4c5 100644 --- a/app/views/exports/_export.erb +++ b/app/views/exports/_export.erb @@ -10,11 +10,13 @@ <li class="remove"><%= link_to "<i class='fa fa-trash-o'></i>".html_safe, referential_export_path(@referential, export), :method => :delete, :data => {:confirm => t('exports.actions.destroy_confirm')}, :class => "remove" %></li> </ul> <div class="history"> - <%= t("exports.statuses.#export.status}") %> + <%= t("exports.statuses.#{export.status}") %> </div> <div class="links"> <% if export.status == 'completed' %> <%= link_to t("exports.actions.download"), referential_export_path(@referential, export, :format => :zip), :class => "download" %> + <% else %> + <% end %> </div> <div class="history"> diff --git a/app/views/stop_area_copies/_form.html.erb b/app/views/stop_area_copies/_form.html.erb new file mode 100644 index 000000000..5ac6fb345 --- /dev/null +++ b/app/views/stop_area_copies/_form.html.erb @@ -0,0 +1,24 @@ +<%= title_tag t("stop_area_copies.new.title."+@stop_area_copy.hierarchy) %> + +<%= semantic_form_for [@referential, @stop_area, @stop_area_copy] do |form| %> + <br> + <%= form.inputs do %> + <%= form.input :source_id , :as => :hidden%> + <%= form.input :hierarchy , :as => :hidden%> + <% if @stop_area_copy.hierarchy == "child"%> + <% if @stop_area.area_type.underscore == "stop_place"%> + <%= form.input :area_type, :as => :select, :input_html => { :disabled => true }, :collection => [@stop_area_copy.area_type], :include_blank => false, :member_label => Proc.new { |stop_area_type| t("area_types.label.#{stop_area_type}") } %> + <%= form.input :area_type , :as => :hidden%> + <% else%> + <%= form.input :area_type, :as => :select, :collection => ["boarding_position","quay"], :include_blank => false, :member_label => Proc.new { |stop_area_type| t("area_types.label.#{stop_area_type}") } %> + <% end %> + <% else %> + <%= form.input :area_type, :as => :select, :input_html => { :disabled => true }, :collection => [@stop_area_copy.area_type], :include_blank => false, :member_label => Proc.new { |stop_area_type| t("area_types.label.#{stop_area_type}") } %> + <%= form.input :area_type , :as => :hidden%> + <% end %> + <% end %> + <%= form.actions do %> + <%= form.action :submit, :as => :button , :label => t( 'formtastic.duplicate' ) %> + <%= form.action :cancel, :as => :link %> + <% end %> +<% end %> diff --git a/app/views/stop_area_copies/create.html.erb b/app/views/stop_area_copies/create.html.erb new file mode 100644 index 000000000..3e3151812 --- /dev/null +++ b/app/views/stop_area_copies/create.html.erb @@ -0,0 +1 @@ +<%= render "form" %>
\ No newline at end of file diff --git a/app/views/stop_area_copies/new.html.erb b/app/views/stop_area_copies/new.html.erb new file mode 100644 index 000000000..3e3151812 --- /dev/null +++ b/app/views/stop_area_copies/new.html.erb @@ -0,0 +1 @@ +<%= render "form" %>
\ No newline at end of file diff --git a/app/views/stop_areas/show.html.erb b/app/views/stop_areas/show.html.erb index dc2e60349..6659b703f 100644 --- a/app/views/stop_areas/show.html.erb +++ b/app/views/stop_areas/show.html.erb @@ -116,25 +116,29 @@ <ul class="actions"> <li><%= link_to t('stop_areas.actions.new'), new_referential_stop_area_path(@referential), :class => "add" %></li> <li><%= link_to t('stop_areas.actions.edit'), edit_referential_stop_area_path(@referential, @stop_area), :class => "edit" %></li> - <li><%= link_to t('stop_areas.actions.destroy'), referential_stop_area_path(@referential, @stop_area), :method => :delete, :data => {:confirm => t('stop_areas.actions.destroy_confirm')}, :class => "remove" %></li> + <li><%= link_to t('stop_areas.actions.destroy'), referential_stop_area_path(@referential, @stop_area), :method => :delete, :data => {:confirm => t('stop_areas.actions.destroy_confirm')}, :class => "remove" %></li> </ul> </td></tr> <% if manage_itl %> <tr><td> <h4><%= t(".itl_managment") %></h4> <ul class="actions"> - <li><%= link_to t('stop_areas.actions.add_routing_lines'), add_routing_lines_referential_stop_area_path(@referential, @stop_area), :class => "add_routing_lines" %></li> - <li><%= link_to t('stop_areas.actions.add_routing_stops'), add_routing_stops_referential_stop_area_path(@referential, @stop_area), :class => "add_routing_stops" %></li> + <li><%= link_to t('stop_areas.actions.add_routing_lines'), add_routing_lines_referential_stop_area_path(@referential, @stop_area), :class => "add_routing_lines" %></li> + <li><%= link_to t('stop_areas.actions.add_routing_stops'), add_routing_stops_referential_stop_area_path(@referential, @stop_area), :class => "add_routing_stops" %></li> </ul> </td></tr> <% else %> <tr><td> <h4><%= t(".stop_managment") %></h4> <ul class="actions"> - <li><%= link_to t('stop_areas.actions.select_parent'), select_parent_referential_stop_area_path(@referential, @stop_area), :class => "select_parent" %></li> - <% if manage_children %> - <li><%= link_to t('stop_areas.actions.add_children'), add_children_referential_stop_area_path(@referential, @stop_area), :class => "add_children" %></li> - <% end %> + <li><font color="#D98F3B"><i class="fa fa-arrow-up fa-fw"></i></font><%= link_to t('stop_areas.actions.select_parent'), select_parent_referential_stop_area_path(@referential, @stop_area), :class => "with_fa" %></li> + <% if @stop_area.parent == nil %> + <li><font color="green"><i class="fa fa-files-o fa-fw"></i></font><%= link_to t('stop_areas.actions.clone_as_parent'), new_referential_stop_area_stop_area_copy_path(@referential, @stop_area, :hierarchy => "parent"), :class => "with_fa" %></li> + <% end %> + <% if manage_children %> + <li><font color="#D98F3B"><i class="fa fa-sitemap fa-fw"></i></font><%= link_to t('stop_areas.actions.add_children'), add_children_referential_stop_area_path(@referential, @stop_area), :class => "with_fa" %></li> + <li><font color="green"><i class="fa fa-files-o fa-fw"></i></font><%= link_to t('stop_areas.actions.clone_as_child'), new_referential_stop_area_stop_area_copy_path(@referential, @stop_area, :hierarchy => "child"), :class => "with_fa" %></li> + <% end %> </ul> </td></tr> @@ -142,8 +146,8 @@ <tr><td> <h4><%= t(".access_managment") %></h4> <ul class="actions"> - <li><%= link_to t('access_points.actions.new'), new_referential_stop_area_access_point_path(@referential,@stop_area), :class => "add" %></li> - <li><%= link_to t('stop_areas.actions.manage_access_links'), access_links_referential_stop_area_path(@referential,@stop_area), :class => "select_parent" %></li> + <li><font color="green"><i class="fa fa-caret-square-o-right fa-fw"></i></font><%= link_to t('access_points.actions.new'), new_referential_stop_area_access_point_path(@referential,@stop_area), :class => "with_fa" %></li> + <li><font color="#D98F3B"><i class="fa fa-arrows-alt fa-fw"></i></font><%= link_to t('stop_areas.actions.manage_access_links'), access_links_referential_stop_area_path(@referential,@stop_area), :class => "with_fa" %></li> </ul> </td></tr> <% end %> |
