diff --git a/app/assets/javascripts/banners.js.coffee b/app/assets/javascripts/banners.js.coffee index 5f0c770f1..e7748c148 100644 --- a/app/assets/javascripts/banners.js.coffee +++ b/app/assets/javascripts/banners.js.coffee @@ -36,7 +36,16 @@ App.Banners = change: -> App.Banners.update_background_color("#js-banner-style", "#banner_background_color", $(this).val()); + $("#banner_background_color").on + change: -> + App.Banners.update_background_color("#js-banner-style", "#banner_background_color_picker", $(this).val()); + $("#banner_font_color_picker").on change: -> App.Banners.update_font_color("#js-banner-title", "#banner_font_color", $(this).val()); App.Banners.update_font_color("#js-banner-description", "#banner_font_color", $(this).val()); + + $("#banner_font_color").on + change: -> + App.Banners.update_font_color("#js-banner-title", "#banner_font_color_picker", $(this).val()); + App.Banners.update_font_color("#js-banner-description", "#banner_font_color_picker", $(this).val()); diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 8ef6ebb7f..e7e917be8 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -2226,7 +2226,8 @@ table { .banner-style-one, .banner-style-two, -.banner-style-three { +.banner-style-three, +.banner { margin: 0; margin-bottom: $line-height; diff --git a/app/controllers/admin/banners_controller.rb b/app/controllers/admin/banners_controller.rb index 1c0d1528c..802110063 100644 --- a/app/controllers/admin/banners_controller.rb +++ b/app/controllers/admin/banners_controller.rb @@ -40,8 +40,9 @@ class Admin::BannersController < Admin::BaseController def banner_params attributes = [:title, :description, :target_url, :style, :image, - :post_started_at, :post_ended_at, :sections, - :background_color, :font_color] + :post_started_at, :post_ended_at, + :background_color, :font_color, + web_section_ids: []] params.require(:banner).permit(*attributes) end @@ -58,6 +59,6 @@ class Admin::BannersController < Admin::BaseController end def banner_sections - @banner_sections = Banner::Section.sections.map {|banner_section| [banner_section[1], banner_section[0]]} # name, value + @banner_sections = WebSection.all end end diff --git a/app/models/banner.rb b/app/models/banner.rb index afa6e5115..ad37fdc72 100644 --- a/app/models/banner.rb +++ b/app/models/banner.rb @@ -7,15 +7,13 @@ class Banner < ActiveRecord::Base length: { minimum: 2 } validates :description, presence: true validates :target_url, presence: true - validates :style, presence: true - validates :image, presence: true validates :post_started_at, presence: true validates :post_ended_at, presence: true has_many :sections + has_many :web_sections, through: :sections scope :with_active, -> { where("post_started_at <= ?", Time.current).where("post_ended_at >= ?", Time.current) } scope :with_inactive, -> { where("post_started_at > ? or post_ended_at < ?", Time.current, Time.current) } - end diff --git a/app/models/banner/section.rb b/app/models/banner/section.rb index ac1861a1e..493093731 100644 --- a/app/models/banner/section.rb +++ b/app/models/banner/section.rb @@ -1,5 +1,4 @@ class Banner::Section < ActiveRecord::Base - enum sections: { homepage: 0, debates: 1, proposals: 2, budgets: 3, more_info: 4 } - belongs_to :banner + belongs_to :web_section end diff --git a/app/models/web_section.rb b/app/models/web_section.rb new file mode 100644 index 000000000..ffeca96f2 --- /dev/null +++ b/app/models/web_section.rb @@ -0,0 +1,4 @@ +class WebSection < ActiveRecord::Base + has_many :sections + has_many :banners, through: :sections +end diff --git a/app/views/admin/banners/_form.html.erb b/app/views/admin/banners/_form.html.erb index 852ef551c..1db97e71a 100644 --- a/app/views/admin/banners/_form.html.erb +++ b/app/views/admin/banners/_form.html.erb @@ -3,18 +3,8 @@ <%= render 'errors' %>
-
- <%= f.label :style, t("admin.banners.banner.style") %> - <%= f.select :style, options_for_select(@banner_styles, @banner.style),:include_blank => '-', - label: false,placeholder: t("admin.banners.banner.style") %> -
-
- <%= f.label :image, t("admin.banners.banner.image") %> - <%= f.select :image, options_for_select(@banner_imgs, @banner.image),:include_blank => '-', - label: false, placeholder: t("admin.banners.banner.image") %> -
<% date_started_at = @banner.post_started_at.present? ? I18n.localize(@banner.post_started_at) : "" %> -
+
<%= f.label :post_started_at, t("admin.banners.banner.post_started_at") %> <%= f.text_field :post_started_at, label: false, @@ -24,7 +14,7 @@ id: "post_started_at" %>
<% date_ended_at = @banner.post_ended_at.present? ? I18n.localize(@banner.post_ended_at) : ""%> -
+
<%= f.label :post_ended_at, t("admin.banners.banner.post_ended_at") %> <%= f.text_field :post_ended_at, label: false, @@ -63,9 +53,8 @@
<%= f.label :sections, t("admin.banners.banner.sections_label") %> - <% @banner_sections.each do |section| %> - <%= f.check_box :sections, {multiple: true, label: false}, section[0], nil %> - <%= t("admin.banners.banner.sections.#{section[1]}") %>
+ <%= f.collection_check_boxes(:web_section_ids, @banner_sections, :id, :name) do |b| %> + <%= b.check_box %> <%= t("admin.banners.banner.sections.#{b.text}") %>
<% end %>
@@ -88,7 +77,7 @@ <%= f.submit(class: "button expanded", value: t("admin.banners.edit.form.submit_button")) %>
-
+