Refactored the ticket attribute click handlers to be more modular for adding new attribute modifications
This commit is contained in:
parent
ab2c87ce3a
commit
15ee9b78a3
@ -1,61 +1,37 @@
|
||||
$(document).ready ->
|
||||
console.log('Hello, world!')
|
||||
|
||||
$('.ticket-severity').on('click', handleSeverityClick)
|
||||
$('.ticket-status').on('click', handleStatusClick)
|
||||
$('.ticket-severity').on('click', handleAttributeClick('severity'))
|
||||
$('.ticket-status').on('click', handleAttributeClick('status'))
|
||||
|
||||
handleSeverityClick = (e, msg = 'Set ticket severity:') ->
|
||||
validSeverity = ['low', 'medium', 'high']
|
||||
newSeverity = prompt(msg, $('.ticket-severity > span').text())
|
||||
newSeverity = newSeverity.toLowerCase()
|
||||
validOptions =
|
||||
'severity' = ['low', 'medium', 'high'],
|
||||
'status' = ['open', 'closed', 'parked']
|
||||
|
||||
if (newSeverity != null) and (newSeverity != '')
|
||||
if (newSeverity in validSeverity)
|
||||
console.log('Setting severity to ' + newSeverity)
|
||||
editLink = $('#ticketEditLink').attr('href') + '/severity'
|
||||
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:
|
||||
severity: newSeverity,
|
||||
attr: newValue,
|
||||
dataType: 'json',
|
||||
success: (result) ->
|
||||
newSeverity = newSeverity.charAt(0).toUpperCase() + newSeverity.slice(1)
|
||||
$('.ticket-severity > span').text(newSeverity)
|
||||
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 severity entered')
|
||||
handleSeverityClick(e, 'Invalid severity; valid values are low, medium, and high.')
|
||||
|
||||
|
||||
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,
|
||||
dataType: 'json',
|
||||
success: (result) ->
|
||||
newStatus = newStatus.charAt(0).toUpperCase() + newStatus.slice(1)
|
||||
$('.ticket-status > span').text(newStatus)
|
||||
updateTicketModified(result.updated_at)
|
||||
console.log('Ticket updated successfully.')
|
||||
)
|
||||
else
|
||||
console.log('Invalid status entered')
|
||||
handleStatusClick(e, 'Invalid status; valid values are open, closed, and parked.')
|
||||
console.log('Invalid ' + attr + ' entered')
|
||||
handleAttributeClick(e, attr, 'Invalid ' + attr + '; valid values are ' + validOptions.toString() + '.')
|
||||
|
||||
updateTicketModified = (date) ->
|
||||
$('.ticket-updated > span').text(date)
|
||||
|
Loading…
Reference in New Issue
Block a user