diff --git a/app/assets/javascripts/banners.js.coffee b/app/assets/javascripts/banners.js.coffee
index 66d3a8df7..5f0c770f1 100644
--- a/app/assets/javascripts/banners.js.coffee
+++ b/app/assets/javascripts/banners.js.coffee
@@ -7,6 +7,14 @@ App.Banners =
$(selector).removeClass($(selector).attr("class"), true)
.addClass(style, true)
+ update_background_color: (selector, text_selector, background_color) ->
+ $(selector).css('background-color', background_color);
+ $(text_selector).val(background_color);
+
+ update_font_color: (selector, text_selector, font_color) ->
+ $(selector).css('color', font_color);
+ $(text_selector).val(font_color);
+
initialize: ->
$('[data-js-banner-title]').on
change: ->
@@ -23,3 +31,12 @@ App.Banners =
$("#banner_image").on
change: ->
App.Banners.update_style("#js-banner-image", $(this).val())
+
+ $("#banner_background_color_picker").on
+ change: ->
+ App.Banners.update_background_color("#js-banner-style", "#banner_background_color", $(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());
diff --git a/app/controllers/admin/banners_controller.rb b/app/controllers/admin/banners_controller.rb
index 281fc9360..1c0d1528c 100644
--- a/app/controllers/admin/banners_controller.rb
+++ b/app/controllers/admin/banners_controller.rb
@@ -4,6 +4,7 @@ class Admin::BannersController < Admin::BaseController
before_action :banner_styles, only: [:edit, :new, :create, :update]
before_action :banner_imgs, only: [:edit, :new, :create, :update]
+ before_action :banner_sections, only: [:edit, :new, :create, :update]
respond_to :html, :js
@@ -39,7 +40,8 @@ class Admin::BannersController < Admin::BaseController
def banner_params
attributes = [:title, :description, :target_url, :style, :image,
- :post_started_at, :post_ended_at]
+ :post_started_at, :post_ended_at, :sections,
+ :background_color, :font_color]
params.require(:banner).permit(*attributes)
end
@@ -55,4 +57,7 @@ class Admin::BannersController < Admin::BaseController
end
end
+ def banner_sections
+ @banner_sections = Banner::Section.sections.map {|banner_section| [banner_section[1], banner_section[0]]} # name, value
+ end
end
diff --git a/app/models/banner.rb b/app/models/banner.rb
index 8e816d446..afa6e5115 100644
--- a/app/models/banner.rb
+++ b/app/models/banner.rb
@@ -12,6 +12,8 @@ class Banner < ActiveRecord::Base
validates :post_started_at, presence: true
validates :post_ended_at, presence: true
+ has_many :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) }
diff --git a/app/models/banner/section.rb b/app/models/banner/section.rb
new file mode 100644
index 000000000..ac1861a1e
--- /dev/null
+++ b/app/models/banner/section.rb
@@ -0,0 +1,5 @@
+class Banner::Section < ActiveRecord::Base
+ enum sections: { homepage: 0, debates: 1, proposals: 2, budgets: 3, more_info: 4 }
+
+ belongs_to :banner
+end
diff --git a/app/views/admin/banners/_form.html.erb b/app/views/admin/banners/_form.html.erb
index 9c8d20612..852ef551c 100644
--- a/app/views/admin/banners/_form.html.erb
+++ b/app/views/admin/banners/_form.html.erb
@@ -60,17 +60,40 @@
+
+
+ <%= 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]}") %>
+ <% end %>
+
+
+
+
+
+ <%= f.label :sections, t("admin.banners.banner.background_color") %>
+ <%= color_field(:banner, :background_color, id: 'banner_background_color_picker') %>
+ <%= f.text_field :background_color, label: false %>
+
+
+ <%= f.label :sections, t("admin.banners.banner.font_color") %>
+ <%= color_field(:banner, :font_color, id: 'banner_font_color_picker') %>
+ <%= f.text_field :font_color, label: false %>
+
+
+
<%= f.submit(class: "button expanded", value: t("admin.banners.edit.form.submit_button")) %>
-
+
<%= link_to @banner.target_url do %>
-
<%= @banner.title %>
- <%= @banner.description %>
+ <%= @banner.title %>
+ <%= @banner.description %>
<% end %>
-<% end %>
\ No newline at end of file
+<% end %>
diff --git a/app/views/admin/banners/index.html.erb b/app/views/admin/banners/index.html.erb
index 11f2ef6ab..352816bfc 100644
--- a/app/views/admin/banners/index.html.erb
+++ b/app/views/admin/banners/index.html.erb
@@ -37,11 +37,11 @@
-
+
<%= link_to banner.target_url do %>
- <%= banner.title %>
- <%= banner.description %>
+ <%= banner.title %>
+ <%= banner.description %>
<% end %>
@@ -51,4 +51,4 @@
<% end %>
-<%= paginate @banners %>
\ No newline at end of file
+<%= paginate @banners %>
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index 67273c327..c999fcbc6 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -33,6 +33,15 @@ en:
image: Image
post_started_at: Post started at
post_ended_at: Post ended at
+ sections_label: Seccions where it will appear
+ sections:
+ homepage: Homepage
+ debates: Debates
+ proposals: Proposals
+ budgets: Participatory budgeting
+ more_info: More info page
+ background_color: Background colour
+ font_color: Font colour
edit:
editing: Edit banner
form:
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 8e3c546f9..371fab679 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -33,6 +33,15 @@ es:
image: Imagen
post_started_at: Inicio de publicación
post_ended_at: Fin de publicación
+ sections_label: Secciones en las que aparece
+ sections:
+ homepage: Homepage
+ debates: Debates
+ proposals: Propuestas
+ budgets: Presupuestos participativos
+ more_info: Página de más información
+ background_color: Color de fondo
+ font_color: Color del texto
edit:
editing: Editar el banner
form:
diff --git a/db/migrate/20180109081115_add_settings_to_banners.rb b/db/migrate/20180109081115_add_settings_to_banners.rb
new file mode 100644
index 000000000..5092501cc
--- /dev/null
+++ b/db/migrate/20180109081115_add_settings_to_banners.rb
@@ -0,0 +1,6 @@
+class AddSettingsToBanners < ActiveRecord::Migration
+ def change
+ add_column :banners, :background_color, :text
+ add_column :banners, :font_color, :text
+ end
+end
diff --git a/db/migrate/20180109101656_create_banner_sections.rb b/db/migrate/20180109101656_create_banner_sections.rb
new file mode 100644
index 000000000..e65bbd91a
--- /dev/null
+++ b/db/migrate/20180109101656_create_banner_sections.rb
@@ -0,0 +1,9 @@
+class CreateBannerSections < ActiveRecord::Migration
+ def change
+ create_table :banner_sections do |t|
+ t.integer :banner_id
+ t.integer :section
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 916342063..bb5863510 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -63,8 +63,15 @@ ActiveRecord::Schema.define(version: 20180519132610) do
add_index "annotations", ["legacy_legislation_id"], name: "index_annotations_on_legacy_legislation_id", using: :btree
add_index "annotations", ["user_id"], name: "index_annotations_on_user_id", using: :btree
+ create_table "banner_sections", force: :cascade do |t|
+ t.integer "banner_id"
+ t.integer "section"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
create_table "banners", force: :cascade do |t|
- t.string "title", limit: 80
+ t.string "title", limit: 80
t.string "description"
t.string "target_url"
t.string "style"
@@ -72,8 +79,10 @@ ActiveRecord::Schema.define(version: 20180519132610) do
t.date "post_started_at"
t.date "post_ended_at"
t.datetime "hidden_at"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.text "background_color"
+ t.text "font_color"
end
add_index "banners", ["hidden_at"], name: "index_banners_on_hidden_at", using: :btree
|