Skip to content

Commit

Permalink
Revert "Fix edit info on grant page (#4793)" (#4921)
Browse files Browse the repository at this point in the history
This reverts commit 90bb0ff.
  • Loading branch information
danlipert authored Jul 31, 2019
1 parent 9dff0fc commit 3cdc50e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 59 deletions.
61 changes: 31 additions & 30 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,6 +43,8 @@ $(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 @@ -52,11 +54,10 @@ $(document).ready(function() {
$('#edit-details').on('click', (event) => {
event.preventDefault();

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

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

});

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

$('#edit-details').removeClass('hidden');
$('#save-details').addClass('hidden');
$('#cancel-details').addClass('hidden');
Expand All @@ -81,32 +87,23 @@ $(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,
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
},
success: function(json) {
window.location.reload(false);
},
Expand All @@ -118,10 +115,10 @@ $(document).ready(function() {
editableFields.forEach(field => disableEdit(field));
});

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

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

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

$(document).ready(() => {
$('#grant-profile-tabs button').click(function() {
document.location = $(this).attr('href');
});
});
48 changes: 22 additions & 26 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,30 +91,26 @@ <h4 class="m-auto text-center font-weight-semibold">{% trans "No Activity for th
</div>
</div>
{% endif %}

</div>
</div>

<script>
{% with description_tab_url=grant.url|addstr:'?tab=description' %}
let grant_description;

{% if request.get_full_path == description_tab_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>
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>
5 changes: 2 additions & 3 deletions app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,12 @@ 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

0 comments on commit 3cdc50e

Please sign in to comment.