diff --git a/src/Components/FormInputs/CurrencyInput/CurrencyInput.js b/src/Components/FormInputs/CurrencyInput/CurrencyInput.js deleted file mode 100644 index 8e1a1c0..0000000 --- a/src/Components/FormInputs/CurrencyInput/CurrencyInput.js +++ /dev/null @@ -1,16 +0,0 @@ -import { Component } from '@/modules/Components/Component'; -import { ValidatedInputController } from '@/Components/FormInputs/ValidatedInput/ValidatedInputController'; -import { ValidatedInputView } from '@/Components/FormInputs/ValidatedInput/ValidatedInputView'; -import { CurrencyInputModel } from './CurrencyInputModel'; - -export class CurrencyInput extends Component { - constructor({ existingElement, selfValidate = false }) { - super({ - modelClass: CurrencyInputModel, - controllerClass: ValidatedInputController, - viewClass: ValidatedInputView, - existingElement, - controllerParams: { selfValidate }, - }); - } -} diff --git a/src/Components/FormInputs/CurrencyInput/CurrencyInputModel.js b/src/Components/FormInputs/CurrencyInput/CurrencyInputModel.js deleted file mode 100644 index 1d5158b..0000000 --- a/src/Components/FormInputs/CurrencyInput/CurrencyInputModel.js +++ /dev/null @@ -1,9 +0,0 @@ -import { ValidatedInputModel } from '@/Components/FormInputs/ValidatedInput/ValidatedInputModel'; - -export class CurrencyInputModel extends ValidatedInputModel { - validate(numberStr) { - numberStr = numberStr.trim(); - const matches = numberStr.match(/^[0-9]+$/); - return matches ? '' : 'Тут нужно ввести целое число'; - } -} diff --git a/src/Components/VacancyForm/VacancyForm.js b/src/Components/VacancyForm/VacancyForm.js deleted file mode 100644 index 8d6b3fe..0000000 --- a/src/Components/VacancyForm/VacancyForm.js +++ /dev/null @@ -1,73 +0,0 @@ -import { Component } from '@/modules/Components/Component'; -import { LiteralInput } from '@/Components/FormInputs/LiteralInput/LiteralInput'; -import { CityInput } from '@/Components/FormInputs/CityInput/CityInput'; -import { CurrencyInput } from '@/Components/FormInputs/CurrencyInput/CurrencyInput'; -import { TextInput } from '@/Components/FormInputs/TextInput/TextInput'; -import { ValidatedTextArea } from '@/Components/FormInputs/ValidatedTextArea/ValidatedTextArea'; -import { VacancyFormController } from './VacancyFormController'; -import { VacancyFormModel } from './VacancyFormModel'; -import { VacancyFormView } from './VacancyFormView'; -import { SelectInput } from '../FormInputs/SelectInput/SelectInput'; -import vacancySearchConfig from '@/config/vacancy_search.json'; - -export class VacancyForm extends Component { - #isNew; - constructor({ vacancyId = null, elementClass, existingElement }) { - super({ - modelClass: VacancyFormModel, - viewClass: VacancyFormView, - controllerClass: VacancyFormController, - modelParams: { vacancyId }, - existingElement, - viewParams: { elementClass, isNew: !vacancyId, vacancyId }, - }); - this.#isNew = !vacancyId; - this._positionField = new TextInput({ - existingElement: this._view.positionField, - selfValidate: true, - }); - this._workTypeField = new LiteralInput({ - existingElement: this._view.workTypeField, - selfValidate: true, - }); - this._salaryField = new CurrencyInput({ - existingElement: this._view.salaryField, - selfValidate: true, - }); - this._locationField = new CityInput({ - existingElement: this._view.locationField, - selfValidate: true, - }); - this._descriptionField = new ValidatedTextArea({ - existingElement: this._view.descriptionField, - selfValidate: true, - }); - this._groupField = new SelectInput( - { - options: [ - { value: '', caption: 'Не указывать' }, - ...vacancySearchConfig.searchGroupOptions, - ], - }, - this._view.groupField, - ); - this._children.push( - this._positionField, - this._workTypeField, - this._locationField, - this._descriptionField, - this._groupField, - ); - if (!this.#isNew) { - this.reset(); - } - } - - get view() { - return this._view; - } - - reset() { - return this._controller.reset(); - } -} diff --git a/src/Components/VacancyForm/VacancyFormController.js b/src/Components/VacancyForm/VacancyFormController.js deleted file mode 100644 index d08d663..0000000 --- a/src/Components/VacancyForm/VacancyFormController.js +++ /dev/null @@ -1,83 +0,0 @@ -import { ComponentController } from '@/modules/Components/Component'; -import { NOTIFICATION_OK, REDIRECT_TO, SUBMIT_FORM } from '@/modules/Events/Events'; -import { Vacancy } from '@/modules/models/Vacancy'; -import { VacancyPage } from '@/Pages/VacancyPage/VacancyPage'; -import { resolveUrl } from '@/modules/common_utils/url_utils/url_utils'; -import eventBus from '@/modules/Events/EventBus'; -import { NOTIFICATION_ERROR } from '@/modules/Events/Events'; -import { NOTIFICATION_TIMEOUT } from '@/Components/NotificationBox/NotificationBox'; -import { catchStandardResponseError } from '@/modules/app_errors/Errors'; - -export class VacancyFormController extends ComponentController { - constructor(model, view, controller) { - super(model, view, controller); - this.setHandlers([ - { - event: SUBMIT_FORM, - handler: this.submit.bind(this), - }, - ]); - } - - _validate() { - const errorMessage = this._model.validate(this._view.getData()); - if (errorMessage) { - eventBus.emit(NOTIFICATION_ERROR, { - message: errorMessage, - timeout: NOTIFICATION_TIMEOUT.MEDIUM, - }); - return false; - } - return [ - this._component._positionField.controller.validateInput({ - callerView: this._component._positionField._view, - }), - - this._component._salaryField.controller.validateInput({ - callerView: this._component._salaryField._view, - }), - - this._component._workTypeField.controller.validateInput({ - callerView: this._component._workTypeField._view, - }), - - this._component._locationField.controller.validateInput({ - callerView: this._component._locationField._view, - }), - - this._component._descriptionField.controller.validateInput({ - callerView: this._component._descriptionField._view, - }), - ].every((val) => val); - } - - async submit({ caller }) { - if (!Object.is(caller, this._view)) { - return; - } - if (!this._validate()) { - return; - } - try { - const vacancy = await this._model.submit(new Vacancy(this._view.getData())); - if (!vacancy) { - return; - } - const query = {}; - query[VacancyPage.VACANCY_ID_PARAM] = vacancy.id; - eventBus.emit(NOTIFICATION_OK, { - message: 'Операция проведена успешно', - timeout: NOTIFICATION_TIMEOUT.MEDIUM, - }); - eventBus.emit(REDIRECT_TO, { redirectUrl: resolveUrl('vacancy', query) }); - } catch (err) { - catchStandardResponseError(err); - } - } - - async reset() { - const oldData = await this._model.getLastValidData(); - this._view.renderData(oldData); - return true; - } -} diff --git a/src/Components/VacancyForm/VacancyFormModel.js b/src/Components/VacancyForm/VacancyFormModel.js deleted file mode 100644 index ca30bcb..0000000 --- a/src/Components/VacancyForm/VacancyFormModel.js +++ /dev/null @@ -1,55 +0,0 @@ -import { ComponentModel } from '@/modules/Components/Component'; -import { Vacancy } from '@/modules/models/Vacancy'; -import { resolveUrl } from '@/modules/common_utils/url_utils/url_utils'; -import { zip } from '@common_utils/object_utils/zip'; -import eventBus from '@/modules/Events/EventBus'; -import { REDIRECT_TO } from '@/modules/Events/Events'; -import { getVacancy, createVacancy, updateVacancy } from '@/modules/api/api'; -import appState from '@/modules/AppState/AppState'; - -export class VacancyFormModel extends ComponentModel { - #lastValidData; - #vacancyId; - #isNew; - - constructor({ vacancyId = null }) { - super(); - this.#vacancyId = vacancyId; - this.#isNew = !this.#vacancyId; - this.#lastValidData = this.#vacancyId - ? getVacancy(appState.backendUrl, this.#vacancyId).then( - (vacancy) => new Vacancy(vacancy), - () => { - eventBus.emit(REDIRECT_TO, { redirectUrl: resolveUrl('createVacancy') }); - }, - ) - : null; - } - - async getLastValidData() { - return this.#lastValidData; - } - - async submit(formData) { - const vacancy = this.#isNew - ? await createVacancy(appState.backendUrl, formData) - : await updateVacancy(appState.backendUrl, zip({ id: this.#vacancyId }, formData)); - if (vacancy) { - this.#lastValidData = formData; - return vacancy; - } - return null; - } - - validate(formData) { - const hasEmptyFields = Object.entries(formData).some(([fieldKey, fieldValue]) => { - if (fieldKey === 'salary' || fieldKey === 'positionGroup') { - return false; - } - return !fieldValue.trim(); - }); - if (hasEmptyFields) { - return 'Заполните пустые поля'; - } - } -} diff --git a/src/Components/VacancyForm/VacancyFormView.js b/src/Components/VacancyForm/VacancyFormView.js deleted file mode 100644 index 448b77e..0000000 --- a/src/Components/VacancyForm/VacancyFormView.js +++ /dev/null @@ -1,48 +0,0 @@ -import { ComponentView } from '@/modules/Components/Component'; -import eventBus from '@/modules/Events/EventBus'; -import { SUBMIT_FORM } from '@/modules/Events/Events'; -import { addEventListeners } from '@/modules/Events/EventUtils'; -import { getFormData } from '@/modules/FormUtils/FormUtils'; -import VacancyFormHbs from './vacancy-form.hbs'; - -export class VacancyFormView extends ComponentView { - constructor({ elementClass, isNew, vacancyId }, existingElement) { - super({ - renderParams: { elementClass, isNew, vacancyId }, - existingElement, - template: VacancyFormHbs, - }); - this.positionField = this._html.querySelector('.vacancy-form__position'); - this.workTypeField = this._html.querySelector('.vacancy-form__work-type'); - this.locationField = this._html.querySelector('.vacancy-form__location'); - this.salaryField = this._html.querySelector('.vacancy-form__salary'); - this.descriptionField = this._html.querySelector('.vacancy-form__description'); - this.groupField = this._html.querySelector('.vacancy-form__group'); - this._eventListeners.push({ - event: 'submit', - object: this._html, - listener: function (ev) { - ev.preventDefault(); - eventBus.emit(SUBMIT_FORM, { caller: this }); - }.bind(this), - }); - addEventListeners(this._eventListeners); - } - - getData() { - return getFormData(this._html); - } - - getId() { - return 'vacancy-form'; - } - - renderData({ position, workType, salary, location, description, positionGroup }) { - this.positionField.querySelector('.validated-input__input').value = position; - this.workTypeField.querySelector('.validated-input__input').value = workType; - this.locationField.querySelector('.validated-input__input').value = location; - this.salaryField.querySelector('.validated-input__input').value = salary; - this.descriptionField.querySelector('.validated-textarea__textarea').value = description; - this.groupField.querySelector('.select-input__select').value = positionGroup; - } -} diff --git a/src/Components/VacancyForm/vacancy-form.hbs b/src/Components/VacancyForm/vacancy-form.hbs deleted file mode 100644 index 0d03e4e..0000000 --- a/src/Components/VacancyForm/vacancy-form.hbs +++ /dev/null @@ -1,20 +0,0 @@ -
\ No newline at end of file diff --git a/src/Pages/VacancyEditPage/VacancyEditPage.js b/src/Pages/VacancyEditPage/VacancyEditPage.js deleted file mode 100644 index 5dd4dc6..0000000 --- a/src/Pages/VacancyEditPage/VacancyEditPage.js +++ /dev/null @@ -1,59 +0,0 @@ -import { Header } from '@/Components/Header/Header'; -import state from '@/modules/AppState/AppState'; -import { Page } from '@/modules/Page/Page'; -import { ForbiddenPage, NotFoundError } from '@/modules/Router/Router'; -import { resolveUrl } from '@/modules/common_utils/url_utils/url_utils'; -import { VacancyEditPageController } from './VacancyEditPageController'; -import { VacancyEditPageModel } from './VacancyEditPageModel'; -import { VacancyEditPageView } from './VacancyEditPageView'; -import { VacancyForm } from '@/Components/VacancyForm/VacancyForm'; -import USER_TYPE from '@/modules/UserSession/UserType'; -import { zip } from '@common_utils/object_utils/zip'; - -export class VacancyEditPage extends Page { - #vacancyId; - - static VACANCY_ID_PARAM = 'id'; - - constructor({ url }) { - if (state.userSession.userType !== USER_TYPE.EMPLOYER) { - throw new ForbiddenPage(resolveUrl('vacancies')); - } - let vacancyId; - switch (url.pathname) { - case resolveUrl('editVacancy').pathname: { - vacancyId = +url.searchParams.get(VacancyEditPage.VACANCY_ID_PARAM); - if (!vacancyId && vacancyId !== 0) { - throw new NotFoundError(); - } - break; - } - case resolveUrl('createVacancy').pathname: { - vacancyId = null; - break; - } - } - super({ - url, - modelClass: VacancyEditPageModel, - viewClass: VacancyEditPageView, - controllerClass: VacancyEditPageController, - viewParams: zip(Header.getViewParams(), { isNew: !vacancyId }), - }); - this.#vacancyId = vacancyId; - } - - postRenderInit() { - this._header = new Header({ - existingElement: this._view.header, - }); - this._children.push(this._header); - this._vacancyForm = new VacancyForm({ - userId: state.userSession.userId, - vacancyId: this.#vacancyId, - elementClass: 'vacancy-edit-page__vacancy-form', - }); - this._children.push(this._vacancyForm); - this._controller.addVacancyForm(this._vacancyForm); - } -} diff --git a/src/Pages/VacancyEditPage/VacancyEditPageController.js b/src/Pages/VacancyEditPage/VacancyEditPageController.js deleted file mode 100644 index 28074f8..0000000 --- a/src/Pages/VacancyEditPage/VacancyEditPageController.js +++ /dev/null @@ -1,11 +0,0 @@ -import { PageController } from '@/modules/Page/Page'; - -export class VacancyEditPageController extends PageController { - constructor(model, view, component) { - super(model, view, component); - } - - addVacancyForm(vacancyForm) { - this._view.addVacancyForm(vacancyForm.render()); - } -} diff --git a/src/Pages/VacancyEditPage/VacancyEditPageModel.js b/src/Pages/VacancyEditPage/VacancyEditPageModel.js deleted file mode 100644 index d16f079..0000000 --- a/src/Pages/VacancyEditPage/VacancyEditPageModel.js +++ /dev/null @@ -1,3 +0,0 @@ -import { PageModel } from '@/modules/Page/Page'; - -export class VacancyEditPageModel extends PageModel {} diff --git a/src/Pages/VacancyEditPage/VacancyEditPageView.js b/src/Pages/VacancyEditPage/VacancyEditPageView.js deleted file mode 100644 index e66f326..0000000 --- a/src/Pages/VacancyEditPage/VacancyEditPageView.js +++ /dev/null @@ -1,19 +0,0 @@ -import { PageView } from '@/modules/Page/Page'; -import VacancyPageEditHbs from './vacancy-page-edit.hbs'; - -export class VacancyEditPageView extends PageView { - constructor(renderParams) { - renderParams.isEmployer = !renderParams.isApplicant && renderParams.isAuthorized; - super({ - template: VacancyPageEditHbs, - renderParams: renderParams, - }); - this.header = this._html.querySelector('.header'); - this.formBox = this._html.querySelector('.vacancy-page-edit__form-container'); - } - - addVacancyForm(formRender) { - this.vacancyForm = formRender; - this.formBox.appendChild(formRender); - } -} diff --git a/src/Pages/VacancyEditPage/vacancy-page-edit.hbs b/src/Pages/VacancyEditPage/vacancy-page-edit.hbs deleted file mode 100644 index b62b7c7..0000000 --- a/src/Pages/VacancyEditPage/vacancy-page-edit.hbs +++ /dev/null @@ -1,8 +0,0 @@ -