Skip to content

Instantly share code, notes, and snippets.

@jgannonjr
Created September 13, 2011 21:32
Show Gist options
  • Save jgannonjr/1215224 to your computer and use it in GitHub Desktop.
Save jgannonjr/1215224 to your computer and use it in GitHub Desktop.
A widget for Zendesk that allows AJAX auto refresh of Views.
<!--
To use this widget, create a new "Custom" widget. Copy and paste this code into the widget then save.
Once saved, you can add the widget to your Views. Be sure to disable the widget by hitting the Enable/Disable
button whenever mass updating tickets (otherwise the check boxes next to tickets you have selected may get
cleared if an update occurs before you submit the changes). You can set whether the refresh is enabled or
disabled by default as well as the refresh interval in the section commented "SET CUSTOM SETTINGS HERE".
-->
<script>
// SET CUSTOM SETTINGS HERE
var tickets_table_refresh_enabled = true; // specifies whether the updater is enabled/disabled by default (true=enabled)
var tickets_table_refresh_seconds = 60; // specifies how often the ticket table is updated (in seconds)
// END CUSTOM SETTINGS
update_tickets_table = function(url) {
if (tickets_table_refresh_enabled) {
new Ajax.Request(url, {
method: 'get',
asynchronous: true,
requestHeaders: {
"Accept": "text\/html"
},
onCreate: function() {
$('tickets_table_refresh_spinner').show();
},
onSuccess: function(transport) {
var regex = /<div class="content content_grey">[\s\S]*?<div class="box box_bottom"><\/div><\/div><\/div>/gim;
var tickets_table_html = (transport.responseText.match(regex))[0];
$$('div.content.content_grey')[0].replace(tickets_table_html);
$$('div.ui-tooltip.zd_comment').invoke('hide');
$('tickets_table_refresh_spinner').hide();
},
onFailure: function() {
alert('Something went wrong...')
}
});
}
}
toggleTicketsTableRefresh = function() {
if (tickets_table_refresh_enabled) {
tickets_table_refresh_enabled = false;
$('tickets_table_refresh_button').writeAttribute("value", "Disabled");
} else {
tickets_table_refresh_enabled = true;
$('tickets_table_refresh_button').writeAttribute("value", "Enabled");
}
}
if (tickets_table_refresh_enabled) {
$('tickets_table_refresh_button').writeAttribute("value", "Enabled");
} else {
$('tickets_table_refresh_button').writeAttribute("value", "Disabled");
}
setInterval("update_tickets_table(location.href)", tickets_table_refresh_seconds * 1000);
</script>
<div style="text-align:center;height:50px;">
<input type="button" id="tickets_table_refresh_button" value="Loading..."
style="width: 100px; height:50px;" onClick="toggleTicketsTableRefresh();">
<div id="tickets_table_refresh_spinner" style="position:relative;left:-72px;top:-32px;display:none">
<img src="http://i55.tinypic.com/dwc09k.gif">
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment