Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IT-2637] Add hidden input with active status again after setting new…
… next execution time
- Loading branch information
ole.wellnitz@iteratec.de
committed
Mar 14, 2019
1 parent
69b654c
commit 00fe129
Showing
2 changed files
with
51 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 50 additions & 48 deletions
98
grails-app/assets/javascripts/timeago/future-only-timeago.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,50 +1,52 @@ | |||
FutureOnlyTimeago = function() { | FutureOnlyTimeago = function () { | ||
var nextExecutionServerUrl = ''; | var nextExecutionServerUrl = ''; | ||
var timeouts = []; | var timeouts = []; | ||
|
|||
jQuery.timeago.settings.allowFuture = true; | |||
|
|||
function futureHandler(cronExpression, elem, parentElem) { | |||
delete FutureOnlyTimeago.timeouts[elem]; | |||
jQuery.ajax({ | |||
type: 'POST', | |||
url: FutureOnlyTimeago.nextExecutionServerUrl, | |||
data: { value: cronExpression, noprepend: true }, | |||
success : function(newNextExecutionHtml) { | |||
// replace past date with new template | |||
$(parentElem).html(newNextExecutionHtml); | |||
var newElem = $('abbr.timeago', parentElem); | |||
makeFutureOnlyTimeago(newElem); | |||
} | |||
}); | |||
}; | |||
|
|
||
function makeFutureOnlyTimeago(elem) { | jQuery.timeago.settings.allowFuture = true; | ||
var fromNowInMs = $(elem).attr('data-date-diff-ms'); |
|
||
var cronExpression = $(elem).attr('data-cronstring'); | function futureHandler(cronExpression, elem, parentElem) { | ||
var parentElem = $(elem).parent(); | delete FutureOnlyTimeago.timeouts[elem]; | ||
|
jQuery.ajax({ | ||
if (cronExpression && fromNowInMs < 1000 * 60 * 60 * 24 * 7) { | type: 'POST', | ||
var updateTimeout = setTimeout(futureHandler.bind(this, cronExpression, elem, parentElem), fromNowInMs); | url: FutureOnlyTimeago.nextExecutionServerUrl, | ||
FutureOnlyTimeago.timeouts[elem] = updateTimeout; | data: {value: cronExpression, noprepend: true}, | ||
|
success: function (newNextExecutionHtml) { | ||
// cut off second as PrettyCron can only handle Cron expressions where minutes are the smallest unit | // replace past date with new template | ||
//var prettyCronString = prettyCron.toString(cronExpression.substr(cronExpression.indexOf(' ') + 1)); | var active = $('input.job_active', parentElem); | ||
//$(parentElem).append('(<abbr class="cronExpression">' + prettyCronString + '</abbr>)'); | $(parentElem).html(newNextExecutionHtml); | ||
} | $(parentElem).append(active); | ||
$(elem).timeago(); | var newElem = $('abbr.timeago', parentElem); | ||
} | makeFutureOnlyTimeago(newElem); | ||
|
} | ||
// ${createLink(action: 'nextExecution')} | }); | ||
function initializeTimeagos(timeagos, nextExecutionServerUrl) { | }; | ||
this.nextExecutionServerUrl = nextExecutionServerUrl; |
|
||
this.timeouts = []; | function makeFutureOnlyTimeago(elem) { | ||
$.each(timeagos, function (index, elem) { | var fromNowInMs = $(elem).attr('data-date-diff-ms'); | ||
makeFutureOnlyTimeago(elem); | var cronExpression = $(elem).attr('data-cronstring'); | ||
}); | var parentElem = $(elem).parent(); | ||
} |
|
||
|
if (cronExpression && fromNowInMs < 1000 * 60 * 60 * 24 * 7) { | ||
return { | var updateTimeout = setTimeout(futureHandler.bind(this, cronExpression, elem, parentElem), fromNowInMs); | ||
init: initializeTimeagos | FutureOnlyTimeago.timeouts[elem] = updateTimeout; | ||
} |
|
||
// cut off second as PrettyCron can only handle Cron expressions where minutes are the smallest unit | |||
//var prettyCronString = prettyCron.toString(cronExpression.substr(cronExpression.indexOf(' ') + 1)); | |||
//$(parentElem).append('(<abbr class="cronExpression">' + prettyCronString + '</abbr>)'); | |||
} | |||
$(elem).timeago(); | |||
} | |||
|
|||
// ${createLink(action: 'nextExecution')} | |||
function initializeTimeagos(timeagos, nextExecutionServerUrl) { | |||
this.nextExecutionServerUrl = nextExecutionServerUrl; | |||
this.timeouts = []; | |||
$.each(timeagos, function (index, elem) { | |||
makeFutureOnlyTimeago(elem); | |||
}); | |||
} | |||
|
|||
return { | |||
init: initializeTimeagos | |||
} | |||
}(); | }(); |