-
-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase Funding Limit Request Form (#2209)
* Increase Funding Limit Request Form Fixes #2199 * Increase Funding Limit Request Form: lint * Increase Funding Limit Request Form: lint
- Loading branch information
1 parent
1bb6b1c
commit de119e6
Showing
7 changed files
with
287 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
app/assets/v2/js/pages/increase_funding_limit_request_form.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
// Overwrite from shared.js | ||
// eslint-disable-next-line no-empty-function | ||
var trigger_form_hooks = function() { | ||
}; | ||
|
||
$(document).ready(function() { | ||
$('[for=id_comment]').append( | ||
' (<span id="charcount">500</span> ' + gettext('characters left') + ')' | ||
); | ||
$('[name=comment]').bind('input propertychange', function() { | ||
this.value = this.value.replace(/ +(?= )/g, ''); | ||
|
||
if (this.value.length > 500) { | ||
this.value = this.value.substring(0, 500); | ||
} | ||
|
||
$('#charcount').html(500 - this.value.length); | ||
}); | ||
|
||
const form = $('#increase_request_form'); | ||
|
||
form.validate({ | ||
submitHandler: function(form) { | ||
const inputElements = $(form).find(':input'); | ||
const formData = {}; | ||
|
||
inputElements.removeAttr('disabled'); | ||
$.each($(form).serializeArray(), function() { | ||
formData[this.name] = this.value; | ||
}); | ||
|
||
inputElements.attr('disabled', 'disabled'); | ||
loading_button($('.js-submit')); | ||
|
||
const payload = JSON.stringify(formData); | ||
|
||
$.post('/requestincrease', payload).then( | ||
function(result) { | ||
inputElements.removeAttr('disabled'); | ||
$('#requested_by').attr('disabled', 'disabled'); | ||
unloading_button($('.js-submit')); | ||
|
||
$('#primary_form').hide(); | ||
$('#success_container').show(); | ||
} | ||
).fail( | ||
function(result) { | ||
inputElements.removeAttr('disabled'); | ||
$('#requested_by').attr('disabled', 'disabled'); | ||
unloading_button($('.js-submit')); | ||
|
||
var alertMsg = result && result.responseJSON ? result.responseJSON.error : null; | ||
|
||
if (alertMsg === null) { | ||
alertMsg = gettext('Network error. Please reload the page and try again.'); | ||
} | ||
|
||
_alert({ message: alertMsg }, 'error'); | ||
} | ||
); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -759,3 +759,31 @@ def new_bounty_request(model): | |
) | ||
finally: | ||
translation.activate(cur_language) | ||
|
||
|
||
def new_funding_limit_increase_request(profile, cleaned_data): | ||
to_email = '[email protected]' | ||
from_email = profile.email or settings.SERVER_EMAIL | ||
cur_language = translation.get_language() | ||
usdt_per_tx = cleaned_data.get('usdt_per_tx', 0) | ||
usdt_per_week = cleaned_data.get('usdt_per_week', 0) | ||
comment = cleaned_data.get('comment', '') | ||
accept_link = f'{settings.BASE_URL}requestincrease?'\ | ||
f'profile_pk={profile.pk}&'\ | ||
f'usdt_per_tx={usdt_per_tx}&'\ | ||
f'usdt_per_week={usdt_per_week}' | ||
|
||
try: | ||
setup_lang(to_email) | ||
subject = _('New Funding Limit Increase Request') | ||
body = f'New Funding Limit Request from {profile} ({profile.absolute_url}).\n\n'\ | ||
f'New Limit in USD per Transaction: {usdt_per_tx}\n'\ | ||
f'New Limit in USD per Week: {usdt_per_week}\n\n'\ | ||
f'To accept the Funding Limit, visit: {accept_link}\n'\ | ||
f'Administration Link: ({settings.BASE_URL}_administrationdashboard/profile/'\ | ||
f'{profile.pk}/change/#id_max_tip_amount_usdt_per_tx)\n\n'\ | ||
f'Comment:\n{comment}' | ||
|
||
send_mail(from_email, to_email, subject, body, from_name=_("No Reply from Gitcoin.co")) | ||
finally: | ||
translation.activate(cur_language) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Define retail related forms. | ||
Copyright (C) 2018 Gitcoin Core | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
from django import forms | ||
from django.utils.html import escape, strip_tags | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class FundingLimitIncreaseRequestForm(forms.Form): | ||
"""Define the FundingLimitIncreaseRequestForm handling.""" | ||
|
||
usdt_per_tx = forms.DecimalField(label=_('New Limit in USD per Transaction'), initial=500, max_digits=50) | ||
usdt_per_week = forms.DecimalField(label=_('New Limit in USD per Week'), initial=1500, max_digits=50) | ||
comment = forms.CharField(max_length=500, widget=forms.Textarea) | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(FundingLimitIncreaseRequestForm, self).__init__(*args, **kwargs) | ||
|
||
self.fields['comment'].widget.attrs['placeholder'] = _('Please tell us why you need a limit increase.') | ||
self.fields['comment'].widget.attrs['rows'] = '4' | ||
self.fields['comment'].widget.attrs['cols'] = '50' | ||
|
||
for field in self.fields: | ||
self.fields[field].widget.attrs['class'] = 'form__input' | ||
|
||
def clean_comment(self): | ||
comment = self.cleaned_data['comment'] or '' | ||
return escape(strip_tags(comment)) |
81 changes: 81 additions & 0 deletions
81
app/retail/templates/increase_funding_limit_request_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{% comment %} | ||
Copyright (C) 2018 Gitcoin Core | ||
|
||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published | ||
by the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
|
||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
{% endcomment %} | ||
{% load i18n static %} | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
{% include 'shared/head.html' %} | ||
{% include 'shared/cards.html' %} | ||
</head> | ||
<body class="interior {{ active }}"> | ||
<div class="container-fluid header dash"> | ||
{% include 'shared/nav.html' %} | ||
</div> | ||
<div class="row no-gutter"> | ||
<div class="col body"> | ||
<div class="container-fluid no-gutter"> | ||
<div class="m-4"> | ||
<div> | ||
<div class="request-form" id="primary_form"> | ||
<h3>{{ title }}</h3> | ||
<p>{{ card_desc }}</p> | ||
<div class="mb-3"> | ||
<label for="requested_by" class="form__label">{% trans 'Your Github Profile' %} | ||
{% if not user.is_authenticated %} | ||
(<a href="{% url 'social:begin' 'github' %}?next={{ request.get_full_path }}">{% trans 'Login' %}</a>) | ||
{% endif %} | ||
</label> | ||
<input name="requested_by" placeholder="{% trans "Please Login First" %}" id="requested_by" class="form__input" type="text" value="{% if github_handle %}{{ github_handle }}{% endif %}" required disabled /> | ||
</div> | ||
<form id="increase_request_form"> | ||
{% for field in form %} | ||
<div class="mb-3"> | ||
<label for="id_{{ field.name }}" class="form__label">{{ field.label }}</label> | ||
{{ field }} | ||
</div> | ||
{% endfor %} | ||
<div class="form__footer"> | ||
<button class="button button--primary btn-block js-submit" type="submit">{% trans 'Proceed' %}</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
<div id="success_container" class="text-center" style="display: none;"> | ||
<h3>{% trans 'Funding Limit Request Received' %}</h3> | ||
{% include 'svgs/success.svg' %} | ||
<div> | ||
<p> | ||
{% trans 'It takes us usually 1 business day to process your request.' %} | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-12 offset-md-1 col-md-10"> | ||
{% include 'shared/newsletter.html' %} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% include 'shared/bottom_notification.html' %} | ||
{% include 'shared/analytics.html' %} | ||
{% include 'shared/footer_scripts.html' %} | ||
{% include 'shared/footer.html' %} | ||
{% include 'shared/messages.html' %} | ||
</body> | ||
<script src="{% static "v2/js/shared.js" %}"></script> | ||
<script src="{% static "v2/js/pages/increase_funding_limit_request_form.js" %}"></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters