mirror of https://github.com/gophish/gophish
1 line
3.0 KiB
JavaScript
1 line
3.0 KiB
JavaScript
function deleteCampaign(a){confirm("Delete "+campaigns[a].name+"?")&&api.campaignId.delete(campaigns[a].id).success(function(a){successFlash(a.message),location.reload()})}var campaigns=[],labels={"In progress":"label-primary",Queued:"label-info",Completed:"label-success","Emails Sent":"label-success",Error:"label-danger"};$(document).ready(function(){api.campaigns.summary().success(function(a){if($("#loading").hide(),campaigns=a.campaigns,campaigns.length>0){$("#dashboard").show();var e={labels:[],series:[[]]},t={series:[]},s={axisX:{showGrid:!1},showArea:!0,plugins:[],low:0,high:100},i={donut:!0,donutWidth:40,chartPadding:0,showLabel:!1},n=0;campaignTable=$("#campaignTable").DataTable({columnDefs:[{orderable:!1,targets:"no-sort"}],order:[[1,"desc"]]}),$.each(campaigns,function(a,t){var s=moment(t.created_date).format("MMMM Do YYYY, h:mm:ss a"),i=labels[t.status]||"label-default";campaignTable.row.add([escapeHtml(t.name),s,'<span class="label '+i+'">'+t.status+"</span>","<div class='pull-right'><a class='btn btn-primary' href='/campaigns/"+t.id+"' data-toggle='tooltip' data-placement='right' title='View Results'> <i class='fa fa-bar-chart'></i> </a> <button class='btn btn-danger' onclick='deleteCampaign("+a+")' data-toggle='tooltip' data-placement='right' title='Delete Campaign'> <i class='fa fa-trash-o'></i> </button></div>"]).draw(),t.y=0,t.y+=t.stats.clicked+t.stats.submitted_data,t.y=Math.floor(t.y/t.stats.total*100),n+=t.y,e.labels.push(s),e.series[0].push({meta:a,value:t.y})}),n=Math.floor(n/a.total),t.series.push({meta:"Unsuccessful Phishes",value:100-n}),t.series.push({meta:"Successful Phishes",value:n});new Chartist.Pie("#average_chart",t,i),new Chartist.Line("#overview_chart",e,s);$piechart=$("#average_chart");var c=$piechart.append('<div class="chartist-tooltip"></div>').find(".chartist-tooltip").hide();$piechart.on("mouseenter",".ct-slice-donut",function(){var a=$(this);value=a.attr("ct:value"),label=a.attr("ct:meta"),c.html(label+": "+value.toString()+"%").show()}),$piechart.on("mouseleave",".ct-slice-donut",function(){c.hide()}),$piechart.on("mousemove",function(a){c.css({left:(a.offsetX||a.originalEvent.layerX)-c.width()/2-10,top:(a.offsetY+40||a.originalEvent.layerY)-c.height()-80})}),$chart=$("#overview_chart");var l=$chart.append('<div class="chartist-tooltip"></div>').find(".chartist-tooltip").hide();$chart.on("mouseenter",".ct-point",function(){var a=$(this);value=a.attr("ct:value")||0,cidx=a.attr("ct:meta"),l.html(campaigns[cidx].name+"<br>Successes: "+value.toString()+"%").show()}),$chart.on("mouseleave",".ct-point",function(){l.hide()}),$chart.on("mousemove",function(a){l.css({left:(a.offsetX||a.originalEvent.layerX)-l.width()/2-10,top:(a.offsetY+40||a.originalEvent.layerY)-l.height()-40})}),$("#overview_chart").on("click",".ct-point",function(a){$(this).attr("ct:meta");window.location.href="/campaigns/"+campaigns[cidx].id})}else $("#emptyMessage").show()}).error(function(){errorFlash("Error fetching campaigns")})}); |