diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/chouette/area_type.rb | 34 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 2 | ||||
| -rw-r--r-- | app/views/stop_areas/_filters.html.slim | 2 | ||||
| -rw-r--r-- | app/views/stop_areas/_form.html.slim | 2 | ||||
| -rw-r--r-- | app/views/stop_areas/index.html.slim | 2 | ||||
| -rw-r--r-- | app/views/stop_areas/show.html.slim | 2 |
6 files changed, 39 insertions, 5 deletions
diff --git a/app/models/chouette/area_type.rb b/app/models/chouette/area_type.rb new file mode 100644 index 000000000..183092e50 --- /dev/null +++ b/app/models/chouette/area_type.rb @@ -0,0 +1,34 @@ +class Chouette::AreaType + + ALL = %i(zdep zder zdlp zdlr lda).freeze + + @@all = ALL + mattr_accessor :all + + def self.all=(values) + @@all = ALL & values + + @@instances = {} + @@options = nil + end + + @@instances = {} + def self.find(code) + code = code.to_sym + @@instances[code] ||= new(code) if ALL.include? code + end + + def self.options + @@options ||= all.map { |c| find(c) }.map { |t| [ t.label, t.code ] } + end + + attr_reader :code + def initialize(code) + @code = code + end + + def label + I18n.translate code, scope: 'area_types.label' + end + +end diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index cc7170728..646976f71 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -9,7 +9,7 @@ module Chouette include ObjectidSupport extend Enumerize - enumerize :area_type, in: %i(zdep zder zdlp zdlr lda) + enumerize :area_type, in: Chouette::AreaType::ALL with_options dependent: :destroy do |assoc| assoc.has_many :stop_points diff --git a/app/views/stop_areas/_filters.html.slim b/app/views/stop_areas/_filters.html.slim index 3b99f377c..90368dff4 100644 --- a/app/views/stop_areas/_filters.html.slim +++ b/app/views/stop_areas/_filters.html.slim @@ -12,7 +12,7 @@ .form-group.togglable = f.label Chouette::StopArea.human_attribute_name(:area_type), required: false, class: 'control-label' - = f.input :area_type_eq_any, collection: Chouette::StopArea.area_type.options.sort, as: :check_boxes, label: false, label_method: lambda{|w| ("<span>" + t("enumerize.stop_area.area_type.#{w[1]}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' } + = f.input :area_type_eq_any, collection: Chouette::AreaType.options, as: :check_boxes, label: false, label_method: lambda{|w| ("<span>" + w[0] + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list' } .actions = link_to 'Effacer', @workbench, class: 'btn btn-link' diff --git a/app/views/stop_areas/_form.html.slim b/app/views/stop_areas/_form.html.slim index 20c7c0468..ac2cb4e87 100644 --- a/app/views/stop_areas/_form.html.slim +++ b/app/views/stop_areas/_form.html.slim @@ -6,7 +6,7 @@ /= @map.to_html = f.input :id, as: :hidden = f.input :name, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.name")} - = f.input :area_type, as: :select, :input_html => {:disabled => !@stop_area.new_record?}, :collection => Chouette::StopArea.area_type.options, :include_blank => false + = f.input :area_type, as: :select, :input_html => {:disabled => !@stop_area.new_record?}, :collection => Chouette::AreaType.options, :include_blank => false .location_info h3 = t("stop_areas.stop_area.localisation") diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim index c4d880081..710192635 100644 --- a/app/views/stop_areas/index.html.slim +++ b/app/views/stop_areas/index.html.slim @@ -48,7 +48,7 @@ ), \ TableBuilderHelper::Column.new( \ key: :area_type, \ - attribute: Proc.new { |s| (s.area_type.nil? ? '-' : t("enumerize.stop_area.area_type.#{s.try(:area_type)}")) } \ + attribute: Proc.new { |s| Chouette::AreaType.find(s.area_type).try :label } \ ), \ ], links: [:show, :edit, :delete], diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim index af673bb25..1b1209a68 100644 --- a/app/views/stop_areas/show.html.slim +++ b/app/views/stop_areas/show.html.slim @@ -17,7 +17,7 @@ .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), { t('id_reflex') => @stop_area.get_objectid.short_id, - @stop_area.human_attribute_name(:stop_area_type) => t("area_types.label.#{@stop_area.stop_area_type}"), + @stop_area.human_attribute_name(:stop_area_type) => Chouette::AreaType.find(@stop_area.area_type).try(:label), @stop_area.human_attribute_name(:registration_number) => @stop_area.registration_number, 'Coordonnées' => geo_data(@stop_area, @stop_area_referential), @stop_area.human_attribute_name(:zip_code) => @stop_area.zip_code, |
