-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from frontend-park-mail-ru/e8branch
МР для РК2
- Loading branch information
Showing
40 changed files
with
2,030 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
/node_modules | ||
/node_modules | ||
/public/components/*/*.precompiled.js | ||
/public/config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
async function loadCategories() { | ||
const selectElement = document.createElement('select'); | ||
try { | ||
const request = { headers: {} }; | ||
const response = await api.get('/categories', request); | ||
const categories = await response.json(); | ||
|
||
// Заполнение выпадающего списка | ||
categories.forEach(category => { | ||
const option = document.createElement('option'); | ||
option.value = category.id; // id категории | ||
option.textContent = category.name; // название категории | ||
selectElement.appendChild(option); | ||
}); | ||
|
||
} catch (error) { | ||
console.error('Ошибка при загрузке категорий:', error); | ||
} | ||
return categorySelect; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.edit_container { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{{#each items}} | ||
|
||
{{#if this.needPlaceholder}} | ||
<div style = ".edit_container"> | ||
<label>{{this.text}}</label> | ||
<{{this.tag}} class="{{this.className}}" id = "{{this.key}}" placeholder = "{{this.text}}" type="{{this.type}}" data-section="{{this.key}}"></{{this.tag}}> | ||
</div> | ||
|
||
{{else}} | ||
<{{this.tag}} class="{{this.className}}" id = "{{this.key}}" data-section="{{this.key}}">{{this.text}}</{{this.tag}}> | ||
{{/if}} | ||
|
||
{{/each}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/** | ||
* EditEventForm class | ||
*/ | ||
import { api } from '../../modules/FrontendAPI.js'; | ||
|
||
|
||
export class EditEventForm { | ||
constructor(formId) { | ||
this.form = document.createElement('form'); | ||
this.form.id = formId; | ||
this.form.className = 'event-edit-form'; | ||
} | ||
async init(id) { | ||
const path = `/events/${id}`; | ||
const request = { headers: {} }; | ||
try { | ||
const response = await api.get(path, request); | ||
const event = await response.json(); | ||
this._renderEvent(event); | ||
} catch (error) { | ||
console.log(error); | ||
console.log("Ошибка при загрузке события"); | ||
} | ||
} | ||
_renderEvent(event) { | ||
const mapping = { | ||
title: 'eventNameEntry', | ||
image: 'imageInput', | ||
description: 'eventDescriptionEntry', | ||
category_id: 'categories', | ||
|
||
}; | ||
const time = { | ||
event_start: 'eventBeginEntry', | ||
event_end: 'eventEndEntry', | ||
}; | ||
for (const key in mapping) { | ||
const inputElement = this.form.querySelector(`[id="${mapping[key]}"]`); | ||
if (inputElement) { | ||
if (mapping[key] === 'imageInput') { | ||
inputElement.src = event[key]; | ||
} else { | ||
inputElement.value = event[key]; | ||
} | ||
} | ||
} | ||
for (const key in time) { | ||
const inputElement = this.form.querySelector(`[id="${time[key]}"]`); | ||
if (inputElement) { | ||
inputElement.value = formatDateTimeForInput(event[key]); | ||
} | ||
} | ||
} | ||
config = { | ||
eventServerError: { | ||
text: '', | ||
tag: 'label', | ||
className: 'event-edit-form__error-text', | ||
type: '', | ||
}, | ||
eventAddLabel: { | ||
text: 'Редактировать мероприятие', | ||
tag: 'label', | ||
className: 'event-edit-form__title', | ||
type: '', | ||
}, | ||
eventNameEntry: { | ||
text: 'Название мероприятия', | ||
tag: 'input', | ||
type: 'text', | ||
className: 'event-edit-form__input', | ||
}, | ||
eventNameError: { | ||
text: '', | ||
tag: 'label', | ||
className: 'event-edit-form__error-text', | ||
type: '', | ||
}, | ||
eventDescriptionEntry: { | ||
text: 'Описание мероприятия', | ||
tag: 'textarea', | ||
type: '', | ||
className: 'event-edit-form__textarea', | ||
}, | ||
eventDescriptionError: { | ||
text: '', | ||
tag: 'label', | ||
className: 'event-edit-form__error-text', | ||
type: '', | ||
}, | ||
eventTagEntry: { | ||
text: 'Тэги (не более 3 штук)', | ||
tag: 'input', | ||
type: 'text', | ||
className: 'event-edit-form__input', | ||
}, | ||
eventTagsError: { | ||
text: '', | ||
tag: 'label', | ||
className: 'event-edit-form__error-text', | ||
type: '', | ||
}, | ||
eventBeginEntry: { | ||
text: 'Время начала мероприятия', | ||
tag: 'input', | ||
type: 'datetime-local', | ||
className: 'event-edit-form__input event-edit-form__input--datetime-local', | ||
}, | ||
eventBeginError: { | ||
text: '', | ||
tag: 'label', | ||
className: 'event-edit-form__error-text', | ||
type: '', | ||
}, | ||
eventEndEntry: { | ||
text: 'Время окончания мероприятия', | ||
tag: 'input', | ||
type: 'datetime-local', | ||
className: 'event-edit-form__input event-edit-form__input--datetime-local', | ||
}, | ||
eventEndError: { | ||
text: '', | ||
tag: 'label', | ||
className: 'event-edit-form__error-text', | ||
type: '', | ||
}, | ||
imageInput: { | ||
text: '', | ||
tag: 'input', | ||
className: 'event-edit-form__input event-edit-form__input--file', | ||
type: 'file', | ||
accept: "image/png, image/jpeg", | ||
}, | ||
categories: { | ||
text: '', | ||
tag: 'div', | ||
className: 'event-edit-form__categories-select', | ||
type: '', | ||
}, | ||
editSubmitBtn: { | ||
text: 'Изменить', | ||
tag: 'button', | ||
type: 'submit', | ||
className: 'event-edit-form__submit-btn', | ||
}, | ||
}; | ||
/** | ||
* Renders the form template | ||
* @returns {HTMLFormElement} The rendered form | ||
*/ | ||
renderTemplate(selectElement) { | ||
const template = Handlebars.templates['EditEventForm.hbs']; | ||
const config = this.config; | ||
const itemsArray = Object.entries(config); | ||
const items = itemsArray.map(([key, { tag, text, className, type }]) => ({ | ||
key, | ||
tag, | ||
text, | ||
className, | ||
type, | ||
needPlaceholder: tag === 'input', | ||
needMaxMinTime: type === 'time', | ||
})); | ||
this.form.innerHTML = template({ items }); | ||
const categoriesSelect = selectElement; | ||
categoriesSelect.classList.add('event-edit-form__categories'); | ||
categoriesSelect.id = 'categoriesInput'; | ||
this.form.insertBefore(categoriesSelect, this.form.querySelector('.event-edit-form__submit-btn')); | ||
return this.form; | ||
} | ||
} | ||
function formatDateTimeForInput(dateTime) { | ||
const date = new Date(dateTime); | ||
const year = date.getFullYear(); | ||
const month = String(date.getMonth() + 1).padStart(2, '0'); // Months are 0-indexed | ||
const day = String(date.getDate()).padStart(2, '0'); | ||
const hours = String(date.getHours()).padStart(2, '0'); | ||
const minutes = String(date.getMinutes()).padStart(2, '0'); | ||
return `${year}-${month}-${day}T${hours}:${minutes}`; | ||
} |
Oops, something went wrong.