From 1f9da86e39fd4f5b1b89dcba1d0e779dbf5d47be Mon Sep 17 00:00:00 2001 From: CactusPuppy Date: Thu, 4 Mar 2021 23:43:27 -0800 Subject: [PATCH 1/6] Fill submission text if the field is currently empty --- app/assets/javascripts/osem.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/osem.js b/app/assets/javascripts/osem.js index 0839f13b..59174f01 100644 --- a/app/assets/javascripts/osem.js +++ b/app/assets/javascripts/osem.js @@ -147,6 +147,15 @@ function word_count(text, divId, maxcount) { }); }; +function fill_if_empty(text_area, filler) { + let area = $('#' + text_area); + + if (!area.val()) { + area.val(filler); + area.trigger('change'); + } +} + /* Wait for the DOM to be ready before attaching events to the elements */ $( document ).ready(function() { /* Set the minimum and maximum proposal abstract and submission text word length */ @@ -155,15 +164,15 @@ $( document ).ready(function() { var max = $selected.data("max-words"); var min = $selected.data("min-words"); + // Set the placeholder text for the abstract + fill_if_empty('event_submission_text', $selected.data("help")); + $("#abstract-maximum-word-count").text(max); $("#submission-maximum-word-count").text(max); $("#abstract-minimum-word-count").text(min); $("#submission-minimum-word-count").text(min); word_count($('#event_abstract').get(0), 'abstract-count', max); word_count($('#event_submission_text').get(0), 'submission-count', max); - - // Set the placeholder text for the abstract - $('#event_submission_text').attr("placeholder", $selected.data("help")); }) .trigger('change'); From 71ce82c968aebfc246d4cdfbc593a541e381ca28 Mon Sep 17 00:00:00 2001 From: CactusPuppy Date: Fri, 5 Mar 2021 12:39:50 -0800 Subject: [PATCH 2/6] Create JS hook for template reset --- app/assets/javascripts/osem.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/assets/javascripts/osem.js b/app/assets/javascripts/osem.js index 59174f01..9d5054f8 100644 --- a/app/assets/javascripts/osem.js +++ b/app/assets/javascripts/osem.js @@ -189,6 +189,18 @@ $( document ).ready(function() { var max = $selected.data("max-words"); word_count(this, 'submission-count', max); }); + + /* Listen for reset template button, wait for confirm, and reset. */ + $('#sub_text_reset').click((e) => { + let $selected = $("#event_event_type_id option:selected"); + let $this = $(e.target); + let affirm = confirm($this.data('confirm')); + if (affirm) { + let sub_text = $('#event_submission_text'); + sub_text.val($selected.data('help')); + sub_text.trigger('change'); + } + }); }); /* Commodity function for modal windows */ From 8f465136c3a7d6a0da7f1e2c9582078347539c05 Mon Sep 17 00:00:00 2001 From: CactusPuppy Date: Sat, 6 Mar 2021 22:56:01 -0800 Subject: [PATCH 3/6] Add buttons for submission text template reset --- app/views/proposals/_proposal_form.html.haml | 1 + app/views/proposals/new.html.haml | 1 + 2 files changed, 2 insertions(+) diff --git a/app/views/proposals/_proposal_form.html.haml b/app/views/proposals/_proposal_form.html.haml index 5b4e7079..010eea9e 100644 --- a/app/views/proposals/_proposal_form.html.haml +++ b/app/views/proposals/_proposal_form.html.haml @@ -50,6 +50,7 @@ = f.input :submission_text, input_html: { rows: 5, data: { provide: 'markdown' }, placeholder: '' }, hint: markdown_hint('Only conference organizers will read this.') + %button.btn.btn-primary.primary-button{ type: 'button', id: 'sub_text_reset', data: { confirm: 'Do you really want to reset your submission text to the provided template?' } } Reset to Template %p You have used diff --git a/app/views/proposals/new.html.haml b/app/views/proposals/new.html.haml index bdd16e11..e6aaa355 100644 --- a/app/views/proposals/new.html.haml +++ b/app/views/proposals/new.html.haml @@ -63,6 +63,7 @@ = f.input :submission_text, input_html: { rows: 5, data: { provide: 'markdown' } }, hint: markdown_hint + %button.btn.btn-primary.primary-button{ type: 'button', id: 'sub_text_reset', data: { confirm: 'Do you really want to reset your submission text to the provided template?' } } Reset to Template %p You have used From cdbeb6ec4cd2e0c2c4e9b8e337bf89a8b0f9002b Mon Sep 17 00:00:00 2001 From: CactusPuppy Date: Sun, 7 Mar 2021 23:00:40 -0800 Subject: [PATCH 4/6] Add test for covering Rest to Template button --- spec/features/proposals_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 15c23fcb..d3946ec6 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -177,5 +177,24 @@ feature Event do @event.reload expect(@event.state).to eq('withdrawn') end + + scenario 'can reset to text template', feature: true, js: true do + event_type = conference.program.event_types[-1] + event_type.description = 'Example event description' + event_type.save! + + sign_in participant + visit new_conference_program_proposal_path(conference.short_title) + + fill_in 'event_title', with: 'Example Proposal' + select(event_type.title, from: 'event[event_type_id]') + fill_in 'event_submission_text', with: 'Lorem ipsum example submission text' + + accept_confirm do + click_button 'Reset to Template' + end + + expect(page.find('#event_submission_text').value).to eq(event_type.description) + end end end From 2e61bc2948667a536b2020d3b88a8a75056c6fcc Mon Sep 17 00:00:00 2001 From: CactusPuppy Date: Sun, 7 Mar 2021 23:02:49 -0800 Subject: [PATCH 5/6] Include help data for event types in new proposal view (Why doesn't the new view use the proposal form partial?) --- app/views/proposals/new.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/proposals/new.html.haml b/app/views/proposals/new.html.haml index e6aaa355..e6307efa 100644 --- a/app/views/proposals/new.html.haml +++ b/app/views/proposals/new.html.haml @@ -33,7 +33,7 @@ = f.input :title, as: :string, required: true, input_html: { required: true } = f.input :event_type_id, as: :select, collection: @program.event_types.map {|type| ["#{type.title} - #{show_time(type.length)}", type.id, - data: { min_words: type.minimum_abstract_length, max_words: type.maximum_abstract_length }]}, + data: { min_words: type.minimum_abstract_length, max_words: type.maximum_abstract_length, help: type.description }]}, include_blank: false, label: 'Type', input_html: { class: 'select-help-toggle' } - @program.event_types.each do |event_type| From f6b026226aa798f0d2ff87c2cc41dc981e2a5f7d Mon Sep 17 00:00:00 2001 From: CactusPuppy Date: Tue, 9 Mar 2021 19:08:13 -0800 Subject: [PATCH 6/6] Update comment in osem.js to be accurate --- app/assets/javascripts/osem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/osem.js b/app/assets/javascripts/osem.js index 9d5054f8..636ed959 100644 --- a/app/assets/javascripts/osem.js +++ b/app/assets/javascripts/osem.js @@ -164,7 +164,7 @@ $( document ).ready(function() { var max = $selected.data("max-words"); var min = $selected.data("min-words"); - // Set the placeholder text for the abstract + // Set the filler text for the submission text fill_if_empty('event_submission_text', $selected.data("help")); $("#abstract-maximum-word-count").text(max);