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(e,a){groups=[],$.each($("#groupTable").DataTable().rows().data(),function(e,a){groups.push({name:unescapeHtml(a[0])})}),campaign={name:$("#name").val(),template:{name:$("#template").val()},url:$("#url").val(),page:{name:$("#page").val()},smtp:{name:$("#profile").val()},launch_date:moment($("#launch_date").val(),"MM/DD/YYYY hh:mm a").format(),groups:groups},api.campaigns.post(campaign).success(function(a){e(),campaign=a}).error(function(e){$("#modal\\.flashes").empty().append('
'+e.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 e={template:{name:$("#template").val()},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").val()},smtp:{name:$("#profile").val()}};btnHtml=$("#sendTestModalSubmit").html(),$("#sendTestModalSubmit").html(' Sending'),api.send_test_email(e).success(function(e){$("#sendTestEmailModal\\.flashes").empty().append(' Email Sent!
'),$("#sendTestModalSubmit").html(btnHtml)}).error(function(e){$("#sendTestEmailModal\\.flashes").empty().append(' '+e.responseJSON.message+"
"),$("#sendTestModalSubmit").html(btnHtml)})}function dismiss(){$("#modal\\.flashes").empty(),$("#name").val(""),$("#template").val(""),$("#page").val(""),$("#url").val(""),$("#profile").val(""),$("#groupSelect").val(""),$("#modal").modal("hide"),$("#groupTable").dataTable().DataTable().clear().draw()}function deleteCampaign(e){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[e].name,confirmButtonColor:"#428bca",reverseButtons:!0,allowOutsideClick:!1,preConfirm:function(){return new Promise(function(a,t){api.campaignId.delete(campaigns[e].id).success(function(e){a()}).error(function(e){t(e.responseJSON.message)})})}}).then(function(){swal("Campaign Deleted!","This campaign has been deleted!","success"),$('button:contains("OK")').on("click",function(){location.reload()})})}function edit(e){group_bh.clear(),template_bh.clear(),page_bh.clear(),profile_bh.clear(),"new"==e&&(api.groups.get().success(function(e){return 0==e.length?(modalError("No groups found!"),!1):void group_bh.add(e)}),api.templates.get().success(function(e){return 0==e.length?(modalError("No templates found!"),!1):void template_bh.add(e)}),api.pages.get().success(function(e){return 0==e.length?(modalError("No pages found!"),!1):void page_bh.add(e)}),api.SMTP.get().success(function(e){return 0==e.length?(modalError("No profiles found!"),!1):void profile_bh.add(e)}))}function copy(e){group_bh.clear(),template_bh.clear(),page_bh.clear(),profile_bh.clear(),api.groups.get().success(function(e){return 0==e.length?(modalError("No groups found!"),!1):void group_bh.add(e)}),api.templates.get().success(function(e){return 0==e.length?(modalError("No templates found!"),!1):void template_bh.add(e)}),api.pages.get().success(function(e){return 0==e.length?(modalError("No pages found!"),!1):void page_bh.add(e)}),api.SMTP.get().success(function(e){return 0==e.length?(modalError("No profiles found!"),!1):void profile_bh.add(e)}),api.campaignId.get(campaigns[e].id).success(function(e){$("#name").val("Copy of "+e.name),$("#template").val(e.template.name),$("#page").val(e.page.name),$("#profile").val(e.smtp.name),$("#url").val(e.url)}).error(function(e){$("#modal\\.flashes").empty().append(' '+e.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(e){$(this).removeClass("fv-modal-stack"),$("body").data("fv_open_modals",$("body").data("fv_open_modals")-1)}),$(".modal").on("shown.bs.modal",function(e){"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"))}),$.fn.modal.Constructor.prototype.enforceFocus=function(){$(document).off("focusin.bs.modal").on("focusin.bs.modal",$.proxy(function(e){this.$element[0]===e.target||this.$element.has(e.target).length||$(e.target).closest(".cke_dialog, .cke").length||this.$element.trigger("focus")},this))},$("#modal").on("hidden.bs.modal",function(e){dismiss()}),api.campaigns.summary().success(function(e){campaigns=e.campaigns,$("#loading").hide(),campaigns.length>0?($("#campaignTable").show(),campaignTable=$("#campaignTable").DataTable({columnDefs:[{orderable:!1,targets:"no-sort"}],order:[[1,"desc"]]}),$.each(campaigns,function(e,a){label=labels[a.status]||"label-default",campaignTable.row.add([escapeHtml(a.name),moment(a.created_date).format("MMMM Do YYYY, h:mm:ss a"),''+a.status+"",""]).draw(),$('[data-toggle="tooltip"]').tooltip()})):$("#emptyMessage").show()}).error(function(){$("#loading").hide(),errorFlash("Error fetching campaigns")}),$("#groupForm").submit(function(){var e=groupTable.row.add([escapeHtml($("#groupSelect").val()),'']).draw().node();return $(e).on("click","span>i.fa-trash-o",function(){groupTable.row($(this).parents("tr")).remove().draw()}),$("#groupSelect").typeahead("val",""),!1}),groupTable=$("#groupTable").DataTable({columnDefs:[{orderable:!1,targets:"no-sort"}]}),group_bh=new Bloodhound({datumTokenizer:function(e){return Bloodhound.tokenizers.whitespace(e.name)},queryTokenizer:Bloodhound.tokenizers.whitespace,local:[]}),group_bh.initialize(),$("#groupSelect.typeahead.form-control").typeahead({hint:!0,highlight:!0,minLength:1},{name:"groups",source:group_bh,templates:{empty:function(e){return'No groups matched that query
'},suggestion:function(e){return""+escapeHtml(e.name)+"
"}}}).bind("typeahead:select",function(e,a){$("#groupSelect").typeahead("val",a.name),$("#groupForm").submit()}).bind("typeahead:autocomplete",function(e,a){$("#groupSelect").typeahead("val",a.name)}),template_bh=new Bloodhound({datumTokenizer:function(e){return Bloodhound.tokenizers.whitespace(e.name)},queryTokenizer:Bloodhound.tokenizers.whitespace,local:[]}),template_bh.initialize(),$("#template.typeahead.form-control").typeahead({hint:!0,highlight:!0,minLength:1},{name:"templates",source:template_bh,templates:{empty:function(e){return'No templates matched that query
'},suggestion:function(e){return""+escapeHtml(e.name)+"
"}}}).bind("typeahead:select",function(e,a){$("#template").typeahead("val",a.name)}).bind("typeahead:autocomplete",function(e,a){$("#template").typeahead("val",a.name)}),page_bh=new Bloodhound({datumTokenizer:function(e){return Bloodhound.tokenizers.whitespace(e.name)},queryTokenizer:Bloodhound.tokenizers.whitespace,local:[]}),page_bh.initialize(),$("#page.typeahead.form-control").typeahead({hint:!0,highlight:!0,minLength:1},{name:"pages",source:page_bh,templates:{empty:function(e){return'No pages matched that query
'},suggestion:function(e){return""+escapeHtml(e.name)+"
"}}}).bind("typeahead:select",function(e,a){$("#page").typeahead("val",a.name)}).bind("typeahead:autocomplete",function(e,a){$("#page").typeahead("val",a.name)}),profile_bh=new Bloodhound({datumTokenizer:function(e){return Bloodhound.tokenizers.whitespace(e.name)},queryTokenizer:Bloodhound.tokenizers.whitespace,local:[]}),profile_bh.initialize(),$("#profile.typeahead.form-control").typeahead({hint:!0,highlight:!0,minLength:1},{name:"profiles",source:profile_bh,templates:{empty:function(e){return'No profiles matched that query
'},suggestion:function(e){return""+escapeHtml(e.name)+"
"}}}).bind("typeahead:select",function(e,a){$("#profile").typeahead("val",a.name)}).bind("typeahead:autocomplete",function(e,a){$("#profile").typeahead("val",a.name)})});