Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (/\/support\/tickets\/\d*/.test(window.location.pathname)) {
- console.log(jQuery('.item-name').text())
- const itemName = "Ringteam Inventory"
- const rawDataFieldName = "Raw_data"
- if (jQuery('.item-name').text() === itemName) {
- jQuery('.redactor_box').hide()
- jQuery('.control-group').hide()
- const commentNative = jQuery('.redactor_editor p')
- console.log('ELEM PROBING')
- const rawDataElem = jQuery(`[for=${rawDataFieldName}]`).parent()
- const rawDataText = rawDataElem.find("pre").text()
- const rawData = JSON.parse(rawDataText)
- console.log(rawData)
- console.log('rendering items for requester')
- renderItemList(rawData)
- const replyTable = createReplyTable(rawData)
- jQuery('.redactor_box').parent().append(replyTable)
- function createReplyTable(data){
- const table = document.createElement("table")
- rawData.forEach(item => {
- const row = document.createElement("tr")
- row.id = item.asset_tag
- const itemName = document.createElement("td")
- itemName.innerHTML = item.display_name
- itemName.style.fontWeight = "bold"
- itemName.style.margin = "5px"
- itemName.style.textAlign = "right"
- const isConfirmed = document.createElement("td")
- const checkbox = document.createElement("input")
- checkbox.type = "checkbox"
- checkbox.id = "check_" + item.asset_tag
- checkbox.onchange = function(){ renderController() }
- const label = document.createElement("label")
- label.htmlFor = "check_" + item.asset_tag
- label.innerHTML = "Confirm"
- label.style.margin = "5px"
- label.style.display = "inline"
- isConfirmed.appendChild(label)
- isConfirmed.appendChild(checkbox)
- const comment = document.createElement("td")
- const commentInput = document.createElement("textarea")
- commentInput.id = "comment_" + item.asset_tag
- commentInput.style.marginLeft = "10px"
- commentInput.onkeyup = function(){ renderController() }
- comment.appendChild(commentInput)
- row.appendChild(itemName)
- row.appendChild(isConfirmed)
- row.appendChild(comment)
- table.appendChild(row)
- })
- return table
- }
- function renderItemList(itemList){
- var parsedItems = []
- itemList.forEach(item => {
- var text = `<b>Display name:</b> ${item.display_name}<br>
- <b>Asset type:</b> ${item.asset_type}<br>
- <b>Asset tag:</b> ${item.asset_tag}<br>
- <b>Serial number:</b> ${item.serial_number}<br>
- <b>Finance name:</b> ${item.finance_name}<br>`
- parsedItems.push(text)
- })
- rawDataElem.html(parsedItems.join("<br>"))
- }
- function renderController(){
- var replyData = []
- rawData.forEach(item => {
- var replyItem = item
- replyItem.is_confirmed = document.getElementById("check_" + item.asset_tag).checked
- replyItem.comment = document.getElementById("comment_" + item.asset_tag).value
- replyData.push(replyItem)
- })
- commentNative.html(JSON.stringify(replyData))
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement