Skip to content

Commit

Permalink
UI for creators to select allowed visibility levels
Browse files Browse the repository at this point in the history
closes #2099
  • Loading branch information
Changaco committed Apr 7, 2023
1 parent 9bec381 commit 0e5ccd9
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 57 deletions.
4 changes: 2 additions & 2 deletions liberapay/utils/__init__.py
Expand Up @@ -538,8 +538,8 @@ def word(mapping, k, pattern=r'^\w+$', unicode=False):
return r


FALSEISH = {'0', 'f', 'false', 'n', 'no'}
TRUEISH = {'1', 't', 'true', 'y', 'yes'}
FALSEISH = {'0', 'f', 'false', 'n', 'no', 'off'}
TRUEISH = {'1', 't', 'true', 'y', 'yes', 'on'}
NULLISH = {'', 'null', 'none'}


Expand Down
5 changes: 5 additions & 0 deletions style/base/base.scss
Expand Up @@ -929,3 +929,8 @@ abbr[title] {
/* Bootstrap 3.3.6 adds a bottom border but doesn't disable text-decoration */
text-decoration: none;
}

.preview {
border-left: 2px solid $gray-lighter;
padding: 11px 0 1px 2ex;
}
4 changes: 4 additions & 0 deletions style/base/utils.scss
Expand Up @@ -85,6 +85,10 @@
max-width: 500px;
}

.max-width-750 {
max-width: 750px;
}

@for $i from 0 through 100 {
.width-#{$i} {
width: $i * 1%;
Expand Down
54 changes: 31 additions & 23 deletions templates/macros/your-tip.html
Expand Up @@ -252,8 +252,37 @@ <h5 class="list-group-item-heading">{{ _("Manual renewal") }}</h5>
</label>
</li>
</ul>
% set patron_visibilities = tippee_p.recipient_settings.patron_visibilities
% set paypal_only = tippee_p.payment_providers == 2
{{ tip_visibility_choice(
tippee_name,
tippee_p.recipient_settings.patron_visibilities,
tippee_p.payment_providers,
tip
) }}
<br>
<button class="btn btn-primary btn-lg btn-block" {{ disabled }}>{{
(_("Modify your pledge") if pledging else _("Modify your donation"))
if tip.renewal_mode > 0 else
(_("Pledge") if pledging else _("Donate"))
}}</button>
% if tip.renewal_mode > 0
<br>
<button class="btn btn-danger btn-lg btn-block" name="selected_amount" value="0">{{
_("Cancel the pledge") if pledging else _("Discontinue the donation")
}}</button>
% elif tippee_p.payment_providers
<p class="text-center">{{ payment_methods_icons(tippee_p, new_currency) }}</p>
% elif not pledging
<p class="text-muted">{{ glyphicon('info-sign') }} {{ _(
"{username} hasn't configured any payment method yet, so your donation "
"cannot actually be processed right now. We will notify you when payment "
"becomes possible.",
username=tippee_name
) }}</p>
% endif
% endmacro

% macro tip_visibility_choice(tippee_name, patron_visibilities, payment_providers, tip)
% set paypal_only = payment_providers == 2
% if paypal_only
% if patron_visibilities == 0
% set patron_visibilities = 2
Expand Down Expand Up @@ -332,25 +361,4 @@ <h5 class="list-group-item-heading">{{ _("Public donation") }}</h5>
username=tippee_name
) }}</p>
% endif
<br>
<button class="btn btn-primary btn-lg btn-block" {{ disabled }}>{{
(_("Modify your pledge") if pledging else _("Modify your donation"))
if tip.renewal_mode > 0 else
(_("Pledge") if pledging else _("Donate"))
}}</button>
% if tip.renewal_mode > 0
<br>
<button class="btn btn-danger btn-lg btn-block" name="selected_amount" value="0">{{
_("Cancel the pledge") if pledging else _("Discontinue the donation")
}}</button>
% elif tippee_p.payment_providers
<p class="text-center">{{ payment_methods_icons(tippee_p, new_currency) }}</p>
% elif not pledging
<p class="text-muted">{{ glyphicon('info-sign') }} {{ _(
"{username} hasn't configured any payment method yet, so your donation "
"cannot actually be processed right now. We will notify you when payment "
"becomes possible.",
username=tippee_name
) }}</p>
% endif
% endmacro
89 changes: 57 additions & 32 deletions www/%username/patrons/index.spt
Expand Up @@ -7,10 +7,27 @@ if user != participant and user.recipient_settings.patron_visibilities < 2:
if not user.is_acting_as('admin'):
response.redirect(user.path('patrons/'))

