Created
November 8, 2024 14:20
-
-
Save bjoerntx/b4eaf83b6a28f692073a38afb2b63bae to your computer and use it in GitHub Desktop.
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
TXTextControl.addEventListener("textControlLoaded", e => { | |
let idleTimeout; | |
function onIdle() { | |
mergeTemplate(); | |
} | |
function resetIdleTimer() { | |
clearTimeout(idleTimeout); | |
idleTimeout = setTimeout(onIdle, 2000); // Set idle time to 2 seconds | |
} | |
// Attach event listener to TXTextControl's "changed" event | |
TXTextControl.addEventListener("changed", e => { | |
resetIdleTimer(); | |
}); | |
// Initialize the idle timer | |
resetIdleTimer(); | |
}); | |
function mergeTemplate() { | |
TXTextControl.saveDocument(TXTextControl.StreamType.InternalUnicodeFormat, document => { | |
// call web api endpoint with ajax | |
$.ajax({ | |
url: '/mailmerge/merge', | |
type: 'POST', | |
contentType: 'application/json', | |
data: JSON.stringify(document.data), | |
success: function (data) { | |
// load the document into the viewer | |
TXDocumentViewer.loadDocument(data); | |
} | |
}); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment