Skip to content

Commit

Permalink
Add Today and Clear buttons to fuzzy dates, addresses #697.
Browse files Browse the repository at this point in the history
  • Loading branch information
remomueller committed Mar 11, 2019
1 parent a586b70 commit ee0437f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
28 changes: 28 additions & 0 deletions app/assets/javascripts/components/fuzzy_dates.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,31 @@ $(document)
else
$(this).val("")
)
.on("click", "[data-object~=fuzzy-date-today]", ->
date = new Date()
dy = date.getDate()
mo = date.getMonth() + 1
yr = date.getFullYear()
key = $(this).data("key")
$("#medication_#{key}_mo_1").val(parseInt(mo / 10))
$("#medication_#{key}_mo_2").val(mo % 10)
$("#medication_#{key}_dy_1").val(parseInt(dy / 10))
$("#medication_#{key}_dy_2").val(dy % 10)
$("#medication_#{key}_yr_1").val(parseInt(yr / 1000))
$("#medication_#{key}_yr_2").val((parseInt(yr / 100)) % 10)
$("#medication_#{key}_yr_3").val((parseInt(yr / 10)) % 10)
$("#medication_#{key}_yr_4").val(yr % 10)
false
)
.on("click", "[data-object~=fuzzy-date-clear]", ->
key = $(this).data("key")
$("#medication_#{key}_mo_1").val("")
$("#medication_#{key}_mo_2").val("")
$("#medication_#{key}_dy_1").val("")
$("#medication_#{key}_dy_2").val("")
$("#medication_#{key}_yr_1").val("")
$("#medication_#{key}_yr_2").val("")
$("#medication_#{key}_yr_3").val("")
$("#medication_#{key}_yr_4").val("")
false
)
4 changes: 2 additions & 2 deletions app/views/medications/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
.form-group.row
= form.label :start_date, "Start date", class: "col-md-2 col-form-label"
.col-md-10
= render "medications/fuzzy_date_form_control", form: form, object: medication, key: :start_date_fuzzy, key_name: "Start date"
= render "medications/fuzzy_date_form_control", form: form, object: medication, key: :start_date_fuzzy, key_name: "Start date", inline_buttons: true

.form-group.row
= form.label :stop_date, "Stop date", class: "col-md-2 col-form-label"
.col-md-10
= render "medications/fuzzy_date_form_control", form: form, object: medication, key: :stop_date_fuzzy, key_name: "Stop date"
= render "medications/fuzzy_date_form_control", form: form, object: medication, key: :stop_date_fuzzy, key_name: "Stop date", inline_buttons: true

= render "forms/horizontal/submit", form: form, object: [medication.project, medication.subject, medication]
26 changes: 25 additions & 1 deletion app/views/medications/_fuzzy_date_form_control.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
%div
%div{ style: "position: relative;" }
- unless inline_buttons
.d-none.d-md-block{ style: "position: absolute;right: 0; top: 0;" }
.d-block.d-lg-inline-block.ml-lg-3
= link_to "#", tabindex: "-1", class: "btn btn-sm btn-light", data: { object: "fuzzy-date-today", key: key } do
= icon("fas", "calendar-alt")
today
.d-block.d-lg-inline-block.ml-lg-1
= link_to "#", tabindex: "-1", class: "btn btn-sm btn-light", data: { object: "fuzzy-date-clear", key: key } do
= icon("fas", "calendar-times")
clear

= form.hidden_field :"#{key}_edit", value: "1"
= form.text_field :"#{key}_mo_1", maxlength: 1, size: 1, placeholder: "M", class: "fuzzy-date-control #{"border-danger" if object.errors[:"#{key}_mo"].present?}", data: { object: "fuzzy-date" }, pattern: "[0-9]{1}", autocomplete: "off", autofocus: defined?(autofocus) ? autofocus : nil
= form.text_field :"#{key}_mo_2", maxlength: 1, size: 1, placeholder: "M", class: "fuzzy-date-control #{"border-danger" if object.errors[:"#{key}_mo"].present?}", data: { object: "fuzzy-date" }, pattern: "[0-9]{1}", autocomplete: "off"
Expand All @@ -10,9 +21,22 @@
= form.text_field :"#{key}_yr_2", maxlength: 1, size: 1, placeholder: "Y", class: "fuzzy-date-control #{"border-danger" if object.errors[:"#{key}_yr"].present?}", data: { object: "fuzzy-date" }, pattern: "[0-9]{1}", autocomplete: "off"
= form.text_field :"#{key}_yr_3", maxlength: 1, size: 1, placeholder: "Y", class: "fuzzy-date-control #{"border-danger" if object.errors[:"#{key}_yr"].present?}", data: { object: "fuzzy-date" }, pattern: "[0-9]{1}", autocomplete: "off"
= form.text_field :"#{key}_yr_4", maxlength: 1, size: 1, placeholder: "Y", class: "fuzzy-date-control #{"border-danger" if object.errors[:"#{key}_yr"].present?}", data: { object: "fuzzy-date" }, pattern: "[0-9]{1}", autocomplete: "off"

- if inline_buttons
.d-inline-block.ml-3
= link_to "#", tabindex: "-1", class: "btn btn-sm btn-light", data: { object: "fuzzy-date-today", key: key } do
= icon("fas", "calendar-alt")
.d-none.d-sm-inline today
.d-inline-block.ml-1
= link_to "#", tabindex: "-1", class: "btn btn-sm btn-light", data: { object: "fuzzy-date-clear", key: key } do
= icon("fas", "calendar-times")
.d-none.d-sm-inline clear

- if object.errors[key].present?
%small.text-danger
= succeed "." do
= object.errors[key].collect { |e| "#{defined?(key_name) ? key_name : key.to_s.humanize} #{e}" }.join(", ")
- if object.errors[key].include?("can't have blank fields")
%small.text-danger Enter 99 for unknown values.
- else
%small.text-muted Enter 99 for unknown values.
2 changes: 1 addition & 1 deletion app/views/medications/change_occurred.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
.dashboard-container
.text-center{ style: "font-size: 1.5rem;" }
= form_with model: @medication, url: submit_change_occurred_project_subject_medication_path(@project, @subject, @medication), method: :post, local: true do |form|
= render "medications/fuzzy_date_form_control", form: form, object: @medication, key: :start_date_fuzzy, key_name: "Change date"
= render "medications/fuzzy_date_form_control", form: form, object: @medication, key: :start_date_fuzzy, key_name: "Change date", inline_buttons: false
= render "forms/vertical/submit", form: form, object: @medication, cancel: false, submit_text: "Submit change and continue review"
2 changes: 1 addition & 1 deletion app/views/medications/stopped_completely.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
.dashboard-container
.text-center{ style: "font-size: 1.5rem;" }
= form_with model: @medication, url: submit_stopped_completely_project_subject_medication_path(@project, @subject, @medication), method: :post, local: true do |form|
= render "medications/fuzzy_date_form_control", form: form, object: @medication, key: :stop_date_fuzzy, key_name: "Stop date"
= render "medications/fuzzy_date_form_control", form: form, object: @medication, key: :stop_date_fuzzy, key_name: "Stop date", inline_buttons: false
= render "forms/vertical/submit", form: form, object: @medication, cancel: false, submit_text: "Submit change and continue review"

0 comments on commit ee0437f

Please sign in to comment.