diff options
| author | Zog | 2018-01-26 16:17:22 +0100 |
|---|---|---|
| committer | Zog | 2018-01-26 16:17:22 +0100 |
| commit | 22c38fb750843f0c74996175a6bd17a1f20a943c (patch) | |
| tree | ebf3b2213be01c64b418e0e5b47d1afc860cc962 /app | |
| parent | c1da45b2f561ab7ec8d2785bb53f25218e471ce2 (diff) | |
| download | chouette-core-22c38fb750843f0c74996175a6bd17a1f20a943c.tar.bz2 | |
Refs #5750 @1h; Add a "kind" attribute to StopAreas
This determines if the StopArea is commercial or not
The useless fields are hidden in the form for the non-commercials ones
Diffstat (limited to 'app')
| -rw-r--r-- | app/assets/stylesheets/components/_forms.sass | 8 | ||||
| -rw-r--r-- | app/javascript/helpers/master_slave.coffee | 18 | ||||
| -rw-r--r-- | app/javascript/packs/stop_areas/new.js | 3 | ||||
| -rw-r--r-- | app/models/chouette/area_type.rb | 25 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 9 | ||||
| -rw-r--r-- | app/views/stop_areas/_form.html.slim | 10 | ||||
| -rw-r--r-- | app/views/stop_areas/show.html.slim | 8 |
7 files changed, 67 insertions, 14 deletions
diff --git a/app/assets/stylesheets/components/_forms.sass b/app/assets/stylesheets/components/_forms.sass index b7f720963..214795b8b 100644 --- a/app/assets/stylesheets/components/_forms.sass +++ b/app/assets/stylesheets/components/_forms.sass @@ -85,9 +85,15 @@ input // BS horizontal form label positionning fix .form-horizontal + input[type="radio"].form-control + height: auto + width: auto .form-group position: relative - + .radio-inline + padding-top: 4px + &:first-child + padding-left: 0 > .control-label &[class*='col-sm-'] float: none diff --git a/app/javascript/helpers/master_slave.coffee b/app/javascript/helpers/master_slave.coffee new file mode 100644 index 000000000..11f6bca7e --- /dev/null +++ b/app/javascript/helpers/master_slave.coffee @@ -0,0 +1,18 @@ +class MasterSlave + constructor: (selector)-> + $(selector).find('[data-master]').each (i, slave)-> + $slave = $(slave) + master = $($slave.data().master) + console.log $slave.data().master + console.log master + toggle = -> + val = master.filter(":checked").val() if master.filter("[type=radio]").length > 0 + val ||= master.val() + selected = val == $slave.data().value + $slave.toggle selected + $slave.find("input, select").attr "disabled", !selected + master.change toggle + toggle() + # $slave.toggle master.val() == $slave.data().value + +export default MasterSlave diff --git a/app/javascript/packs/stop_areas/new.js b/app/javascript/packs/stop_areas/new.js new file mode 100644 index 000000000..ffe702cdb --- /dev/null +++ b/app/javascript/packs/stop_areas/new.js @@ -0,0 +1,3 @@ +import MasterSlave from "../../helpers/master_slave" + +new MasterSlave("form") diff --git a/app/models/chouette/area_type.rb b/app/models/chouette/area_type.rb index 4703ea646..e17d2ee8d 100644 --- a/app/models/chouette/area_type.rb +++ b/app/models/chouette/area_type.rb @@ -1,13 +1,22 @@ class Chouette::AreaType include Comparable - ALL = %i(zdep zder zdlp zdlr lda gdl).freeze + COMMERCIAL = %i(zdep zder zdlp zdlr lda gdl).freeze + NON_COMMERCIAL = %i(deposit border service_area relief other).freeze + ALL = COMMERCIAL + NON_COMMERCIAL + @@commercial = COMMERCIAL + @@non_commercial = NON_COMMERCIAL @@all = ALL - mattr_accessor :all + mattr_accessor :all, :commercial, :non_commercial - def self.all=(values) - @@all = ALL & values + def self.commercial=(values) + @@commercial = COMMERCIAL & values + reset_caches! + end + + def self.non_commercial=(values) + @@non_commercial = NON_COMMERCIAL & values reset_caches! end @@ -20,12 +29,14 @@ class Chouette::AreaType end def self.reset_caches! + @@all = @@commercial + @@non_commercial @@instances = {} - @@options = nil + @@options = {} end - def self.options - @@options ||= all.map { |c| find(c) }.map { |t| [ t.label, t.code ] } + def self.options(kind=:all) + @@options ||= {} + @@options[kind] ||= self.send(kind).map { |c| find(c) }.map { |t| [ t.label, t.code ] } end attr_reader :code diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index ea1855ea8..d270a8696 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -10,6 +10,7 @@ module Chouette extend Enumerize enumerize :area_type, in: Chouette::AreaType::ALL + enumerize :kind, in: %i(commercial non_commercial) with_options dependent: :destroy do |assoc| assoc.has_many :stop_points @@ -96,6 +97,10 @@ module Chouette end end + def local_id + id.to_s + end + def children_in_depth return [] if self.children.empty? @@ -374,5 +379,9 @@ module Chouette return nil unless time_zone.present? ActiveSupport::TimeZone[time_zone]&.formatted_offset end + + def commercial? + kind == "commercial" + end end end diff --git a/app/views/stop_areas/_form.html.slim b/app/views/stop_areas/_form.html.slim index b2322f73a..699381d50 100644 --- a/app/views/stop_areas/_form.html.slim +++ b/app/views/stop_areas/_form.html.slim @@ -7,9 +7,13 @@ = f.input :id, as: :hidden = f.input :name, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.name")} - = f.input :parent_id, as: :select, :collection => [f.object.parent_id], input_html: { data: { select2_ajax: 'true', url: autocomplete_stop_area_referential_stop_areas_path(@stop_area_referential), initvalue: {id: f.object.parent_id, text: f.object.parent.try(:full_name)}}} + = f.input :kind, as: :radio_buttons, :input_html => {:disabled => !@stop_area.new_record?}, :include_blank => false, item_wrapper_class: 'radio-inline', wrapper: :horizontal_form, item_class: "fooo" - = f.input :area_type, as: :select, :input_html => {:disabled => !@stop_area.new_record?}, :collection => Chouette::AreaType.options, :include_blank => false + .slave data-master="[name='stop_area[kind]']" data-value="commercial" + = f.input :parent_id, as: :select, :collection => [f.object.parent_id], input_html: { data: { select2_ajax: 'true', url: autocomplete_stop_area_referential_stop_areas_path(@stop_area_referential), initvalue: {id: f.object.parent_id, text: f.object.parent.try(:full_name)}}} + - %i(commercial non_commercial).each do |kind| + .slave data-master="[name='stop_area[kind]']" data-value=kind + = f.input :area_type, as: :select, :input_html => {:disabled => !@stop_area.new_record?}, :collection => Chouette::AreaType.options(kind), :include_blank => false .location_info h3 = t("stop_areas.stop_area.localisation") @@ -49,3 +53,5 @@ .separator = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'stop_area_form' + += javascript_pack_tag "stop_areas/new" diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim index b5ec8ac00..b0896c1e0 100644 --- a/app/views/stop_areas/show.html.slim +++ b/app/views/stop_areas/show.html.slim @@ -6,11 +6,11 @@ .container-fluid .row .col-lg-6.col-md-6.col-sm-12.col-xs-12 - - attributes = { t('id_reflex') => @stop_area.get_objectid.short_id, - @stop_area.human_attribute_name(:parent) => @stop_area.parent ? link_to(@stop_area.parent.name, stop_area_referential_stop_area_path(@stop_area_referential, @stop_area.parent)) : "-", - @stop_area.human_attribute_name(:stop_area_type) => Chouette::AreaType.find(@stop_area.area_type).try(:label), + - attributes = { t('id_reflex') => @stop_area.get_objectid.short_id } + - attributes.merge!({ @stop_area.human_attribute_name(:parent) => @stop_area.parent ? link_to(@stop_area.parent.name, stop_area_referential_stop_area_path(@stop_area_referential, @stop_area.parent)) : "-" }) if @stop_area.commercial? + - attributes.merge!({ @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, - } + }) - attributes.merge!(@stop_area.human_attribute_name(:waiting_time) => @stop_area.waiting_time_text) if has_feature?(:stop_area_waiting_time) - attributes.merge!({ "Coordonnées" => geo_data(@stop_area, @stop_area_referential), @stop_area.human_attribute_name(:zip_code) => @stop_area.zip_code, |
