pacho_the_python

Untitled

Apr 10th, 2023
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     const title_input = document.getElementById('title')
  3.     const description_input = document.getElementById('description')
  4.     const select_input = document.getElementById('label')
  5.     const points_input = document.getElementById('points')
  6.     const assignee_input = document.getElementById('assignee')
  7.     const create_task_btn = document.getElementById('create-task-btn')
  8.     const tasks_section = document.getElementById('tasks-section')
  9.     const total_points_element = document.getElementById('total-sprint-points')
  10.     const delete_task_btn = document.getElementById('delete-task-btn')
  11.     const hidden_input = document.getElementById('task-id')
  12.  
  13.  
  14.     let total_points = 0
  15.  
  16.     let icons = {
  17.         'feature': '&#8865',
  18.         'low': '&#9737',
  19.         'high': '&#9888',
  20.     }
  21.  
  22.     create_task_btn.addEventListener("click", create_task)
  23.     let counter = 0
  24.     function create_task(e) {
  25.         e.preventDefault()
  26.  
  27.         counter += 1
  28.         hidden_input.value = `task-${counter}`
  29.  
  30.         let title = title_input.value
  31.         let description = description_input.value
  32.         let label = select_input.value
  33.         let points = points_input.value
  34.         let assignee = assignee_input.value
  35.  
  36.         if (title === '' || description === '' || label === '' || points === '' || assignee === '') {return}
  37.  
  38.         let article = create_element('article', '', tasks_section, `${hidden_input.value}`, 'task-card')
  39.  
  40.         let label_content = ''
  41.         let label_class = ''
  42.  
  43.         if (label === 'Feature') {
  44.             label_content = `${label} ${icons["feature"]}`
  45.             label_class = 'feature'
  46.         } else if (label === 'Low Priority Bug') {
  47.             label_content = `${label} ${icons["low"]}`
  48.             label_class = 'low-priority'
  49.         } else if (label === 'High Priority Bug') {
  50.             label_content = `${label} ${icons["high"]}`
  51.             label_class = 'high-priority'
  52.         }
  53.  
  54.         let div_label = create_element('div', '', article, '','task-card-label')
  55.         div_label.innerHTML = label_content
  56.         div_label.classList.add(label_class)
  57.  
  58.         let h3 = create_element('h3', title, article, '', 'task-card-title')
  59.         let p = create_element('p', description, article, '', 'task-card-description')
  60.         let points_div = create_element('div', `Estimated at ${points} pts`, article, '', 'task-card-points')
  61.         let assignee_div = create_element('div', `Assigned to: ${assignee}`, article, '', 'task-card-assignee')
  62.         let div_btn = create_element('div', '', article, '', 'task-card-actions')
  63.         let del_btn = create_element('button', 'Delete', div_btn, '', '', delete_element)
  64.  
  65.         total_points += Number(points)
  66.  
  67.         total_points_element.textContent = `Total Points ${total_points}pts`
  68.  
  69.         title_input.value = ''
  70.         description_input.value = ''
  71.         select_input.value = ''
  72.         points_input.value = ''
  73.         assignee_input.value = ''
  74.  
  75.     }
  76.  
  77.     function delete_element(delete_event) {
  78.         create_task_btn.disabled = true
  79.         delete_task_btn.disabled = false
  80.         let delete_article = delete_event.currentTarget.parentElement.parentElement
  81.         let data = Array.from(delete_article.children)
  82.  
  83.         title_input.value = data[1].textContent
  84.         description_input.value = data[2].textContent
  85.         points_input.value = data[3].textContent.split(' ')[2]
  86.         assignee_input.value = data[4].textContent.split(': ')[1]
  87.  
  88.         let current_value_data = data[0].textContent.split(' ')
  89.         current_value_data.pop()
  90.         select_input.value = current_value_data.join(' ')
  91.  
  92.         title_input.disabled = true
  93.         description_input.disabled = true
  94.         select_input.disabled = true
  95.         points_input.disabled = true
  96.         assignee_input.disabled = true
  97.  
  98.         delete_task_btn.addEventListener("click", total_delete_task)
  99.  
  100.         function total_delete_task() {
  101.             total_points -= Number(data[3].textContent.split(' ')[2])
  102.             delete_article.remove()
  103.             create_task_btn.disabled = false
  104.             delete_task_btn.disabled = true
  105.  
  106.             total_points_element.textContent = `Total Points ${total_points}pts`
  107.  
  108.             title_input.value = ''
  109.             description_input.value = ''
  110.             select_input.value = ''
  111.             points_input.value = ''
  112.             assignee_input.value = ''
  113.  
  114.             title_input.disabled = false
  115.             description_input.disabled = false
  116.             select_input.disabled = false
  117.             points_input.disabled = false
  118.             assignee_input.disabled = false
  119.         }
  120.     }
  121.  
  122.     function  create_element(element_type, element_content, parent_element, id, element_class, event) {
  123.         let current_element = document.createElement(element_type)
  124.         if (element_content) {
  125.             current_element.textContent = element_content
  126.         }
  127.         if (id) {
  128.             current_element.id = id
  129.         }
  130.         if (event) {
  131.             current_element.addEventListener('click', event)
  132.         }
  133.         if (element_class) {
  134.             current_element.classList.add(element_class)
  135.         }
  136.         parent_element.appendChild(current_element)
  137.         return current_element
  138.     }
  139. }
Add Comment
Please, Sign In to add comment