diff --git a/r2/example.ini b/r2/example.ini index 1b487afe7..75fcf2f42 100644 --- a/r2/example.ini +++ b/r2/example.ini @@ -316,6 +316,7 @@ ad_domain = http://reddit.local allowed_pay_countries = United States, United Kingdom, Canada sponsors = selfserve_support_email = selfservesupport@mydomain.com +MAX_CAMPAIGNS_PER_LINK = 100 # authorize.net credentials (blank authorizenetapi to disable) authorizenetapi = diff --git a/r2/r2/controllers/promotecontroller.py b/r2/r2/controllers/promotecontroller.py index eb08882a5..4474b612e 100644 --- a/r2/r2/controllers/promotecontroller.py +++ b/r2/r2/controllers/promotecontroller.py @@ -387,6 +387,17 @@ class PromoteController(ListingController): errors.BAD_FUTURE_DATE, errors.BAD_DATE_RANGE)): return + # Limit the number of PromoCampaigns a Link can have + # Note that the front end should prevent the user from getting + # this far + existing_campaigns = list(PromoCampaign._by_link(l._id)) + if len(existing_campaigns) > g.MAX_CAMPAIGNS_PER_LINK: + c.errors.add(errors.TOO_MANY_CAMPAIGNS, + msg_params={'count': g.MAX_CAMPAIGNS_PER_LINK}, + field='title') + form.has_errors('title', errors.TOO_MANY_CAMPAIGNS) + return + duration = max((end - start).days, 1) if form.has_errors('bid', errors.BAD_BID): diff --git a/r2/r2/lib/app_globals.py b/r2/r2/lib/app_globals.py index ff8e5a17c..a9aeb7ea0 100755 --- a/r2/r2/lib/app_globals.py +++ b/r2/r2/lib/app_globals.py @@ -88,6 +88,7 @@ class Globals(object): 'page_cache_time', 'commentpane_cache_time', 'num_mc_clients', + 'MAX_CAMPAIGNS_PER_LINK', 'MIN_DOWN_LINK', 'MIN_UP_KARMA', 'MIN_DOWN_KARMA', diff --git a/r2/r2/lib/errors.py b/r2/r2/lib/errors.py index 25af9676e..b25002810 100644 --- a/r2/r2/lib/errors.py +++ b/r2/r2/lib/errors.py @@ -113,6 +113,7 @@ error_list = dict(( ('BAD_HASH', _("i don't believe you.")), ('ALREADY_MODERATOR', _('that user is already a moderator')), ('BID_LIVE', _('you cannot edit the bid of a live ad')), + ('TOO_MANY_CAMPAIGNS', _('you have too many campaigns for that promotion')), ('BAD_JSONP_CALLBACK', _('that jsonp callback contains invalid characters')), )) errors = Storage([(e, e) for e in error_list.keys()]) diff --git a/r2/r2/public/static/css/reddit.css b/r2/r2/public/static/css/reddit.css index be09bcacc..2eda78bac 100755 --- a/r2/r2/public/static/css/reddit.css +++ b/r2/r2/public/static/css/reddit.css @@ -4683,6 +4683,9 @@ table.lined-table { margin-top: 0px; } +.create-promo .hidden { display: none; } +button.new-campaign:disabled { color: gray; } + .bidding-history { padding-top: 10px; } .bidding-history .linefield { width: auto; diff --git a/r2/r2/public/static/js/sponsored.js b/r2/r2/public/static/js/sponsored.js index 7d24dc7e9..90faff7ef 100644 --- a/r2/r2/public/static/js/sponsored.js +++ b/r2/r2/public/static/js/sponsored.js @@ -103,7 +103,7 @@ function targeting_off(elem) { (function($) { function get_flag_class(flags) { - var css_class = ""; + var css_class = "campaign-row"; if(flags.free) { css_class += " free"; } @@ -147,6 +147,7 @@ $.new_campaign = function(campaign_id36, start_date, end_date, duration, $(".existing-campaigns table").show() .insert_table_rows([{"id": "", "css_class": css_class, "cells": row}], -1); + check_number_of_campaigns(); $.set_up_campaigns() }); return $; @@ -280,7 +281,7 @@ function del_campaign(elem) { $.request("delete_campaign", {"campaign_id36": campaign_id36, "link_id": link_id}, null, true, "json", false); - $(elem).children(":first").delete_table_row(); + $(elem).children(":first").delete_table_row(check_number_of_campaigns); } @@ -338,7 +339,22 @@ function edit_campaign(elem) { } } +function check_number_of_campaigns(){ + if ($(".campaign-row").length >= $(".existing-campaigns").data("max-campaigns")){ + $(".error.TOO_MANY_CAMPAIGNS").fadeIn(); + $("button.new-campaign").attr("disabled", "disabled"); + return true; + } else { + $(".error.TOO_MANY_CAMPAIGNS").fadeOut(); + $("button.new-campaign").removeAttr("disabled"); + return false; + } +} + function create_campaign(elem) { + if (check_number_of_campaigns()){ + return; + } cancel_edit(function() {; init_startdate(); init_enddate(); diff --git a/r2/r2/templates/promotelinkform.html b/r2/r2/templates/promotelinkform.html index b03690c26..d74718def 100644 --- a/r2/r2/templates/promotelinkform.html +++ b/r2/r2/templates/promotelinkform.html @@ -220,7 +220,13 @@ ${self.javascript_setup()}
-${_("You have too many campaigns for this link.")} + ${_("It's time to start fresh!")}
+