{"size": 1156, "ext": "js", "max_stars_repo_path": "static/create.js", "max_stars_repo_name": "lumodon/Item-Catalog", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "static/create.js", "max_issues_repo_name": "lumodon/Item-Catalog", "max_issues_repo_issues_event_min_datetime": "2021-02-08T20:34:12.000Z", "max_issues_repo_issues_event_max_datetime": "2021-02-08T20:34:12.000Z", "max_forks_repo_path": "static/create.js", "max_forks_repo_name": "lumodon/Item-Catalog", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 33.0285714286, "max_line_length": 74, "alphanum_fraction": 0.5302768166}
import { fetchData, validateContent } from '/static/utilities.js'
import mainToaster from '/static/toaster.js'

document.addEventListener('DOMContentLoaded', () => {
  // Handle save
  Array.from(document.querySelectorAll('.controls .save-link'))
    .forEach(link => {
      link.addEventListener('click', event => {
        event.preventDefault()
        const container = document.querySelector('.content')
        const validation = validateContent(container)
        if (validation.valid) {
          fetchData(`/items/create`, {
            'owner': sessionUser.gplus_id,
            ...['description', 'name', 'category'].reduce((acc, type) => {
              acc[type] = container.querySelector(`.${type}`).value
              return acc
            }, {}),
          })
            .then(res => res.json())
            .then(serverResponse => {
              if(serverResponse.response == 'success') {
                window.location = '/'
              }
            })
        } else {
          mainToaster.pushMessage({
            type: 'error',
            payload: {...validation, interrupt: true}
          })
        }
      })
    })
})
