diff --git a/static/js/app/campaigns.js b/static/js/app/campaigns.js index d12d4736..c733fb82 100644 --- a/static/js/app/campaigns.js +++ b/static/js/app/campaigns.js @@ -145,6 +145,62 @@ function edit(campaign) { } } +function copy(idx) { + group_bh.clear(); + template_bh.clear(); + page_bh.clear(); + api.groups.get() + .success(function(groups) { + if (groups.length == 0) { + modalError("No groups found!") + return false; + } else { + group_bh.add(groups) + } + }) + api.templates.get() + .success(function(templates) { + if (templates.length == 0) { + modalError("No templates found!") + return false + } else { + template_bh.add(templates) + } + }) + api.pages.get() + .success(function(pages) { + if (pages.length == 0) { + modalError("No pages found!") + return false + } else { + page_bh.add(pages) + } + }) + // Set our initial values + var campaign = campaigns[idx] + $("#name").val("Copy of " + campaign.name) + $("#template").val(campaign.template.name) + $("#page").val(campaign.page.name) + $("#url").val(campaign.url) + $("input[name=from]").val(campaign.smtp.from_address) + $("input[name=host]").val(campaign.smtp.host) + $("input[name=username]").val(campaign.smtp.username) + $("input[name=password]").val(campaign.smtp.password) + $("input[name=ignore_cert_errors]").val(campaign.smtp.ignore_cert_errors) + console.log(campaign) + $.each(campaign.groups, function(i, group){ + groupTable.row.add([ + group.name, + '' + ]).draw() + $("#groupTable").on("click", "span>i.fa-trash-o", function() { + groupTable.row($(this).parents('tr')) + .remove() + .draw(); + }) + }) +} + $(document).ready(function() { // Setup multiple modals // Code based on http://miles-by-motorcycle.com/static/bootstrap-modal/index.html @@ -205,6 +261,9 @@ $(document).ready(function() { "
\ \ \ + \
"