diff --git a/app/assets/javascripts/components/fuzzy_dates.coffee b/app/assets/javascripts/components/fuzzy_dates.coffee index d23f856e5..77eb69519 100644 --- a/app/assets/javascripts/components/fuzzy_dates.coffee +++ b/app/assets/javascripts/components/fuzzy_dates.coffee @@ -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 + ) diff --git a/app/views/medications/_form.html.haml b/app/views/medications/_form.html.haml index 8bf9c499b..e4a95c529 100644 --- a/app/views/medications/_form.html.haml +++ b/app/views/medications/_form.html.haml @@ -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] diff --git a/app/views/medications/_fuzzy_date_form_control.html.haml b/app/views/medications/_fuzzy_date_form_control.html.haml index 24a356966..8d8074602 100644 --- a/app/views/medications/_fuzzy_date_form_control.html.haml +++ b/app/views/medications/_fuzzy_date_form_control.html.haml @@ -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" @@ -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. diff --git a/app/views/medications/change_occurred.html.haml b/app/views/medications/change_occurred.html.haml index a309b2fad..317a54f8b 100644 --- a/app/views/medications/change_occurred.html.haml +++ b/app/views/medications/change_occurred.html.haml @@ -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" diff --git a/app/views/medications/stopped_completely.html.haml b/app/views/medications/stopped_completely.html.haml index e1f6977f2..86fe9bc98 100644 --- a/app/views/medications/stopped_completely.html.haml +++ b/app/views/medications/stopped_completely.html.haml @@ -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"