patron_visibilities = participant.recipient_settings.patron_visibilities
if request.method == 'POST':
see_patrons = request.body.parse_boolean('see_patrons')
participant.update_recipient_settings(patron_visibilities=(7 if see_patrons else 1))
form_post_success(state)
if 'see_patrons' in request.body:
# Temporary support for legacy form
see_patrons = request.body.parse_boolean('see_patrons')
participant.update_recipient_settings(patron_visibilities=(7 if see_patrons else 1))
form_post_success(state)
new_patron_visibilities=(
(1 if request.body.get('allow_secret_donations') == 'on' else 0) |
(2 if request.body.get('allow_private_donations') == 'on' else 0) |
(4 if request.body.get('allow_public_donations') == 'on' else 0)
)
if new_patron_visibilities == 0:
raise response.error(400, _("You have to check at least one box."))
elif new_patron_visibilities == patron_visibilities:
raise response.redirect(participant.path('patrons/'))
if request.body.parse_boolean('confirmed', default=False):
participant.update_recipient_settings(patron_visibilities=new_patron_visibilities)
form_post_success(state)
else:
new_patron_visibilities = patron_visibilities or 1

title = participant.username
subhead = _("Patrons")
Expand Down Expand Up @@ -42,37 +59,45 @@ subhead = _("Patrons")
) }}</p>
% endif

% set patron_visibilities = participant.recipient_settings.patron_visibilities
<form action="" method="POST">
<h3>{{ _("Visibility levels") }}</h3>
<form action="" method="POST" id="patron_visibilities">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}" />
% if patron_visibilities == 0
<p class="text-info">{{ glyphicon('info-sign') }} {{ _(
"Liberapay now supports non-anonymous donations, do you want to know "
"who your patrons are?"
) }}</p>
<p class="buttons">
<button class="btn btn-primary" name="see_patrons" value="yes">{{ _(
"Enable non-anonymous donations"
) }}</button>
&nbsp;&nbsp;
<button class="btn btn-default" name="see_patrons" value="no">{{ _("No") }}</button>
</p>
% elif patron_visibilities > 1
<p class="text-muted">{{ _(
"You have opted-in to see who your patrons are. If you change your mind, "
"then {link_start}click here to disable non-anonymous donations{link_end}.",
link_start='<button class="link" name="see_patrons" value="no">'|safe,
link_end='</button>'|safe
) }}</p>
% else
<p class="text-muted">{{ _(
"You've chosen not to see who your patrons are. If you change your mind, "
"then {link_start}click here to enable non-anonymous donations{link_end}.",
link_start='<button class="link" name="see_patrons" value="yes">'|safe,
link_end='</button>'|safe
) }}</p>
% endif
<p>{{ _(
"Liberapay supports three visibility levels for donations. Each level can "
"be turned on or off, but at least one of them must be enabled."
) }}</p>
<div class="checkbox">
<label><input type="checkbox" name="allow_secret_donations"{% if new_patron_visibilities.__and__(1) %} checked{% endif %} /> {{ _("Allow secret donations") }}</label><br>
<label><input type="checkbox" name="allow_private_donations"{% if new_patron_visibilities.__and__(2) %} checked{% endif %} /> {{ _("Allow private donations") }}</label><br>
<label><input type="checkbox" name="allow_public_donations"{% if new_patron_visibilities.__and__(4) %} checked{% endif %} /> {{ _("Allow public donations") }}</label>
</div>
<button class="btn btn-primary">{{ _("Preview") }}</button>
</form>
<br>
% from "templates/macros/your-tip.html" import tip_visibility_choice with context
<p>{{ _("This is what your prospective donors currently see:") }}</p>
<div class="preview max-width-750">{{
tip_visibility_choice(
participant.username,
patron_visibilities,
participant.payment_providers,
participant.get_tip_to(participant)
)
}}</div>
% if request.method == 'POST'
<br>
<p>{{ _("This is what your prospective donors will see with the new settings:") }}</p>
<div class="preview max-width-750">{{
tip_visibility_choice(
participant.username,
new_patron_visibilities,
participant.payment_providers,
participant.get_tip_to(participant)
)
}}</div>
<br>
<button class="btn btn-success btn-lg" form="patron_visibilities" name="confirmed" value="true">{{ _("Save") }}</button>
% endif

% if patron_visibilities > 1
<h3>{{ _("Data export") }}</h3>
Expand Down

0 comments on commit 0e5ccd9

Please sign in to comment.