From 43331e2fa60251b5efd78efd71bc24f2d29bf013 Mon Sep 17 00:00:00 2001 From: Pierrick TURELIER Date: Fri, 2 Aug 2019 16:43:20 +0200 Subject: [PATCH] Fix edit info on grant page (#4928) * Fix edit info on grant page * Fix grant data eslint error * Fix grant/detail.js lint * Fix grant detail.js code formatting * Fix build error on grant detail.js * Fix lint formatting * Fix contract_owner_button onClick indentation * Fix condition to initialize quill in grant edit * add css fix --- app/assets/v2/css/grants/detail.css | 2 +- app/assets/v2/js/grants/detail.js | 61 ++++++++++---------- app/grants/templates/grants/detail/tabs.html | 48 ++++++++------- app/grants/views.py | 5 +- 4 files changed, 60 insertions(+), 56 deletions(-) diff --git a/app/assets/v2/css/grants/detail.css b/app/assets/v2/css/grants/detail.css index 2cb0946c33e..a8aadc3441b 100644 --- a/app/assets/v2/css/grants/detail.css +++ b/app/assets/v2/css/grants/detail.css @@ -3,7 +3,7 @@ max-width: 85vw } - #editor.ql-bubble .ql-editor { + #editor.ql-bubble .ql-editor[contenteditable='false'] { padding: 0; } diff --git a/app/assets/v2/js/grants/detail.js b/app/assets/v2/js/grants/detail.js index b98d4160e68..5f5dc720ae5 100644 --- a/app/assets/v2/js/grants/detail.js +++ b/app/assets/v2/js/grants/detail.js @@ -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')) { @@ -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'); @@ -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'); @@ -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'); @@ -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); }, @@ -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'); @@ -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; @@ -206,6 +208,9 @@ $(document).ready(function() { }); }); + $('#grant-profile-tabs button').click(function() { + document.location = $(this).attr('href'); + }); }); const makeEditable = (input) => { @@ -249,9 +254,3 @@ const copyDuplicateDetails = () => { }); }); }; - -$(document).ready(() => { - $('#grant-profile-tabs button').click(function() { - document.location = $(this).attr('href'); - }); -}); \ No newline at end of file diff --git a/app/grants/templates/grants/detail/tabs.html b/app/grants/templates/grants/detail/tabs.html index 15d05a68c59..7a26c8b1739 100644 --- a/app/grants/templates/grants/detail/tabs.html +++ b/app/grants/templates/grants/detail/tabs.html @@ -17,7 +17,7 @@ {% load static humanize i18n grants_extra %}
- + @@ -32,12 +32,12 @@ - + - +
@@ -91,26 +91,30 @@

{% trans "No Activity for th

{% endif %} - \ No newline at end of file + {% 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 %} + diff --git a/app/grants/views.py b/app/grants/views.py index ca0f58ca63d..0a840578624 100644 --- a/app/grants/views.py +++ b/app/grants/views.py @@ -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)