Skip to content

Commit e2dbb00

Browse files
committed
Merge pull request #1799 from rtfd/donate-form-arbitrary
Make dollar input field into optional arbitrary value input
2 parents bc96f5b + 6ddc6df commit e2dbb00

File tree

5 files changed

+53
-22
lines changed

5 files changed

+53
-22
lines changed

readthedocs/donate/forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Meta:
4444
'dollars': _('Companies donating over $400 can specify a logo URL and site link'),
4545
}
4646
widgets = {
47-
'dollars': forms.Select(attrs={
47+
'dollars': forms.HiddenInput(attrs={
4848
'data-bind': 'value: dollars'
4949
}),
5050
'logo_url': forms.TextInput(attrs={

readthedocs/donate/models.py

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
from django.db import models
22
from django.utils.translation import ugettext_lazy as _
33

4-
AMOUNT_CHOICES = (
5-
(5, '$5'),
6-
(10, '$10'),
7-
(25, '$25'),
8-
(50, '1 Hour ($50)'),
9-
(100, '2 Hours ($100)'),
10-
(200, '4 Hours ($200)'),
11-
(400, '1 Day ($400)'),
12-
(800, '2 Days ($800)'),
13-
(1200, '3 Days ($1200)'),
14-
(1600, '4 Days ($1600)'),
15-
(2000, '5 Days ($2000)'),
16-
(4000, '2 Weeks ($4000)'),
17-
(6000, '3 Weeks ($6000)'),
18-
(8000, '4 Weeks ($8000)'),
19-
)
20-
214
DISPLAY_CHOICES = (
225
('doc', 'Documentation Pages'),
236
('site-footer', 'Site Footer'),
@@ -34,8 +17,7 @@ class Supporter(models.Model):
3417
email = models.EmailField(_('Email'), max_length=200, blank=True)
3518
user = models.ForeignKey('auth.User', verbose_name=_('User'),
3619
related_name='goldonce', blank=True, null=True)
37-
dollars = models.IntegerField(_('Amount'), choices=AMOUNT_CHOICES,
38-
default=50)
20+
dollars = models.IntegerField(_('Amount'), default=50)
3921
logo_url = models.URLField(_('Logo URL'), max_length=255, blank=True,
4022
null=True)
4123
site_url = models.URLField(_('Site URL'), max_length=255, blank=True,

readthedocs/donate/static-src/donate/js/donate.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ function DonateView (config) {
1010

1111
self.constructor.call(self, config);
1212

13-
self.dollars = ko.observable();
13+
self.dollars_select = ko.observable();
14+
self.dollars_input = ko.observable();
15+
self.dollars = ko.computed(function () {
16+
var dollars;
17+
dollars = self.dollars_select();
18+
if (dollars == 'custom') {
19+
dollars = self.dollars_input();
20+
}
21+
return dollars;
22+
});
1423
self.logo_url = ko.observable();
1524
self.site_url = ko.observable();
1625
self.error_dollars = ko.observable();

readthedocs/donate/static/donate/js/donate.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readthedocs/donate/templates/donate/create.html

+40
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,46 @@ <h2>Donate to Read the Docs</h2>
5252
{% include 'core/ko_form_field.html' with field=groupfield %}
5353
{% endfor %}
5454
</div>
55+
{% elif field.name == 'logo_url' or field.name == 'site_url' %}
56+
<div data-bind="visible: urls_enabled">
57+
{% include 'core/ko_form_field.html' with field=field %}
58+
</div>
59+
{% elif field.name == 'dollars' %}
60+
{{ field.errors }}
61+
<p>
62+
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
63+
<input
64+
type="hidden"
65+
name="{{ field.name }}"
66+
id="{{ field.id_for_label }}"
67+
data-bind="value: dollars" />
68+
<input
69+
type="number"
70+
data-bind="textInput: dollars_input, visible: dollars_select() == 'custom'"
71+
value="50"
72+
id="id_dollars_input"
73+
style="display: none;" />
74+
<select data-bind="value: dollars_select, visible: dollars_select() != 'custom'">
75+
<option value="custom">{% trans "Custom amount" %}</option>
76+
<option value="5">$5</option>
77+
<option value="10">$10</option>
78+
<option value="25">$25</option>
79+
<option value="50" selected>{% trans "1 Hour" %} ($50)</option>
80+
<option value="100">{% trans "2 Hours" %} ($100)</option>
81+
<option value="200">{% trans "4 Hours" %} ($200)</option>
82+
<option value="400">{% trans "1 Day" %} ($400)</option>
83+
<option value="800">{% trans "2 Days" %} ($800)</option>
84+
<option value="1200">{% trans "3 Days" %} ($1200)</option>
85+
<option value="1600">{% trans "4 Days" %} ($1600)</option>
86+
<option value="2000">{% trans "5 Days" %} ($2000)</option>
87+
<option value="4000">{% trans "2 Weeks" %} ($4000)</option>
88+
<option value="6000">{% trans "3 Weeks" %} ($6000)</option>
89+
<option value="8000">{% trans "4 Weeks" %} ($8000)</option>
90+
</select>
91+
{% if field.help_text %}
92+
<span class="helptext">{{ field.help_text }}</span>
93+
{% endif %}
94+
</p>
5595
{% else %}
5696
{% include 'core/ko_form_field.html' with field=field %}
5797
{% endif %}

0 commit comments

Comments
 (0)