goliath/assets/coffee/slepe.coffee

39 lines
1.4 KiB
CoffeeScript

$(document).ready ->
console.log('Hello, world!')
$('.ticket-severity').on('click', handleAttributeClick('severity'))
$('.ticket-status').on('click', handleAttributeClick('status'))
validOptions =
'severity' = ['low', 'medium', 'high'],
'status' = ['open', 'closed', 'parked']
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
console.log('Sending data to ' + editLink)
$.ajax({
type: "POST",
url: editLink,
data:
attr: newValue,
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)