lib/sensu-dashboard/public/js/functions.js in sensu-dashboard-0.7.0 vs lib/sensu-dashboard/public/js/functions.js in sensu-dashboard-0.8.0

- old
+ new

@@ -150,9 +150,82 @@ var row_count = $('table#clients > tbody > tr').length; $('span#client_count').html(row_count); }); } +function fetchStashes() { + $('table#events > tbody').empty(); + $.ajax({ + type: 'GET', + url: '/stashes.json', + success: function(data, textStatus, xhr) { + $.ajax({ + type: 'POST', + url: '/stashes.json', + data: JSON.stringify(data), + success: function(stash_data, textStatus, xhr) { + stashes = new Array(); + for (stash in stash_data) { + stash_keys = new Array(); + stash_values = new Array(); + for (stash_value in stash_data[stash]) { + stash_keys.push(stash_value); + stash_values.push({ + name: stash_value, + value: stash_data[stash][stash_value] + }); + } + stashes.push({ + identifier: SHA1(stash), + name: stash, + keys: stash_keys.join(', '), + values: stash_values + }); + } + $('#stashTemplate').tmpl(stashes).appendTo('table#events > tbody'); + $('tbody > tr').click(function() { + $('div#event_details_modal').empty(); + var row = $(this).parent().children().index($(this)); + $('#stashDetailsTemplate').tmpl(stashes[row]).appendTo('div#event_details_modal'); + $('div#delete_stash').click(function() { + $('div#delete_stash > img').attr("src", "/img/loading_circle.gif"); + $.ajax({ + type: 'DELETE', + url: '/stash/'+stashes[row]['name']+'.json', + success: function(data, textStatus, xhr) { + $("#lean_overlay").fadeOut(200); + $("#event_details_modal").css({'display':'none'}); + fetchStashes(); + }, + error: function(xhr, textStatus, errorThrown) { + $('div#delete_stash > img').attr("src", "/img/cross.png"); + console.log('XHR: ' + xhr); + console.log('textStatus: ' + textStatus); + console.log('errorThrown: ' + errorThrown); + alert('Error deleting stash'); + } + }); + }); + }); + $('tr[rel*=leanModal]').leanModal({ top : 50, bottom : 50 }); + }, + error: function(xhr, textStatus, errorThrown) { + console.log('XHR: ' + xhr); + console.log('textStatus: ' + textStatus); + console.log('errorThrown: ' + errorThrown); + alert('Error retrieving stashes'); + } + }); + }, + error: function(xhr, textStatus, errorThrown) { + console.log('XHR: ' + xhr); + console.log('textStatus: ' + textStatus); + console.log('errorThrown: ' + errorThrown); + alert('Error retrieving stashes'); + } + }); +} + function filterEvents() { var values = $("input[type=hidden]").val().split(","); filtered_events = []; filtered_events_count = 0;