Advertisement
VladislavNechepaev

Untitled

Dec 11th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (/\/support\/tickets\/\d*/.test(window.location.pathname)) {
  2.       console.log(jQuery('.item-name').text())
  3.        
  4.       const itemName = "Ringteam Inventory"
  5.       const rawDataFieldName = "Raw_data"
  6.          
  7.       if (jQuery('.item-name').text() === itemName) {
  8.         jQuery('.redactor_box').hide()
  9.         jQuery('.control-group').hide()
  10.         const commentNative = jQuery('.redactor_editor p')
  11.              
  12.         console.log('ELEM PROBING')
  13.         const rawDataElem = jQuery(`[for=${rawDataFieldName}]`).parent()
  14.         const rawDataText = rawDataElem.find("pre").text()
  15.         const rawData = JSON.parse(rawDataText)
  16.         console.log(rawData)
  17.          
  18.         console.log('rendering items for requester')
  19.         renderItemList(rawData)
  20.          
  21.         const replyTable = createReplyTable(rawData)
  22.         jQuery('.redactor_box').parent().append(replyTable)
  23.          
  24.         function createReplyTable(data){
  25.           const table = document.createElement("table")
  26.           rawData.forEach(item => {
  27.             const row = document.createElement("tr")
  28.             row.id = item.asset_tag
  29.             const itemName = document.createElement("td")
  30.             itemName.innerHTML = item.display_name
  31.             itemName.style.fontWeight = "bold"
  32.             itemName.style.margin = "5px"
  33.             itemName.style.textAlign = "right"
  34.             const isConfirmed = document.createElement("td")
  35.             const checkbox = document.createElement("input")
  36.             checkbox.type = "checkbox"
  37.             checkbox.id = "check_" + item.asset_tag
  38.             checkbox.onchange = function(){ renderController() }
  39.             const label = document.createElement("label")
  40.             label.htmlFor = "check_" + item.asset_tag
  41.             label.innerHTML = "Confirm"
  42.             label.style.margin = "5px"
  43.             label.style.display = "inline"
  44.             isConfirmed.appendChild(label)
  45.             isConfirmed.appendChild(checkbox)
  46.             const comment = document.createElement("td")
  47.             const commentInput = document.createElement("textarea")
  48.             commentInput.id = "comment_" + item.asset_tag
  49.             commentInput.style.marginLeft = "10px"
  50.             commentInput.onkeyup = function(){ renderController() }
  51.             comment.appendChild(commentInput)
  52.             row.appendChild(itemName)
  53.             row.appendChild(isConfirmed)
  54.             row.appendChild(comment)
  55.             table.appendChild(row)
  56.           })
  57.           return table
  58.         }
  59.      
  60.         function renderItemList(itemList){
  61.           var parsedItems = []
  62.           itemList.forEach(item => {
  63.             var text = `<b>Display name:</b> ${item.display_name}<br>
  64. <b>Asset type:</b> ${item.asset_type}<br>
  65. <b>Asset tag:</b> ${item.asset_tag}<br>
  66. <b>Serial number:</b> ${item.serial_number}<br>
  67. <b>Finance name:</b> ${item.finance_name}<br>`
  68.             parsedItems.push(text)
  69.           })
  70.           rawDataElem.html(parsedItems.join("<br>"))
  71.         }
  72.          
  73.         function renderController(){
  74.           var replyData = []
  75.           rawData.forEach(item => {
  76.             var replyItem = item
  77.             replyItem.is_confirmed = document.getElementById("check_" + item.asset_tag).checked
  78.             replyItem.comment = document.getElementById("comment_" + item.asset_tag).value
  79.             replyData.push(replyItem)
  80.           })
  81.           commentNative.html(JSON.stringify(replyData))
  82.         }
  83.       }
  84.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement