Skip to content

Instantly share code, notes, and snippets.

@ecoologic
Last active December 17, 2015 03:49
Show Gist options
  • Save ecoologic/5545962 to your computer and use it in GitHub Desktop.
Save ecoologic/5545962 to your computer and use it in GitHub Desktop.
$('form#new_invoice:not(".invoice-project-select")').submit ->
$form = $('form#new_invoice')
$tasks = $form.find('.task-checkbox')
$flatFees = $form.find('[data-flatfee]')
confirmCheckAll = 'You have not selected a single item. Please take note that all items that are unbillable are unchecked by default.\n\nDo you want to check them all and create the invoice?'
confirmInvoiceWithFlatFees = "There are either tasks or projects that have a fixed fee set. If you would like to instead invoice these by hours logged, please set them to 'hourly' before creating the invoice.\n\nDo you still wish to create the invoice now?"
# $tasks.find(':not(:checked)').click() # this keeps the graphic in sync
$tasks.attr('checked', true) if $tasks.find(':checked').length == 0 && confirm(confirmCheckAll)
invoice = $tasks.find(':checked').length > 0 # this is ALWAYS false, why?
invoice = confirm(confirmInvoiceWithFlatFees) if invoice && $flatFees.find('.task, .project').length > 0
invoice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment