functionlaunch(){swal({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(a){groups.push({name:a.text})}),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(),"MM/DD/YYYY hh:mm a").format(),groups:groups},api.campaigns.post(campaign).success(function(e){a(),campaign=e}).error(function(a){$("#modal\\.flashes").empty().append('<div style="text-align:center" class="alert alert-danger"> <i class="fa fa-exclamation-circle"></i> '+a.responseJSON.message+"</div>"),swal.close()})})}}).then(function(){swal("Campaign Scheduled!","This campaign has been scheduled for launch!","success"),$('button:contains("OK")').on("click",function(){window.location="/campaigns/"+campaign.id.toString()})})}functionsendTestEmail(){vara={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(a).success(function(a){$("#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(a){$("#sendTestEmailModal\\.flashes").empty().append('<div style="text-align:center" class="alert alert-danger"> <i class="fa fa-exclamation-circle"></i> '+a.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(a){swal({title:"Are you sure?",text:"This will delete the campaign. This can't be undone!",type:"warning",animation:!1,showCancelButton:!0,confirmButtonText:"Delete "+campaigns[a].name,confirmButtonColor:"#428bca",reverseButtons:!0,allowOutsideClick:!1,preConfirm:function(){returnnewPromise(function(e,t){api.campaignId.delete(campaigns[a].id).success(function(a){e()}).error(function(a){t(a.responseJSON.message)})})}}).then(function(){swal("Campaign Deleted!","This campaign has been deleted!","success"),$('button:contains("OK")').on("click",function(){location.reload()})})}functionsetupOptions(){api.groups.get().success(function(a){if(0==a.length)returnmodalError("No groups found!"),!1;vare=$.map(a,function(a){returna.text=a.name,a});$("#users.form-control").select2({placeholder:"Select Groups",data:e})}),api.templates.get().success(function(a){if(0==a.length)returnmodalError("No templates found!"),!1;vare=$.map(a,function(a){returna.text=a.name,a});$("#template.form-control").select2({placeholder:"Select a Template",data:e})}),api.pages.get().success(function(a){if(0==a.length)returnmodalError("No pages found!"),!1;vare=$.map(a,function(a){returna.text=a.name,a});$("#page.form-control").select2({placeholder:"Select a Landing Page",data:e})}),api.SMTP.get().success(function(a){if(0==a.length)returnmodalError("No profiles found!"),!1;vare=$.map(a,function(a){returna.text=a.name,a});$("#profile.form-control").select2({placeholder:"Select a Sending Profile",data:e})})}functionedit(a){setupOptions()}functioncopy(a){setupOptions(),api.campaignId.get(campaigns[a].id).success(function