Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edit info on grant page #4928

Merged
merged 20 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/v2/css/grants/detail.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
max-width: 85vw
}

#editor.ql-bubble .ql-editor {
#editor.ql-bubble .ql-editor[contenteditable='false'] {
padding: 0;
}

Expand Down
61 changes: 30 additions & 31 deletions app/assets/v2/js/grants/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $(document).ready(function() {
$('#grant_contract_owner_address').text(),
'#cancel_grant',
'Looks like your grant has been created with ' +
$('#grant_contract_owner_address').text() + '. Switch to take action on your grant.'
$('#grant_contract_owner_address').text() + '. Switch to take action on your grant.'
);

if ($('#cancel_grant').attr('disabled')) {
Expand All @@ -43,8 +43,6 @@ $(document).ready(function() {
}
}, 1000);

let _text = grant_description.getContents();

userSearch('#grant-admin', false, undefined, false, false, true);
userSearch('#grant-members', false, undefined, false, false, true);
$('.select2-selection__rendered').removeAttr('title');
Expand All @@ -54,10 +52,11 @@ $(document).ready(function() {
$('#edit-details').on('click', (event) => {
event.preventDefault();

if (grant_description) {
if (grant_description !== undefined) {
grant_description.enable(true);
grant_description.getContents();
}

$('#edit-details').addClass('hidden');
$('#save-details').removeClass('hidden');
$('#cancel-details').removeClass('hidden');
Expand All @@ -70,14 +69,9 @@ $(document).ready(function() {
editableFields.forEach(field => {
makeEditable(field);
});

});

$('#save-details').on('click', (event) => {
if (grant_description) {
grant_description.enable(false);
}

$('#save-details').on('click', event => {
$('#edit-details').removeClass('hidden');
$('#save-details').addClass('hidden');
$('#cancel-details').addClass('hidden');
Expand All @@ -87,23 +81,32 @@ $(document).ready(function() {
let edit_title = $('#form--input__title').val();
let edit_reference_url = $('#form--input__reference-url').val();
let edit_admin_profile = $('#grant-admin option').last().text();
let edit_description = grant_description.getText();
let edit_description_rich = JSON.stringify(grant_description.getContents());
let edit_amount_goal = $('#amount_goal').val();
let edit_grant_members = $('#grant-members').val();

let data = {
'edit-title': edit_title,
'edit-reference_url': edit_reference_url,
'edit-admin_profile': edit_admin_profile,
'edit-amount_goal': edit_amount_goal,
'edit-grant_members[]': edit_grant_members
};

if (grant_description !== undefined) {
const edit_description = grant_description.getText();
const edit_description_rich = JSON.stringify(grant_description.getContents());

grant_description.enable(false);
data = Object.assign({}, data, {
'edit-description': edit_description,
'edit-description_rich': edit_description_rich
});
}

$.ajax({
type: 'post',
url: '',
data: {
'edit-title': edit_title,
'edit-reference_url': edit_reference_url,
'edit-admin_profile': edit_admin_profile,
'edit-description': edit_description,
'edit-description_rich': edit_description_rich,
'edit-amount_goal': edit_amount_goal,
'edit-grant_members[]': edit_grant_members
},
data,
success: function(json) {
window.location.reload(false);
},
Expand All @@ -115,10 +118,10 @@ $(document).ready(function() {
editableFields.forEach(field => disableEdit(field));
});

$('#cancel-details').on('click', (event) => {
if (grant_description) {
$('#cancel-details').on('click', event => {
if (grant_description !== undefined) {
grant_description.enable(false);
grant_description.setContents(_text);
grant_description.setContents(grant_description.getContents());
}
$('#edit-details').removeClass('hidden');
$('#save-details').addClass('hidden');
Expand All @@ -129,7 +132,6 @@ $(document).ready(function() {
});

$('#cancel_grant').on('click', function(e) {

$('.modal-cancel-grants').on('click', function(e) {
let contract_address = $('#contract_address').val();
let grant_cancel_tx_id;
Expand Down Expand Up @@ -206,6 +208,9 @@ $(document).ready(function() {
});
});

$('#grant-profile-tabs button').click(function() {
document.location = $(this).attr('href');
});
});

const makeEditable = (input) => {
Expand Down Expand Up @@ -249,9 +254,3 @@ const copyDuplicateDetails = () => {
});
});
};

$(document).ready(() => {
$('#grant-profile-tabs button').click(function() {
document.location = $(this).attr('href');
});
});
48 changes: 26 additions & 22 deletions app/grants/templates/grants/detail/tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{% load static humanize i18n grants_extra %}
<div class="px-lg-5">
<div id="grant-profile-tabs" class="tab-container font-body mt-5 mb-4">

<button type="button" id="nav-description" href="{{grant.url}}?tab=description" class="section-tab {% if tab == "description" %} active {% endif %}">
{% trans "DESCRIPTION" %}
</button>
Expand All @@ -32,12 +32,12 @@
<button type="button" id="nav-summary" href="{{grant.url}}?tab=updates" class="section-tab {% if tab == "updates" %} active {% endif %}">
{% trans "UPDATES" %}
</button>

<button type="button" id="nav-contributors" href="{{grant.url}}?tab=contributors" class="section-tab {% if tab == "contributors" %} active {% endif %}">
{% trans "CONTRIBUTORS" %}
<span class="nav-badge">{{ contributions|length }}</span>
</button>

</div>

<div id="grant-profile-tabs-sections" class="tab-sections section pt-2">
Expand Down Expand Up @@ -91,26 +91,30 @@ <h4 class="m-auto text-center font-weight-semibold">{% trans "No Activity for th
</div>
</div>
{% endif %}

</div>
</div>

<script>
let grant_description;
{% if is_admin and not grant_is_inactive %}
grant_description = new Quill('#editor', {
theme: 'snow',
});
grant_description.enable(false);
{% else %}
grant_description = new Quill('#editor', {
theme: 'bubble',
readOnly: true,
});
{% endif %}

let desc = JSON.parse(grant_description.getContents().ops[0].insert);
if (desc.ops) {
grant_description.setContents(desc);
}
</script>
{% with description_tab_url=grant.url|addstr:'?tab=description' %}
let grant_description;

{% if request.get_full_path == description_tab_url or request.get_full_path == grant.url %}
grant_description = new Quill('#editor', {
theme: 'bubble',
readOnly: true,
});

{% if is_admin and not grant_is_inactive %}
grant_description = new Quill('#editor', {
theme: 'snow',
});
grant_description.enable(false);
{% endif %}

let desc = JSON.parse(grant_description.getContents().ops[0].insert);
if (desc.ops) {
grant_description.setContents(desc);
}
{% endif %}
{% endwith %}
</script>
5 changes: 3 additions & 2 deletions app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,13 @@ def grant_details(request, grant_id, grant_slug):
grant.reference_url = request.POST.get('edit-reference_url')
form_profile = request.POST.get('edit-admin_profile')
admin_profile = Profile.objects.get(handle=form_profile)
grant.description = request.POST.get('edit-description')
grant.description_rich = request.POST.get('edit-description_rich')
grant.amount_goal = Decimal(request.POST.get('edit-amount_goal'))
team_members = request.POST.getlist('edit-grant_members[]')
team_members.append(str(admin_profile.id))
grant.team_members.set(team_members)
if 'edit-description' in request.POST:
grant.description = request.POST.get('edit-description')
grant.description_rich = request.POST.get('edit-description_rich')
if grant.admin_profile != admin_profile:
grant.request_ownership_change = admin_profile
change_grant_owner_request(grant, grant.request_ownership_change)
Expand Down