Created
June 14, 2017 19:21
-
-
Save dpawluk/0e4839f6576029d00ccbb7323c863e1a to your computer and use it in GitHub Desktop.
Shows how a modal can parse a parent's instance uuid and then work with the parent client from the modal
This file contains hidden or 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
<html> | |
<head> | |
<meta charset="utf-8"> | |
<!-- http://garden.zendesk.com --> | |
<link rel="stylesheet" href="https://assets.zendesk.com/apps/sdk-assets/css/0/zendesk_garden.css" type="text/css"> | |
</head> | |
<body> | |
<h2 class="u-gamma">Hello, World!</h2> | |
<div id="content_area"></div> | |
<!-- https://github.com/zendesk/zendesk_app_framework_sdk --> | |
<script type="text/javascript" src="https://assets.zendesk.com/apps/sdk/2.0/zaf_sdk.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script> | |
<script | |
src="https://code.jquery.com/jquery-3.2.1.min.js" | |
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" | |
crossorigin="anonymous"> | |
</script> | |
<script> | |
// Initialise the Zendesk JavaScript API client | |
// https://developer.zendesk.com/apps/docs/apps-v2 | |
var client = ZAFClient.init(); | |
client.invoke('resize', { width: '800px', height: '500px' }); | |
client.on('app.registered', init); | |
function init(){ | |
var params = parseParams(window.location.hash); | |
var pc = getParentClient(params.parent_guid); | |
pc.get('ticket').then(useTicketData); | |
}; | |
function useTicketData(data){ | |
console.log(data.ticket); | |
ticket_data_string = JSON.stringify(data.ticket, null, 2); | |
ticket_data_html = "<pre>" + ticket_data_string + "</pre>"; | |
$("#content_area").append(ticket_data_html); | |
}; | |
function parseParams(param_string){ | |
var param_sub = param_string.replace('#','').split('&'); | |
var param_obj = _.reduce(param_sub, function(memo, k){ | |
kv = k.split('='); | |
memo[kv[0]] = kv[1]; | |
return memo; | |
}, {}); | |
return param_obj; | |
}; | |
function getParentClient(parent_guid) { | |
return client.instance(parent_guid) | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment