From da4b55ceea29a8cc5cef05939f9a77d520f23181 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Thu, 19 Mar 2020 19:43:20 +0100 Subject: [PATCH] Fix protocol and report create modals after dashboard redirect --- app/assets/javascripts/dashboard/quick_start.js | 14 ++++++++++++++ app/assets/javascripts/protocols/index.js | 6 +++++- .../javascripts/reports/reports_datatable.js.erb | 6 +++++- app/views/dashboards/_quick_start.html.erb | 4 ++-- app/views/protocols/index.html.erb | 2 +- app/views/reports/index.html.erb | 2 +- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/dashboard/quick_start.js b/app/assets/javascripts/dashboard/quick_start.js index 809c3d72c..25d1b3c82 100644 --- a/app/assets/javascripts/dashboard/quick_start.js +++ b/app/assets/javascripts/dashboard/quick_start.js @@ -7,6 +7,18 @@ var DasboardQuickStartWidget = (function() { var createTaskButton = '#create-task-modal .create-task-button'; var newProjectsVisibility = '#create-task-modal .new-projects-visibility'; + function initNewReportLink() { + $('.quick-start-widget .new-report').click(() => { + sessionStorage.setItem('scinote-dashboard-new-report', Math.floor(Date.now() / 1000)); + }); + } + + function initNewProtocolLink() { + $('.quick-start-widget .new-protocol').click(() => { + sessionStorage.setItem('scinote-dashboard-new-protocol', Math.floor(Date.now() / 1000)); + }); + } + function initNewTaskModal() { $('.quick-start-widget .new-task').click(() => { $('#create-task-modal').modal('show'); @@ -108,6 +120,8 @@ var DasboardQuickStartWidget = (function() { init: () => { if ($('.quick-start-widget').length) { initNewTaskModal(); + initNewProtocolLink(); + initNewReportLink(); } } }; diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index 944bfd691..b9acb7b5d 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -300,6 +300,7 @@ function initCreateNewModal() { var link = $("[data-action='create-new']"); var modal = $("#create-new-modal"); var submitBtn = modal.find(".modal-footer [data-action='submit']"); + var newProtocol = parseInt(sessionStorage.getItem('scinote-dashboard-new-protocol'), 10); link.on("click", function() { $.ajax({ @@ -329,7 +330,10 @@ function initCreateNewModal() { }); }); - if ($('#protocols-index').data('new-protocol')) link.click(); + if (Math.floor(Date.now() / 1000) - newProtocol < 15) { + link.click(); + sessionStorage.removeItem('scinote-dashboard-new-protocol'); + } submitBtn.on("click", function() { // Submit the form inside modal diff --git a/app/assets/javascripts/reports/reports_datatable.js.erb b/app/assets/javascripts/reports/reports_datatable.js.erb index 467685de5..92901cdb6 100644 --- a/app/assets/javascripts/reports/reports_datatable.js.erb +++ b/app/assets/javascripts/reports/reports_datatable.js.erb @@ -181,13 +181,17 @@ } function initNewReportModal() { + var newReport = parseInt(sessionStorage.getItem('scinote-dashboard-new-report'), 10); $('#new-report-btn').on('click', function() { $('#new-report-modal').modal('show'); initSelectPicker(); initRedirectToNewReportPage(); }); - if ($('#content-reports-index').data('new-report')) $('#new-report-btn').click(); + if (Math.floor(Date.now() / 1000) - newReport < 15) { + $('#new-report-btn').click(); + sessionStorage.removeItem('scinote-dashboard-new-report'); + } } initDatatable(); diff --git a/app/views/dashboards/_quick_start.html.erb b/app/views/dashboards/_quick_start.html.erb index 6d0299a69..6e321adb1 100644 --- a/app/views/dashboards/_quick_start.html.erb +++ b/app/views/dashboards/_quick_start.html.erb @@ -15,10 +15,10 @@ <%= t("dashboard.quick_start.description") %>
<%= t("dashboard.quick_start.new_task") %>
- <%= link_to protocols_path(new_protocol: true), {class: "new-protocol btn btn-secondary btn-block"} do %> + <%= link_to protocols_path, {class: "new-protocol btn btn-secondary btn-block"} do %> <%= t("dashboard.quick_start.new_protocol") %> <% end %> - <%= link_to reports_path(new_report: true), {class: "new-report btn btn-secondary btn-block"} do %> + <%= link_to reports_path, {class: "new-report btn btn-secondary btn-block"} do %> <%= t("dashboard.quick_start.new_report") %> <% end %> <% end %> diff --git a/app/views/protocols/index.html.erb b/app/views/protocols/index.html.erb index 571bf24b3..f405e3d09 100644 --- a/app/views/protocols/index.html.erb +++ b/app/views/protocols/index.html.erb @@ -5,7 +5,7 @@ <% provide(:head_title, t("protocols.index.head_title")) %> <% if current_team %> -
> +