Rename document/image fields HTML classes

Using the `document` or `documents` classes meant styles defined for the
public list of documents conflict with these ones.

So now we're using HTML classes that match the name of the Ruby
component classes, as we usually do.
This commit is contained in:
Javi Martín
2023-10-12 21:38:08 +02:00
parent 1e1d7996bb
commit a8bd5eb192
11 changed files with 27 additions and 25 deletions

View File

@@ -9,9 +9,11 @@
App.Documentable.unlockUploads(); App.Documentable.unlockUploads();
}); });
$("#nested-documents").on("cocoon:after-insert", function(e, nested_document) { $("#nested-documents").on("cocoon:after-insert", function(e, nested_document) {
var input; var input, document_fields;
input = $(nested_document).find(".js-document-attachment"); input = $(nested_document).find(".js-document-attachment");
input.lockUpload = $(nested_document).closest("#nested-documents").find(".document:visible").length >= $("#nested-documents").data("max-documents-allowed"); document_fields = $(nested_document).closest("#nested-documents").find(".document-fields:visible");
input.lockUpload = document_fields.length >= $("#nested-documents").data("max-documents-allowed");
App.Documentable.initializeDirectUploadInput(input); App.Documentable.initializeDirectUploadInput(input);
if (input.lockUpload) { if (input.lockUpload) {
App.Documentable.lockUploads(); App.Documentable.lockUploads();

View File

@@ -9,7 +9,7 @@
$("#new_image_link").removeClass("hide"); $("#new_image_link").removeClass("hide");
}); });
$("#nested-image").on("cocoon:before-insert", function() { $("#nested-image").on("cocoon:before-insert", function() {
$(".js-image-attachment").closest(".image").remove(); $(".js-image-attachment").closest(".image-fields").remove();
}); });
$("#nested-image").on("cocoon:after-insert", function(e, nested_image) { $("#nested-image").on("cocoon:after-insert", function(e, nested_image) {
var input; var input;

View File

@@ -23,7 +23,7 @@
} }
} }
.images { .images-nested {
@include direct-uploads; @include direct-uploads;
} }

View File

@@ -10,8 +10,8 @@
margin-bottom: $line-height; margin-bottom: $line-height;
} }
.document, .document-fields,
.image { .image-fields {
.document-attachment, .document-attachment,
.image-attachment { .image-attachment {

View File

@@ -1,4 +1,4 @@
<div class="<%= singular_name %> direct-upload nested-fields"> <div class="<%= singular_name %>-fields direct-upload nested-fields">
<%= f.hidden_field :id %> <%= f.hidden_field :id %>
<%= f.hidden_field :user_id, value: current_user.id %> <%= f.hidden_field :user_id, value: current_user.id %>
<%= f.hidden_field :cached_attachment %> <%= f.hidden_field :cached_attachment %>

View File

@@ -1,4 +1,4 @@
<fieldset class="documents-list documents"> <fieldset class="documents-list documents-nested">
<legend><%= t("documents.form.title") %></legend> <legend><%= t("documents.form.title") %></legend>
<p class="help-text"><%= note %></p> <p class="help-text"><%= note %></p>

View File

@@ -1,4 +1,4 @@
<fieldset class="images"> <fieldset class="images-nested">
<legend><%= t("images.form.title") %></legend> <legend><%= t("images.form.title") %></legend>
<p class="help-text"><%= note %></p> <p class="help-text"><%= note %></p>

View File

@@ -163,7 +163,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
click_link "Add new document" click_link "Add new document"
click_on submit_button click_on submit_button
within "#nested-documents .document" do within "#nested-documents .document-fields" do
expect(page).to have_content("can't be blank", count: 2) expect(page).to have_content("can't be blank", count: 2)
end end
end end
@@ -175,7 +175,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
documentable_attach_new_file(file_fixture("empty.pdf")) documentable_attach_new_file(file_fixture("empty.pdf"))
click_link "Remove document" click_link "Remove document"
expect(page).not_to have_css("#nested-documents .document") expect(page).not_to have_css("#nested-documents .document-fields")
end end
scenario "Should show successful notice when scenario "Should show successful notice when
@@ -248,7 +248,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
do_login_for user_to_login, management: management do_login_for user_to_login, management: management
visit send(path, arguments) visit send(path, arguments)
expect(page).to have_css ".document", count: 1 expect(page).to have_css ".document-fields", count: 1
end end
scenario "Should not show add document button when scenario "Should not show add document button when
@@ -264,7 +264,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
create_list(:document, documentable.class.max_documents_allowed, documentable: documentable) create_list(:document, documentable.class.max_documents_allowed, documentable: documentable)
do_login_for user_to_login, management: management do_login_for user_to_login, management: management
visit send(path, arguments) visit send(path, arguments)
last_document = all("#nested-documents .document").last last_document = all("#nested-documents .document-fields").last
within last_document do within last_document do
click_on "Remove document" click_on "Remove document"
end end
@@ -278,7 +278,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
visit send(path, arguments) visit send(path, arguments)
click_on "Remove document" click_on "Remove document"
expect(page).not_to have_css ".document" expect(page).not_to have_css ".document-fields"
end end
scenario "Same attachment URL after editing the title" do scenario "Same attachment URL after editing the title" do

View File

@@ -57,7 +57,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments) visit send(path, arguments)
click_link "Add image" click_link "Add image"
input_title = find(".image input[name$='[title]']") input_title = find(".image-fields input[name$='[title]']")
fill_in input_title[:id], with: "Title" fill_in input_title[:id], with: "Title"
attach_file "Choose image", file_fixture("clippy.jpg") attach_file "Choose image", file_fixture("clippy.jpg")
@@ -119,7 +119,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
click_link "Add image" click_link "Add image"
click_on submit_button click_on submit_button
within "#nested-image .image" do within "#nested-image .image-fields" do
expect(page).to have_content("can't be blank", count: 2) expect(page).to have_content("can't be blank", count: 2)
end end
end end
@@ -143,11 +143,11 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
imageable_attach_new_file(file_fixture("clippy.jpg")) imageable_attach_new_file(file_fixture("clippy.jpg"))
within "#nested-image .image" do within "#nested-image .image-fields" do
click_link "Remove image" click_link "Remove image"
end end
expect(page).not_to have_selector("#nested-image .image") expect(page).not_to have_selector("#nested-image .image-fields")
end end
scenario "Should show successful notice when resource filled correctly without any nested images", scenario "Should show successful notice when resource filled correctly without any nested images",
@@ -216,7 +216,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments) visit send(path, arguments)
expect(page).to have_css ".image", count: 1 expect(page).to have_css ".image-fields", count: 1
expect(page).not_to have_css "a#new_image_link" expect(page).not_to have_css "a#new_image_link"
end end
@@ -227,7 +227,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
visit send(path, arguments) visit send(path, arguments)
click_link "Remove image" click_link "Remove image"
expect(page).not_to have_css ".image" expect(page).not_to have_css ".image-fields"
expect(page).to have_link id: "new_image_link" expect(page).to have_link id: "new_image_link"
end end
@@ -239,7 +239,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
click_link "Remove image" click_link "Remove image"
click_link "Add image" click_link "Add image"
expect(page).to have_css ".image", count: 1, visible: :all expect(page).to have_css ".image-fields", count: 1, visible: :all
end end
end end
end end

View File

@@ -9,7 +9,7 @@ module Documents
def documentable_attach_new_file(path, success = true) def documentable_attach_new_file(path, success = true)
click_link "Add new document" click_link "Add new document"
document = all(".document").last document = all(".document-fields").last
attach_file "Choose document", path attach_file "Choose document", path
within document do within document do
@@ -22,7 +22,7 @@ module Documents
end end
def expect_document_has_title(index, title) def expect_document_has_title(index, title)
document = all(".document")[index] document = all(".document-fields")[index]
within document do within document do
expect(find("input[name$='[title]']").value).to eq title expect(find("input[name$='[title]']").value).to eq title

View File

@@ -11,7 +11,7 @@ module Images
def imageable_attach_new_file(path, success = true) def imageable_attach_new_file(path, success = true)
click_link "Add image" click_link "Add image"
within "#nested-image" do within "#nested-image" do
image = find(".image") image = find(".image-fields")
attach_file "Choose image", path attach_file "Choose image", path
within image do within image do
if success if success
@@ -40,7 +40,7 @@ module Images
end end
def expect_image_has_title(title) def expect_image_has_title(title)
image = find(".image") image = find(".image-fields")
within image do within image do
expect(find("input[name$='[title]']").value).to eq title expect(find("input[name$='[title]']").value).to eq title