goliath/assets/coffee/slepe.coffee

69 lines
2.3 KiB
CoffeeScript

$(document).ready ->
$('.ticket-queue').on('click', (e) ->
handleQueueClick(e)
)
$('.ticket-severity').on('click', (e) ->
handleAttributeClick(e, 'severity')
)
$('.ticket-status').on('click', (e) ->
handleAttributeClick(e, 'status')
)
validOptions =
'severity': ['low', 'medium', 'high'],
'status': ['open', 'closed', 'parked']
handleQueueClick = (e, fail = false) ->
newQueueId = prompt('Set queue ID:', $('.ticket-queue').data('id'))
if (newQueueId != null) and (newQueueId != '')
if (true)
console.log('Setting queue ID to ' + newQueueId)
editLink = $('#ticketEditLink').attr('href') + '/queue_id'
console.log('Sending data to ' + editLink)
$.ajax({
type: "POST",
url: editLink,
data:
'queue_id': newQueueId,
dataType: 'json',
success: (result) ->
$('.ticket-queue').data('id', newQueueId)
$('.ticket-queue > span').text(result.queue_name)
updateTicketModified(result.updated_at)
console.log('Ticket updated successfully.')
})
else
console.log('Invalid queue ID entered')
handleQueueClick(e, 'Invalid queue ID entered; you must enter a number.')
handleAttributeClick = (e, attr, fail = false) ->
newValue = prompt('Set ticket ' + attr + ':', $('.ticket-' + attr + ' > span').text())
newValue = newValue.toLowerCase()
if (newValue != null) and (newValue != '')
if (newValue in validOptions[attr])
console.log('Setting ' + attr + ' to ' + newValue)
editLink = $('#ticketEditLink').attr('href') + '/' + attr
postData = {}
postData[attr] = newValue
console.log('Sending data to ' + editLink)
$.ajax({
type: "POST",
url: editLink,
data: postData,
dataType: 'json',
success: (result) ->
newValue = newValue.charAt(0).toUpperCase() + newValue.slice(1)
$('.ticket-' + attr + ' > span').text(newValue)
updateTicketModified(result.updated_at)
console.log('Ticket updated successfully.')
})
else
console.log('Invalid ' + attr + ' entered')
handleAttributeClick(e, attr, 'Invalid ' + attr + '; valid values are ' + validOptions.toString() + '.')
updateTicketModified = (date) ->
$('.ticket-updated > span').text(date)
console.log('Ticket update time is ' + date)