function launch(){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(){return new Promise(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").utc().format(),groups:groups},console.log("Launching campaign at time: "+campaign.launch_date),api.campaigns.post(campaign).success(function(e){a(),campaign=e}).error(function(a){$("#modal\\.flashes").empty().append('
'+a.responseJSON.message+"
"),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()})})}function sendTestEmail(){var a={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(' Sending'),api.send_test_email(a).success(function(a){$("#sendTestEmailModal\\.flashes").empty().append(' Email Sent!
'),$("#sendTestModalSubmit").html(btnHtml)}).error(function(a){$("#sendTestEmailModal\\.flashes").empty().append(' '+a.responseJSON.message+"
"),$("#sendTestModalSubmit").html(btnHtml)})}function dismiss(){$("#modal\\.flashes").empty(),$("#name").val(""),$("#template").val("").change(),$("#page").val("").change(),$("#url").val(""),$("#profile").val("").change(),$("#users").val("").change(),$("#modal").modal("hide")}function deleteCampaign(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(){return new Promise(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()})})}function setupOptions(){api.groups.get().success(function(a){if(0==a.length)return modalError("No groups found!"),!1;var e=$.map(a,function(a){return a.text=a.name,a});$("#users.form-control").select2({placeholder:"Select Groups",data:e})}),api.templates.get().success(function(a){if(0==a.length)return modalError("No templates found!"),!1;var e=$.map(a,function(a){return a.text=a.name,a});$("#template.form-control").select2({placeholder:"Select a Template",data:e})}),api.pages.get().success(function(a){if(0==a.length)return modalError("No pages found!"),!1;var e=$.map(a,function(a){return a.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)return modalError("No profiles found!"),!1;var e=$.map(a,function(a){return a.text=a.name,a});$("#profile.form-control").select2({placeholder:"Select a Sending Profile",data:e})})}function edit(a){setupOptions()}function copy(a){setupOptions(),api.campaignId.get(campaigns[a].id).success(function(a){$("#name").val("Copy of "+a.name),a.template.id?$("#template").select2("val",a.template.id.toString()):$("#template").select2({placeholder:a.template.name}),a.page.id?$("#page").select2("val",a.page.id.toString()):$("#page").select2({placeholder:a.page.name}),a.smtp.id?$("#profile").select2("val",a.smtp.id.toString()):$("#profile").select2({placeholder:a.smtp.name}),$("#url").val(a.url)}).error(function(a){$("#modal\\.flashes").empty().append(' '+a.responseJSON.message+"
")})}var labels={"In progress":"label-primary",Queued:"label-info",Completed:"label-success","Emails Sent":"label-success",Error:"label-danger"},campaigns=[],campaign={};$(document).ready(function(){$("#launch_date").datetimepicker({widgetPositioning:{vertical:"bottom"},showTodayButton:!0,defaultDate:moment()}),$(".modal").on("hidden.bs.modal",function(a){$(this).removeClass("fv-modal-stack"),$("body").data("fv_open_modals",$("body").data("fv_open_modals")-1)}),$(".modal").on("shown.bs.modal",function(a){"undefined"==typeof $("body").data("fv_open_modals")&&$("body").data("fv_open_modals",0),$(this).hasClass("fv-modal-stack")||($(this).addClass("fv-modal-stack"),$("body").data("fv_open_modals",$("body").data("fv_open_modals")+1),$(this).css("z-index",1040+10*$("body").data("fv_open_modals")),$(".modal-backdrop").not(".fv-modal-stack").css("z-index",1039+10*$("body").data("fv_open_modals")),$(".modal-backdrop").not("fv-modal-stack").addClass("fv-modal-stack"))}),$(document).on("hidden.bs.modal",".modal",function(){$(".modal:visible").length&&$(document.body).addClass("modal-open")}),$("#modal").on("hidden.bs.modal",function(a){dismiss()}),api.campaigns.summary().success(function(a){campaigns=a.campaigns,$("#loading").hide(),campaigns.length>0?($("#campaignTable").show(),campaignTable=$("#campaignTable").DataTable({columnDefs:[{orderable:!1,targets:"no-sort"}],order:[[1,"desc"]]}),$.each(campaigns,function(a,e){console.log(e),console.log(e.created_date),label=labels[e.status]||"label-default";var t;if(moment(e.launch_date).isAfter(moment())){t="Scheduled to start: "+moment(e.launch_date).format("MMMM Do YYYY, h:mm:ss a");var n=t+"
Number of recipients: "+e.stats.total}else{t="Launch Date: "+moment(e.launch_date).format("MMMM Do YYYY, h:mm:ss a");var n=t+"
Number of recipients: "+e.stats.total+"
Emails opened: "+e.stats.opened+"
Emails clicked: "+e.stats.clicked+"
Submitted Credentials: "+e.stats.submitted_data+"
Errors : "+e.stats.error}campaignTable.row.add([escapeHtml(e.name),moment(e.created_date).format("MMMM Do YYYY, h:mm:ss a"),''+e.status+"",""]).draw(),$('[data-toggle="tooltip"]').tooltip()})):$("#emptyMessage").show()}).error(function(){$("#loading").hide(),errorFlash("Error fetching campaigns")}),$.fn.select2.defaults.set("width","100%"),$.fn.select2.defaults.set("dropdownParent",$("#modal_body")),$.fn.select2.defaults.set("theme","bootstrap")});