Compare commits
2 commits
23240005a2
...
0c615043f2
Author | SHA1 | Date | |
---|---|---|---|
0c615043f2 | |||
0011fdf76a |
4 changed files with 98 additions and 89 deletions
|
@ -1,21 +1,23 @@
|
||||||
const userListSections = document.querySelectorAll(
|
function setFormStateCookie(value) {
|
||||||
".item-header .user-lists-section");
|
const thirtyDays = 60 * 60 * 24 * 30;
|
||||||
for (const section of userListSections) {
|
document.cookie = `DTIItemPageUserListsFormState=open;max-age=${thirtyDays}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const headers = document.querySelectorAll(".item-header");
|
||||||
|
for (const header of headers) {
|
||||||
try {
|
try {
|
||||||
const dialog = section.querySelector("dialog");
|
const form = header.querySelector(".user-lists-form");
|
||||||
const opener = section.querySelector(".dialog-opener");
|
const opener = header.querySelector(".user-lists-form-opener");
|
||||||
const closer = section.querySelector(".dialog-closer");
|
opener.addEventListener("click", (event) => {
|
||||||
if (dialog.showModal) { // check browser support
|
if (form.hasAttribute("hidden")) {
|
||||||
opener.addEventListener("click", (event) => {
|
form.removeAttribute("hidden");
|
||||||
dialog.show();
|
setFormStateCookie("open");
|
||||||
event.preventDefault();
|
} else {
|
||||||
});
|
form.setAttribute("hidden", "");
|
||||||
document.body.addEventListener("click", (event) => {
|
setFormStateCookie("closed");
|
||||||
if (dialog.open && !section.contains(event.target)) {
|
}
|
||||||
dialog.close();
|
event.preventDefault();
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error applying dialog behavior to item header:`, error);
|
console.error(`Error applying dialog behavior to item header:`, error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,57 +59,59 @@
|
||||||
background: #E2E8F0
|
background: #E2E8F0
|
||||||
color: #1A202C
|
color: #1A202C
|
||||||
|
|
||||||
.user-lists-section
|
.user-lists-info
|
||||||
grid-area: lists
|
grid-area: lists
|
||||||
font-size: 85%
|
font-size: 85%
|
||||||
text-align: left
|
text-align: left
|
||||||
|
|
||||||
.dialog-opener
|
.user-lists-form-opener
|
||||||
&::after
|
&::after
|
||||||
content: " ›"
|
content: " ›"
|
||||||
|
|
||||||
dialog
|
.user-lists-form
|
||||||
background: $background-color
|
background: $background-color
|
||||||
border: 1px solid $module-border-color
|
border: 1px solid $module-border-color
|
||||||
border-radius: .5em
|
border-radius: .5em
|
||||||
padding: 1em
|
padding: 1em
|
||||||
width: 30em
|
width: 30em
|
||||||
text-align: center
|
text-align: center
|
||||||
z-index: 2
|
z-index: 2
|
||||||
margin-top: .5em
|
margin-top: .5em
|
||||||
box-shadow: 0px 1px 4px #666
|
margin-inline: auto
|
||||||
|
margin-bottom: 1.5em
|
||||||
|
font-size: 85%
|
||||||
|
|
||||||
h3
|
h3
|
||||||
font-size: 150%
|
font-size: 150%
|
||||||
font-weight: bold
|
font-weight: bold
|
||||||
margin-bottom: .25em
|
margin-bottom: .75em
|
||||||
|
|
||||||
.closet-hangers-ownership-groups
|
.closet-hangers-ownership-groups
|
||||||
+clearfix
|
+clearfix
|
||||||
margin-bottom: .5em
|
margin-bottom: .5em
|
||||||
|
|
||||||
div
|
div
|
||||||
float: left
|
float: left
|
||||||
margin: 0 5%
|
margin: 0 5%
|
||||||
text-align: left
|
text-align: left
|
||||||
width: 40%
|
width: 40%
|
||||||
|
|
||||||
li
|
li
|
||||||
list-style: none
|
list-style: none
|
||||||
word-wrap: break-word
|
word-wrap: break-word
|
||||||
|
|
||||||
label.unlisted
|
label.unlisted
|
||||||
font-style: italic
|
font-style: italic
|
||||||
|
|
||||||
form
|
form
|
||||||
padding: .5em 0
|
padding: .5em 0
|
||||||
|
|
||||||
select
|
select
|
||||||
width: 9em
|
width: 9em
|
||||||
|
|
||||||
input[type=number]
|
input[type=number]
|
||||||
margin-right: .5em
|
margin-right: .5em
|
||||||
width: 3em
|
width: 3em
|
||||||
|
|
||||||
.item-description
|
.item-description
|
||||||
margin-top: .5em
|
margin-top: .5em
|
||||||
|
|
|
@ -118,5 +118,9 @@ module ItemsHelper
|
||||||
human_name = pet_type.species.name.humanize
|
human_name = pet_type.species.name.humanize
|
||||||
image_tag(src, :alt => human_name, :title => human_name)
|
image_tag(src, :alt => human_name, :title => human_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def item_header_user_lists_form_state
|
||||||
|
cookies.fetch("DTIItemPageUserListsFormState", "closed")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -31,42 +31,43 @@
|
||||||
= link_to t('items.show.resources.auction_genie'), auction_genie_url_for(item)
|
= link_to t('items.show.resources.auction_genie'), auction_genie_url_for(item)
|
||||||
|
|
||||||
- if user_signed_in?
|
- if user_signed_in?
|
||||||
.user-lists-section
|
.user-lists-info
|
||||||
= link_to t('items.show.closet_hangers.button'),
|
= link_to t('items.show.closet_hangers.button'),
|
||||||
user_closet_hangers_path(current_user),
|
user_closet_hangers_path(current_user),
|
||||||
class: 'dialog-opener'
|
class: 'user-lists-form-opener'
|
||||||
%dialog
|
|
||||||
%h3
|
|
||||||
= t 'items.show.closet_hangers.header_html',
|
|
||||||
user_items_link: link_to(t('your_items'),
|
|
||||||
user_closet_hangers_path(current_user))
|
|
||||||
= form_tag update_quantities_user_item_closet_hangers_path(:user_id => current_user, :item_id => item), :method => :put do
|
|
||||||
.closet-hangers-ownership-groups
|
|
||||||
- [true, false].each do |owned|
|
|
||||||
- lists = current_user_lists[owned]
|
|
||||||
%div
|
|
||||||
%h4= closet_lists_group_name(:you, owned)
|
|
||||||
%ul
|
|
||||||
- lists.each_with_index do |list, index|
|
|
||||||
%li
|
|
||||||
= number_field_tag "quantity[#{list.id}]",
|
|
||||||
current_user_quantities[list.id], min: 0,
|
|
||||||
autofocus: owned && index == 0
|
|
||||||
= label_tag "quantity[#{list.id}]", list.name
|
|
||||||
|
|
||||||
%li
|
- if user_signed_in?
|
||||||
= number_field_tag "quantity[#{owned}]",
|
= form_tag update_quantities_user_item_closet_hangers_path(user_id: current_user, item_id: item), method: :put, class: 'user-lists-form', hidden: item_header_user_lists_form_state != "open" do
|
||||||
current_user_quantities[owned], min: 0,
|
%h3
|
||||||
autofocus: owned && lists.empty?
|
= t 'items.show.closet_hangers.header_html',
|
||||||
|
user_items_link: link_to(t('your_items'),
|
||||||
|
user_closet_hangers_path(current_user))
|
||||||
|
.closet-hangers-ownership-groups
|
||||||
|
- [true, false].each do |owned|
|
||||||
|
- lists = current_user_lists[owned]
|
||||||
|
%div
|
||||||
|
%h4= closet_lists_group_name(:you, owned)
|
||||||
|
%ul
|
||||||
|
- lists.each_with_index do |list, index|
|
||||||
|
%li
|
||||||
|
= number_field_tag "quantity[#{list.id}]",
|
||||||
|
current_user_quantities[list.id], min: 0,
|
||||||
|
autofocus: owned && index == 0
|
||||||
|
= label_tag "quantity[#{list.id}]", list.name
|
||||||
|
|
||||||
- unless lists.empty?
|
%li
|
||||||
= label_tag "quantity[#{owned}]",
|
= number_field_tag "quantity[#{owned}]",
|
||||||
t('closet_lists.unlisted_name'),
|
current_user_quantities[owned], min: 0,
|
||||||
:class => 'unlisted'
|
autofocus: owned && lists.empty?
|
||||||
- else
|
|
||||||
= label_tag "quantity[#{owned}]",
|
- unless lists.empty?
|
||||||
t('items.show.closet_hangers.quantity_label')
|
= label_tag "quantity[#{owned}]",
|
||||||
= submit_tag t('items.show.closet_hangers.submit')
|
t('closet_lists.unlisted_name'),
|
||||||
|
:class => 'unlisted'
|
||||||
|
- else
|
||||||
|
= label_tag "quantity[#{owned}]",
|
||||||
|
t('items.show.closet_hangers.quantity_label')
|
||||||
|
= submit_tag t('items.show.closet_hangers.submit')
|
||||||
|
|
||||||
%p.item-description= item.description
|
%p.item-description= item.description
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue