diff --git a/app/assets/stylesheets/mixins.scss b/app/assets/stylesheets/mixins.scss index 89f962eeb..cc8fe9360 100644 --- a/app/assets/stylesheets/mixins.scss +++ b/app/assets/stylesheets/mixins.scss @@ -44,28 +44,6 @@ margin-bottom: $line-height; } - .document-form, - .image-form { - - .title{ - margin-bottom: $line-height; - } - - .document, - .image-form { - .file-name { - margin-top: 0; - } - } - - .document, - .image { - .loading-bar.errors { - margin-top: $line-height * 2; - } - } - } - .document, .image { @@ -107,12 +85,10 @@ &.complete { background-color: $success-color; - width: 100%; } &.errors { background-color: $alert-color; - width: 100%; margin-top: $line-height / 2; } } diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 84e16ebe9..fbcda0ebb 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -249,11 +249,8 @@ .proposal-form, .budget-investment-form, .spending-proposal-form, -.document-form, .topic-new, -.topic-form, -.image-form, -.proposal .image-form { +.topic-form { .icon-debates, .icon-proposals, @@ -305,9 +302,7 @@ .proposal-form, .topic-form, -.topic-new, -.document-form, -.image-form { +.topic-new { .recommendations li::before { color: $proposals; @@ -317,8 +312,6 @@ .budget-investment-new, .proposal-form, .proposal-edit, -.image-form, -.document-form, .new_poll_question, .edit_poll_question { @include direct-uploads; @@ -856,12 +849,6 @@ display: none; } -.document-form { - max-width: 75rem; - margin-left: auto; - margin-right: auto; -} - .more-info { clear: both; color: $text-medium; diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index 73e90eb68..001d23446 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -1,24 +1,8 @@ class DocumentsController < ApplicationController before_action :authenticate_user! - before_action :find_documentable, except: :destroy - before_action :prepare_new_document, only: [:new] - before_action :prepare_document_for_creation, only: :create load_and_authorize_resource - def new - end - - def create - if @document.save - flash[:notice] = t "documents.actions.create.notice" - redirect_to params[:from] - else - flash[:alert] = t "documents.actions.create.alert" - render :new - end - end - def destroy respond_to do |format| format.html do @@ -39,25 +23,4 @@ class DocumentsController < ApplicationController end end - private - - def document_params - params.require(:document).permit(:title, :documentable_type, :documentable_id, - :attachment, :cached_attachment, :user_id) - end - - def find_documentable - @documentable = params[:documentable_type].constantize.find_or_initialize_by(id: params[:documentable_id]) - end - - def prepare_new_document - @document = Document.new(documentable: @documentable, user_id: current_user.id) - end - - def prepare_document_for_creation - @document = Document.new(document_params) - @document.documentable = @documentable - @document.user = current_user - end - end diff --git a/app/controllers/images_controller.rb b/app/controllers/images_controller.rb index 1bfe6e8cd..e273234f2 100644 --- a/app/controllers/images_controller.rb +++ b/app/controllers/images_controller.rb @@ -1,24 +1,8 @@ class ImagesController < ApplicationController before_action :authenticate_user! - before_filter :find_imageable, except: :destroy - before_filter :prepare_new_image, only: [:new] - before_filter :prepare_image_for_creation, only: :create load_and_authorize_resource - def new - end - - def create - if @image.save - flash[:notice] = t "images.actions.create.notice" - redirect_to params[:from] - else - flash[:alert] = t "images.actions.create.alert" - render :new - end - end - def destroy respond_to do |format| format.html do @@ -39,25 +23,4 @@ class ImagesController < ApplicationController end end - private - - def image_params - params.require(:image).permit(:title, :imageable_type, :imageable_id, - :attachment, :cached_attachment, :user_id) - end - - def find_imageable - @imageable = params[:imageable_type].constantize.find_or_initialize_by(id: params[:imageable_id]) - end - - def prepare_new_image - @image = Image.new(imageable: @imageable) - end - - def prepare_image_for_creation - @image = Image.new(image_params) - @image.imageable = @imageable - @image.user = current_user - end - end diff --git a/app/helpers/documentables_helper.rb b/app/helpers/documentables_helper.rb index b95ea80c6..8d9f85578 100644 --- a/app/helpers/documentables_helper.rb +++ b/app/helpers/documentables_helper.rb @@ -1,9 +1,5 @@ module DocumentablesHelper - def can_create_document?(documentable) - can?(:create, Document.new(documentable: documentable)) && documentable.documents.size < documentable.class.max_documents_allowed - end - def documentable_class(documentable) documentable.class.name.parameterize('_') end diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb index 228827516..d7e8d1dea 100644 --- a/app/helpers/documents_helper.rb +++ b/app/helpers/documents_helper.rb @@ -1,10 +1,5 @@ module DocumentsHelper - def document_note(document) - t "documents.new.#{document.documentable.class.name.parameterize.underscore}.note", - title: document.documentable.title - end - def document_attachment_file_name(document) document.attachment_file_name end @@ -40,7 +35,7 @@ module DocumentsHelper klass = document.errors[:attachment].any? ? "error" : "" klass = document.persisted? || document.cached_attachment.present? ? " hide" : "" html = builder.label :attachment, - t("documents.upload_document"), + t("documents.form.attachment_label"), class: "button hollow #{klass}" html += builder.file_field :attachment, label: false, diff --git a/app/helpers/imageables_helper.rb b/app/helpers/imageables_helper.rb index e45302792..b1c8059ce 100644 --- a/app/helpers/imageables_helper.rb +++ b/app/helpers/imageables_helper.rb @@ -1,9 +1,5 @@ module ImageablesHelper - def can_create_image?(imageable) - can?(:create, Image.new(imageable: imageable)) - end - def can_destroy_image?(imageable) imageable.image.present? && can?(:destroy, imageable.image) end diff --git a/app/helpers/images_helper.rb b/app/helpers/images_helper.rb index 79b6dbd1e..4e2bdff0e 100644 --- a/app/helpers/images_helper.rb +++ b/app/helpers/images_helper.rb @@ -9,11 +9,6 @@ module ImagesHelper end end - def image_note(image) - t "images.new.#{image.imageable.class.name.parameterize.underscore}.note", - title: image.imageable.title - end - def image_first_recommendation(image) t "images.#{image.imageable.class.name.parameterize.underscore}.recommendation_one_html", title: image.imageable.title diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 5f0c849e1..4278d4f8d 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -74,7 +74,7 @@ module Abilities cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation] can [:create, :destroy], Document - can [:create, :destroy], Image + can [:destroy], Image can [:create, :destroy], DirectUpload end end diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index b4248c3b6..e4e92abaf 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -37,9 +37,9 @@ module Abilities can [:create, :destroy], Follow - can [:create, :destroy, :new], Document, documentable: { author_id: user.id } + can [:destroy], Document, documentable: { author_id: user.id } - can [:create, :destroy, :new], Image, imageable: { author_id: user.id } + can [:destroy], Image, imageable: { author_id: user.id } can [:create, :destroy], DirectUpload diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index 2e9e24b4f..e257de0bb 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -4,18 +4,6 @@
<%= back_link_to budget_investments_path(investment.budget, heading_id: investment.heading) %> - <% if can_create_document?(investment) %> - <%= link_to t("documents.upload_document"), - new_document_path(documentable_id:investment, documentable_type: investment.class.name, from: request.url), - class: 'button hollow float-right' %> - <% end %> - - <% if can_create_image?(investment) %> - <%= link_to t("images.upload_image"), - new_image_path(imageable_id:investment, imageable_type: investment.class.name, from: request.url), - class: 'button hollow float-right' %> - <% end %> - <% if can_destroy_image?(investment) %> <%= link_to t("images.remove_image"), image_path(investment.image, from: request.url), diff --git a/app/views/documents/_document_fields.html.erb b/app/views/documents/_document_fields.html.erb index 0931ed246..7d7129df6 100644 --- a/app/views/documents/_document_fields.html.erb +++ b/app/views/documents/_document_fields.html.erb @@ -4,7 +4,7 @@ <%= f.hidden_field :cached_attachment %>
- <%= f.text_field :title, placeholder: t("documents.new.form.title_placeholder") %> + <%= f.text_field :title, placeholder: t("documents.form.title_placeholder") %>
diff --git a/app/views/documents/_documents.html.erb b/app/views/documents/_documents.html.erb index e03c8c280..e36d88207 100644 --- a/app/views/documents/_documents.html.erb +++ b/app/views/documents/_documents.html.erb @@ -1,6 +1,6 @@ <% if documents.any? %> - <% if documents.size == max_documents_allowed && can?(:create, Document) %> + <% if documents.size == max_documents_allowed && can?(:destroy, Document) %>
diff --git a/app/views/documents/_form.html.erb b/app/views/documents/_form.html.erb deleted file mode 100644 index 216dbbb3b..000000000 --- a/app/views/documents/_form.html.erb +++ /dev/null @@ -1,63 +0,0 @@ -<%= form_for @document, - url: documents_path( - documentable_type: @document.documentable_type, - documentable_id: @document.documentable_id, - from: params[:from] - ), - html: { multipart: true, class: "documentable document-form" } do |f| %> - - <%= render 'shared/errors', resource: @document %> - -
- - <%= f.hidden_field :cached_attachment %> - -
- <%= f.text_field :title, placeholder: t("documents.new.form.title_placeholder") %> -
- -
-
- <%= f.label :attachment, t("documents.form.attachment_label"), class: 'button hollow' %> - <%= f.file_field :attachment, - accept: accepted_content_types_extensions(@document.documentable.class), - label: false, - class: 'js-document-attachment', - data: { - url: direct_uploads_url("direct_upload[resource_type]": @document.documentable_type, - "direct_upload[resource_id]": @document.documentable_id, - "direct_upload[resource_relation]": "documents"), - cached_attachment_input_field: "document_cached_attachment", - title_input_field: "document_title" - } %> - -
-
- <% if @document.cached_attachment.present? %> - <%= link_to t('documents.form.delete_button'), - direct_upload_destroy_url("direct_upload[resource_type]": @document.documentable_type, - "direct_upload[resource_id]": @document.documentable_id, - "direct_upload[resource_relation]": "documents", - "direct_upload[cached_attachment]": @document.cached_attachment), - method: :delete, - remote: true, - class: "delete remove-cached-attachment" %> - <% end %> -
-
- -
-

- <%= document_attachment_file_name(@document) %> -

-
- -
-
-
- -
- <%= f.submit(t("documents.form.submit_button"), class: "button expanded") %> -
-
-<% end %> diff --git a/app/views/documents/new.html.erb b/app/views/documents/new.html.erb deleted file mode 100644 index 49446a513..000000000 --- a/app/views/documents/new.html.erb +++ /dev/null @@ -1,28 +0,0 @@ -
- -
- <%= back_link_to params[:from] %> -

<%= t("documents.new.title") %>

-

<%= document_note(@document) %>

- <%= render "documents/form", form_url: documents_url %> -
- -
- -

<%= t("documents.recommendations_title") %>

-
    -
  • - <%= t "documents.recommendation_one_html", - max_documents_allowed: max_documents_allowed(@document.documentable) %> -
  • -
  • - <%= t "documents.recommendation_two_html", - accepted_content_types: documentable_humanized_accepted_content_types(@document.documentable.class) %> -
  • -
  • - <%= t "documents.recommendation_three_html", - max_file_size: max_file_size(@document.documentable.class) %> -
  • -
-
-
diff --git a/app/views/images/_form.html.erb b/app/views/images/_form.html.erb deleted file mode 100644 index 8f8cd6995..000000000 --- a/app/views/images/_form.html.erb +++ /dev/null @@ -1,65 +0,0 @@ -<%= form_for @image, - url: images_path( - imageable_type: @image.imageable_type, - imageable_id: @image.imageable_id, - from: params[:from] - ), - html: { multipart: true, class: "imageable" } do |f| %> - - <%= render 'shared/errors', resource: @image %> - -
- - <%= f.hidden_field :cached_attachment %> - -
- <%= f.text_field :title, placeholder: t("images.new.form.title_placeholder") %> -
- - <%= render_image(@image, :thumb, false) if @image.attachment.exists? %> - -
-
- <%= f.label :attachment, t("images.form.attachment_label"), class: 'button hollow' %> - <%= f.file_field :attachment, - accept: imageable_accepted_content_types_extensions, - label: false, - class: 'js-image-attachment', - data: { - url: direct_uploads_url("direct_upload[resource_type]": @image.imageable_type, - "direct_upload[resource_id]": @image.imageable_id, - "direct_upload[resource_relation]": "image"), - cached_attachment_input_field: "image_cached_attachment", - title_input_field: "image_title" - } %> -
-
- <% if @image.cached_attachment.present? %> - <%= link_to t('images.form.delete_button'), - direct_upload_destroy_url("direct_upload[resource_type]": @image.imageable_type, - "direct_upload[resource_id]": @image.imageable_id, - "direct_upload[resource_relation]": "image", - "direct_upload[cached_attachment]": @image.cached_attachment), - method: :delete, - remote: true, - class: "delete remove-cached-attachment" %> - <% end %> -
-
- -
-

- <%= image_attachment_file_name(@image) %> -

-
- -
-
-
- -
- <%= f.submit(t("images.form.submit_button"), class: "button expanded") %> -
- -
-<% end %> diff --git a/app/views/images/_image.html.erb b/app/views/images/_image.html.erb index ca7a95867..1f2494c01 100644 --- a/app/views/images/_image.html.erb +++ b/app/views/images/_image.html.erb @@ -2,7 +2,8 @@
<%= image_tag image.attachment.url(version), class: image_class(image), - alt: image.title %> + alt: image.title, + title: image.title %> <% if show_caption %>
<%= image.title %> diff --git a/app/views/images/_image_fields.html.erb b/app/views/images/_image_fields.html.erb index d067961d7..10a4cf898 100644 --- a/app/views/images/_image_fields.html.erb +++ b/app/views/images/_image_fields.html.erb @@ -4,7 +4,7 @@ <%= f.hidden_field :cached_attachment %>
- <%= f.text_field :title, placeholder: t("images.new.form.title_placeholder") %> + <%= f.text_field :title, placeholder: t("images.form.title_placeholder") %>
<%= render_image(f.object, :thumb, false) if f.object.attachment.exists? %> diff --git a/app/views/images/new.html.erb b/app/views/images/new.html.erb deleted file mode 100644 index 8aef6a6ad..000000000 --- a/app/views/images/new.html.erb +++ /dev/null @@ -1,30 +0,0 @@ -
- -
- -
- <%= back_link_to params[:from] %> -

<%= t("images.new.title") %>

-

<%= image_note(@image) %>

- <%= render "form", form_url: images_url %> -
- -
- -

<%= t("images.recommendations_title") %>

-
    -
  • - <%= image_first_recommendation(@image) %> -
  • -
  • - <%= t "images.recommendation_two_html", - accepted_content_types: imageable_humanized_accepted_content_types %> -
  • -
  • - <%= t "images.recommendation_three_html", - max_file_size: imageable_max_file_size %> -
  • -
-
-
-
diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index ee7ca6f45..96999ca7d 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -108,18 +108,10 @@