Skip to content

Commit

Permalink
Fixed failing book splitting xhr chain
Browse files Browse the repository at this point in the history
* also fixed form layout for custom attributes
  • Loading branch information
arBmind committed Jul 6, 2021
1 parent 02244df commit 54c91f6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
65 changes: 30 additions & 35 deletions app/assets/javascripts/forms.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -131,48 +131,43 @@ split = (timeLogId, mSplitAt, insertNewBefore, round) ->
insert_new_before: insertNewBefore
round: round

submit_without_split_checking = ($form) ->
$form
.removeClass('js-check-splitting')
.submit()

addSplittingSuccessfulHandler = ($form, startJqXhr, stopJqXhr) ->
if startJqXhr
startJqXhr.done ->
submit_without_split_checking $form
else if stopJqXhr
stopJqXhr.done ->
submit_without_split_checking $form

addSplittingFailedHandler = (startJqXhr, stopJqXhr) ->
if stopJqXhr
stopJqXhr.fail ({responseJSON}) ->
hourglass.Utils.showErrorMessage responseJSON.message
if startJqXhr
startJqXhr.fail ({responseJSON}) ->
hourglass.Utils.showErrorMessage responseJSON.message

checkSplitting = ->
submit_without_split_checking = ($form, e) ->
$form.removeClass('js-check-splitting')
$.rails.handleRemote.call($form[0], e)

addSplittingFailedHandler = (xhr) ->
xhr.fail ({responseJSON}) ->
hourglass.Utils.showErrorMessage responseJSON.message

checkSplitting = (e)->
$form = $(@)
timeLogId = $form.data('timeLogId')
$startField = $form.find('[name*=start]')
$stopField = $form.find('[name*=stop]')
mStart = moment $startField.val(), moment.ISO_8601
mStop = moment $stopField.val(), moment.ISO_8601
round = $form.find('[type=checkbox][name*=round]').prop('checked')
stopJqXhr = if mStop.isBefore $stopField.data('mLimit')
split timeLogId, mStop, false, round
startJqXhr = if mStart.isAfter $startField.data('mLimit')
if stopJqXhr
stopJqXhr.then ->
split timeLogId, mStart, true, round
else
split timeLogId, mStart, true, round

addSplittingSuccessfulHandler $form, startJqXhr, stopJqXhr
addSplittingFailedHandler startJqXhr, stopJqXhr

return not (startJqXhr or stopJqXhr)
next = ->
submit_without_split_checking $form, e
any = false
if mStart.isAfter $startField.data('mLimit')
startNext = next
any = true
next = ->
xhr = split timeLogId, mStart, true, round
addSplittingFailedHandler(xhr)
xhr.done startNext
if mStop.isBefore $stopField.data('mLimit')
stopNext = next
any = true
next = ->
xhr = split timeLogId, mStop, false, round
addSplittingFailedHandler(xhr)
xhr.done stopNext
if any
next()
return false
return true

$ ->
$(document)
Expand Down
7 changes: 5 additions & 2 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
.form-field {
float: left;
margin-right: 5px;
.label {
.label, >label {
float: left;
overflow: hidden;
font-size: 9px;
}
.input {
>input {
display: block;
}
.input, >input {
margin-top: 15px;
input ~ a {
margin-left: 10px;
Expand Down

0 comments on commit 54c91f6

Please sign in to comment.