varlabels={"In progress":"label-primary",Queued:"label-info",Completed:"label-success","Emails Sent":"label-success",Error:"label-danger"},campaigns=[],campaign={};functionlaunch(){Swal.fire({title:"Are you sure?",text:"This will schedule the campaign to be launched.",type:"question",animation:!1,showCancelButton:!0,confirmButtonText:"Launch",confirmButtonColor:"#428bca",reverseButtons:!0,allowOutsideClick:!1,showLoaderOnConfirm:!0,preConfirm:function(){returnnewPromise(function(a,e){groups=[],$("#users").select2("data").forEach(function(e){groups.push({name:e.text})});vart=$("#send_by_date").val();""!=t&&(t=moment(t,"MMMM Do YYYY, h:mm a").utc().format()),campaign={name:$("#name").val(),template:{name:$("#template").select2("data")[0].text},url:$("#url").val(),page:{name:$("#page").select2("data")[0].text},smtp:{name:$("#profile").select2("data")[0].text},launch_date:moment($("#launch_date").val(),"MMMM Do YYYY, h:mm a").utc().format(),send_by_date:t||null,groups:groups},api.campaigns.post(campaign).success(function(e){a(),campaign=e}).error(function(e){$("#modal\\.flashes").empty().append('<div style="text-align:center" class="alert alert-danger"> <i class="fa fa-exclamation-circle"></i> '+e.responseJSON.message+"</div>"),Swal.close()})})}}).then(function(e){e.value&&Swal.fire("Campaign Scheduled!","This campaign has been scheduled for launch!","success"),$('button:contains("OK")').on("click",function(){window.location="/campaigns/"+campaign.id.toString()})})}functionsendTestEmail(){vare={template:{name:$("#template").select2("data")[0].text},first_name:$("input[name=to_first_name]").val(),last_name:$("input[name=to_last_name]").val(),email:$("input[name=to_email]").val(),position:$("input[name=to_position]").val(),url:$("#url").val(),page:{name:$("#page").select2("data")[0].text},smtp:{name:$("#profile").select2("data")[0].text}};btnHtml=$("#sendTestModalSubmit").html(),$("#sendTestModalSubmit").html('<i class="fa fa-spinner fa-spin"></i> Sending'),api.send_test_email(e).success(function(e){$("#sendTestEmailModal\\.flashes").empty().append('<div style="text-align:center" class="alert alert-success"> <i class="fa fa-check-circle"></i> Email Sent!</div>'),$("#sendTestModalSubmit").html(btnHtml)}).error(function(e){$("#sendTestEmailModal\\.flashes").empty().append('<div style="text-align:center" class="alert alert-danger"> <i class="fa fa-exclamation-circle"></i> '+e.responseJSON.message+"</div>"),$("#sendTestModalSubmit").html(btnHtml)})}functiondismiss(){$("#modal\\.flashes").empty(),$("#name").val(""),$("#template").val("").change(),$("#page").val("").change(),$("#url").val(""),$("#profile").val("").change(),$("#users").val("").change(),$("#modal").modal("hide")}functiondeleteCampaign(e){Swal.fire({title:"Are you sure?",text:"This will delete the campaign. This can't be undone!",type:"warning",animation:!1,showCancelButton:!0,confirmButtonText:"Delete "+campaigns[e].name,confirmButtonColor:"#428bca",reverseButtons:!0,allowOutsideClick:!1,preConfirm:function(){returnnewPromise(function(a,t){api.campaignId.delete(campaigns[e].id).success(function(e){a()}).error(function(e){t(e.responseJSON.message)})})}}).then(function(e){e.value&&Swal.fire("Campaign Deleted!","This campaign has been deleted!","success"),$('button:contains("OK")').on("click",function(){location.reload()})})}functionsetupOptions(){api.groups.summary().success(function(e){if(groups=e.groups,0==groups.length)returnmodalError("No groups found!"),!1;vara=$.map(groups,function(e){returne.text=e.name,e.title=e.num_targets+" targets",e});console.log(a),$("#users.form-control").select2({placeholder:"Select Groups",data:a})}),api.templates.get().success(function(e){if(0==e.length)returnmodalError("No templates found!"),!1;vara=$.map(e,function(e){returne.text=e.name,e}),t=$("#template.form-control");t.select2({placeholder:"Select a Template",data:a}),1===e.length&&(t.val(a[0].id),t.trigger("change.select2"))}),api.pages.get().success(function(e){if(0==e.length)returnmodalError("No pages found!"),!1;vara=$.map(