diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index b1edc246d..8b7390191 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -310,6 +310,10 @@ .budget-investment-new, .proposal-form, .proposal-edit, +.new_poll_question, +.edit_poll_question, +.new_poll, +.edit_poll, .poll-question-form { @include direct-uploads; } diff --git a/app/controllers/admin/poll/polls_controller.rb b/app/controllers/admin/poll/polls_controller.rb index fb4b4d127..cce880ed4 100644 --- a/app/controllers/admin/poll/polls_controller.rb +++ b/app/controllers/admin/poll/polls_controller.rb @@ -54,7 +54,9 @@ class Admin::Poll::PollsController < Admin::Poll::BaseController end def poll_params - params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, geozone_ids: []) + params.require(:poll).permit(:name, :starts_at, :ends_at, :geozone_restricted, :summary, :description, + geozone_ids: [], + image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) end def search_params diff --git a/app/models/poll.rb b/app/models/poll.rb index 624cfc704..84349bf0b 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -1,4 +1,6 @@ class Poll < ActiveRecord::Base + include Imageable + has_many :booth_assignments, class_name: "Poll::BoothAssignment" has_many :booths, through: :booth_assignments has_many :partial_results, through: :booth_assignments diff --git a/app/views/admin/poll/polls/_form.html.erb b/app/views/admin/poll/polls/_form.html.erb index 0b99ea9f5..aff19d9d7 100644 --- a/app/views/admin/poll/polls/_form.html.erb +++ b/app/views/admin/poll/polls/_form.html.erb @@ -19,6 +19,22 @@ +
+
+ <%=f.text_area :summary, rows: 4%> +
+
+ +
+
+ <%=f.text_area :description, rows: 8%> +
+
+ +
+ <%= render 'images/admin_image', imageable: @poll, f: f %> +
+
<%= f.check_box :geozone_restricted, data: { checkbox_toggle: "#geozones" } %> diff --git a/app/views/images/_admin_image.html.erb b/app/views/images/_admin_image.html.erb new file mode 100644 index 000000000..a782b743b --- /dev/null +++ b/app/views/images/_admin_image.html.erb @@ -0,0 +1,45 @@ +
+
+ <%= f.label :image, t("images.form.admin_title") %> + + + <%= link_to_add_association t('images.form.add_new_image'), f, :image, + force_non_association_create: true, + partial: "images/image_fields", + id: "new_image_link", + class: "button hollow", + render_options: { + locals: { imageable: imageable } + }, + data: { + association_insertion_node: "#nested-image", + association_insertion_method: "append" + } %> + +
+ <%= f.fields_for :image do |image_builder| %> + +
+ <%= image_builder.hidden_field :id %> + <%= image_builder.hidden_field :user_id, value: current_user.id %> + <%= image_builder.hidden_field :cached_attachment %> + + <%= image_builder.text_field :title, placeholder: t("images.form.title_placeholder"), label: "#{t("images.form.admin_alt_text")}" %> + + +
+
+ <%= render_image_attachment(image_builder, imageable, image_builder.object) %> +
+
+ +
+
+
+ +
+ + <% end %> +
+
+
diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 1e3f62b1a..8bb2c3286 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -152,6 +152,8 @@ en: starts_at: "Start Date" ends_at: "Closing Date" geozone_restricted: "Restricted by geozone" + summary: "Summary" + description: "Description" poll/question: title: "Question" valid_answers: "Posibles answers" diff --git a/config/locales/en/images.yml b/config/locales/en/images.yml index 6f16061fa..afd8b2308 100644 --- a/config/locales/en/images.yml +++ b/config/locales/en/images.yml @@ -9,6 +9,9 @@ en: delete_button: Remove image note: "You can upload one image of following content types: %{accepted_content_types}, up to %{max_file_size} MB." add_new_image: Add image + title_placeholder: Add a descriptive title for the image + admin_title: "Main image of the poll" + admin_alt_text: "Alternative text for the image" actions: destroy: diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 108f19fcf..415e81bed 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -146,6 +146,8 @@ es: starts_at: "Fecha de apertura" ends_at: "Fecha de cierre" geozone_restricted: "Restringida por zonas" + summary: "Resumen" + description: "Descripción" poll/question: title: "Pregunta" valid_answers: "Posibles respuestas" diff --git a/config/locales/es/images.yml b/config/locales/es/images.yml index 869a0824e..e842f3f5c 100644 --- a/config/locales/es/images.yml +++ b/config/locales/es/images.yml @@ -9,6 +9,8 @@ es: note: "Puedes subir una imagen en los formatos: %{accepted_content_types}, y de hasta %{max_file_size} MB por archivo." add_new_image: Añadir imagen title_placeholder: Añade un título descriptivo para la imagen + admin_title: "Imagen principal de la votación" + admin_alt_text: "Texto alternativo para la imagen" actions: destroy: diff --git a/db/migrate/20170928132402_add_summary_and_description_to_polls.rb b/db/migrate/20170928132402_add_summary_and_description_to_polls.rb new file mode 100644 index 000000000..6fb965346 --- /dev/null +++ b/db/migrate/20170928132402_add_summary_and_description_to_polls.rb @@ -0,0 +1,6 @@ +class AddSummaryAndDescriptionToPolls < ActiveRecord::Migration + def change + add_column :polls, :summary, :text + add_column :polls, :description, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index e75c2aac3..8b3e89a19 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -783,6 +783,8 @@ ActiveRecord::Schema.define(version: 20171003095936) do t.datetime "ends_at" t.boolean "published", default: false t.boolean "geozone_restricted", default: false + t.text "summary" + t.text "description" end add_index "polls", ["starts_at", "ends_at"], name: "index_polls_on_starts_at_and_ends_at", using: :btree diff --git a/spec/features/admin/poll/polls_spec.rb b/spec/features/admin/poll/polls_spec.rb index e3f2c34b8..be987df2d 100644 --- a/spec/features/admin/poll/polls_spec.rb +++ b/spec/features/admin/poll/polls_spec.rb @@ -58,6 +58,8 @@ feature 'Admin polls' do fill_in "poll_name", with: "Upcoming poll" fill_in 'poll_starts_at', with: start_date.strftime("%d/%m/%Y") fill_in 'poll_ends_at', with: end_date.strftime("%d/%m/%Y") + fill_in 'poll_summary', with: "Upcoming poll's summary. This poll..." + fill_in 'poll_description', with: "Upcomming poll's description. This poll..." click_button "Create poll" expect(page).to have_content "Poll created successfully"