Skip to content

Commit

Permalink
Merge pull request #9 from moevm/kharitonov_add-edit
Browse files Browse the repository at this point in the history
Page: Add/Edit
  • Loading branch information
necitboss authored Nov 10, 2024
2 parents 34d6a2a + 621be1a commit c21e66e
Show file tree
Hide file tree
Showing 12 changed files with 592 additions and 1 deletion.
294 changes: 294 additions & 0 deletions main/_front/src/html/add-edit.html

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions main/_front/src/img/trash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 118 additions & 0 deletions main/_front/src/js/add-edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
const choiceLists = document.querySelectorAll(".choice");

choiceLists.forEach((choiceList) => {
const choiceItems = choiceList.querySelectorAll(".choice__elem");
choiceItems.forEach((choice) => {
if (choice.classList.contains("active")) {
choiceList.dataset.value = choice.dataset.value;
// console.log(choice.dataset.value);
}
choice.addEventListener("click", (e) => {
choiceItems.forEach((choice) => {
if (choice === e.target) {
choiceList.dataset.value = choice.dataset.value;
choice.classList.add("active");
console.log(choice.dataset.value);
}else {
choice.classList.remove("active");
}
});
});
});
})

const steppers = document.querySelectorAll('.stepper');
const checkMinDisabled = (element) => {
return Number(element.textContent) <= 1;
}
const checkMaxDisabled = (element, maxValue) => {
return Number(element.textContent) >= Number(maxValue);
}
const writeDataValue = (element, value) => {
element.dataset.value = value;
}

steppers.forEach(stepper => {


const minus_btn = stepper.querySelector('.stepper__minus');
const plus_btn = stepper.querySelector('.stepper__plus');
const value = stepper.querySelector('.stepper__value');
if (value.textContent) writeDataValue(stepper, value.textContent);

const max = stepper.dataset.max;

if (checkMinDisabled(value)){
minus_btn.disabled = true;
value.textContent = "1";
}
if (checkMaxDisabled(value, max)){
plus_btn.disabled = true;
value.textContent = max;
}

minus_btn.addEventListener('click', (e) => {
let count = Number(value.textContent);
if (count > 1) {
count--;
value.textContent = count;
plus_btn.disabled = false;
writeDataValue(stepper, value.textContent);
if (checkMinDisabled(value)){
minus_btn.disabled = true;
value.textContent = "1";
}
}
})

plus_btn.addEventListener('click', (e) => {
let count = Number(value.textContent);
if (count < max) {
count++;
value.textContent = count;
minus_btn.disabled = false;
writeDataValue(stepper, value.textContent);
if (checkMaxDisabled(value, max)){
plus_btn.disabled = true;
value.textContent = max;
}
}
})
})

// Начало файла, считай (все выше - скопировано из других для удобства разработки)

const input_property_name = document.querySelector("#property_name>input");
const input_property_value = document.querySelector("#property_value>input");

const properties_list = document.querySelector("#properties_list")

const handleDelete = (e) => {
e.currentTarget.parentElement.remove();
}

const property_btn = document.querySelector("#property_btn");
property_btn.addEventListener('click', (e) => {
const name = input_property_name.value;
const value = input_property_value.value;
if (name !== "" && value !== "") {
properties_list.insertAdjacentHTML('beforeend', `
<div class="property property-with-delete">
<div class="property__text">
<div class="property__name">${name}</div>
<div class="property__value">${value}</div>
</div>
<button class="property__btn">
<img src="../img/trash.svg" alt="">
</button>
</div>
`)
properties_list.querySelectorAll(".property .property__btn").forEach(button => {
button.removeEventListener("click", handleDelete);
button.addEventListener("click", handleDelete);
})
input_property_name.value = "";
input_property_value.value = "";
}
})

2 changes: 1 addition & 1 deletion main/_front/src/scss/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ body {
border: 1px solid #d8d8d8;
background-color: #F8F8F8;
border-radius: 10px;
}
}
36 changes: 36 additions & 0 deletions main/_front/src/scss/blocks/_add-center.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.add-center {
width: 468px;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
flex: 1;
}

.add-center__input {
width: 100%;
}

.add-center__price {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
}


.add-center__count {
display: flex;
align-items: center;
column-gap: 50px;
}

.add-center__properties {
width: 100%;
display: flex;
flex-direction: column;
row-gap: 10px;
max-height: 385px;
overflow-y: auto;
}
25 changes: 25 additions & 0 deletions main/_front/src/scss/blocks/_add-edit.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.add-edit {
margin-bottom: 20px;
}

.add-edit__inner {
display: flex;
justify-content: space-between;
}

.add-edit__choice {
width: 276px;
padding: 20px;
}

.add-edit__choice-subtitle {
margin-bottom: 20px;
}

.add-edit__center {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
row-gap: 20px;
}
27 changes: 27 additions & 0 deletions main/_front/src/scss/blocks/_add-right.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.add-right {
width: 276px;
padding: 20px 10px;
display: flex;
flex-direction: column;
align-items: center;
row-gap: 20px;
}

.add-right__choices {
display: flex;
flex-direction: column;
align-items: center;
row-gap: 20px;
max-height: 330px;
overflow-y: auto;
}

.add-right__choice-title {
font-size: 18px;
line-height: 21px;
margin-bottom: 10px;
}

.add-right__choice {
width: 100%;
}
26 changes: 26 additions & 0 deletions main/_front/src/scss/blocks/_form.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.form {
width: 100%;
height: calc(100vh - 2*163px);
display: flex;
justify-content: center;
align-items: center;
}

.form__inner {
width: 400px;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
row-gap: 20px;
}

.form__title {
font-size: 24px;
line-height: 28px;
font-weight: 700;
}

.form__input {
width: 100%;
}
6 changes: 6 additions & 0 deletions main/_front/src/scss/blocks/_subtitle.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.subtitle {
font-size: 24px;
line-height: 28px;
text-align: center;
font-weight: 700;
}
5 changes: 5 additions & 0 deletions main/_front/src/scss/elems/_btn.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
border: 1px solid $primary;
padding: 12px;
transition: background-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
&-big {
min-width: 275px;
font-size: 24px;
line-height: 28px;
}
&:hover {
background-color:#fff;
color: $primary;
Expand Down
1 change: 1 addition & 0 deletions main/_front/src/scss/elems/_input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.input{
position: relative;
background-color: #fff;
}

.input__text{
Expand Down
39 changes: 39 additions & 0 deletions main/_front/src/scss/elems/_property.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.property {
justify-content: space-between;
align-items: center;
text-align: left;
background-color: #EDEDED;
border-radius: 10px;
&-with-delete {
display: flex;

}
}

.property__text {
padding: 10px 15px;
}

.property__name {
font-size: 16px;
line-height: 19px;
color: #555;
margin-bottom: 5px;
}

.property__value {
font-size: 18px;
line-height: 21px;
font-weight: 500;
}

.property__btn {
padding: 10px;
border-radius: 10px;
background-color: #DC3545;
cursor: pointer;
transition: background-color .2s ease;
&:hover {
background-color: darken(#DC3545, 5%);
}
}

0 comments on commit c21e66e

Please sign in to comment.