Skip to content

Instantly share code, notes, and snippets.

@tstachl
Created August 30, 2016 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tstachl/dc80c08e4136a3c1fae6b860be856b92 to your computer and use it in GitHub Desktop.
Save tstachl/dc80c08e4136a3c1fae6b860be856b92 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<script src="//ajax.deskapi.com/libs/desk/opencti/current/interaction.min.js"></script>
<script>
(function() {
desk.ready(function() {
var form = document.querySelector('form')
, text = document.querySelector('input')
function handlePopResponse(response) {
if (response.result) {
alert('screenPop successful.');
} else {
alert('screenPop failed.' + error.message);
}
}
function popCase(response) {
// some error handling here
if (response.status === 200) {
// screen pop the case you found
desk.interaction.screenPop(
response.data.entries[0].id,
'object=case',
handlePopResponse
);
}
}
function search(string, callback) {
// you need to make sure to normalize and url encode the query
// string yourself here.
desk.interaction.ajax('/api/v2/cases/search?q=' + string, {
method: 'GET'
}, callback);
}
function submit(evt) {
evt.preventDefault();
search(text.value, popCase);
}
// add the handler
form.addEventListener('submit', submit, false);
// show the form when everything is loaded
form.style.display = '';
});
}());
</script>
</head>
<body>
<form style="display: none;">
<input type="text">
<button type="submit">Custom Search</button>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment