goliath/assets/coffee/slepe.coffee

29 lines
1016 B
CoffeeScript

$(document).ready ->
console.log('Hello, world!')
$('.ticket-status').on('click', handleStatusClick)
handleStatusClick = (e, msg = 'Set ticket status:') ->
validStatus = ['open', 'closed', 'parked']
newStatus = prompt(msg, $('.ticket-status > span').text())
newStatus = newStatus.toLowerCase()
if (newStatus != null) and (newStatus != '')
if (newStatus in validStatus)
console.log('Setting status to ' + newStatus)
editLink = $('#ticketEditLink').attr('href') + '/status'
console.log('Sending data to ' + editLink)
$.ajax({
type: "POST",
url: editLink,
data:
status: newStatus,
success: (data) ->
newStatus = newStatus.charAt(0).toUpperCase() + newStatus.slice(1)
$('.ticket-status > span').text(newStatus)
console.log('Ticket updated successfully.')
})
else
console.log('Invalid status entered')
handleStatusClick(e, 'Invalid status; valid values are open, closed, and parked')