From 1321cca174fa3f1163ed4db09b8ee19b5fd9e433 Mon Sep 17 00:00:00 2001 From: janpaulo Date: Tue, 8 Mar 2022 07:21:09 +0800 Subject: [PATCH 1/2] Add succes and error message for annotation and doctrines --- .../controllers/annotations_controller.js | 12 ++++++++++++ .../controllers/doctrines_controller.js | 19 ++++++++++++++++++- app/views/layouts/application.html.erb | 8 ++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/app/javascript/controllers/annotations_controller.js b/app/javascript/controllers/annotations_controller.js index 7129d6f..f98452b 100644 --- a/app/javascript/controllers/annotations_controller.js +++ b/app/javascript/controllers/annotations_controller.js @@ -81,13 +81,23 @@ export default class extends ApplicationController { type: 'PUT', data: params, success: function() { + $(".btn-close-x").trigger("click") + $('.toast').addClass('bg-success').show() + $( ".toast-body" ).html( "Submitted Successfully" ), location.pathname = "/documents/" + current_document_id + "/doctrines/" + doctrine_id + }, + error: function() { + $(".btn-close-x").trigger("click"), + $('.toast').addClass('bg-danger').show(), + $( ".toast-body" ).html( "Unexpected Error Problem Occurred" ) } }) } else { $.post("/api/doctrines/" + doctrine_id + "/annotations", params, function(result, status) { if(status === "success") { $(".btn-close-x").trigger("click") + $('.toast').addClass('bg-success').show() + $( ".toast-body" ).html( "Submitted Successfully" ), location.pathname = "/documents/" + current_document_id + "/doctrines/" + doctrine_id } }) @@ -105,6 +115,8 @@ export default class extends ApplicationController { url: "/api/doctrines/" + doctrine_id + "/annotations/" + annotation_id, type: 'DELETE', success: function() { + $('.toast').addClass('bg-danger').show() + $( ".toast-body" ).html( "Deleted Successfully" ) location.pathname = "/documents/" + current_document_id + "/doctrines/" + doctrine_id } }) diff --git a/app/javascript/controllers/doctrines_controller.js b/app/javascript/controllers/doctrines_controller.js index 9f5d00d..cd599bf 100644 --- a/app/javascript/controllers/doctrines_controller.js +++ b/app/javascript/controllers/doctrines_controller.js @@ -73,15 +73,30 @@ export default class extends ApplicationController { type: 'PUT', data: params, success: function() { + $(".btn-close-x").trigger("click") + $('.toast').addClass('bg-success').show() + $( ".toast-body" ).html( "Submitted Successfully" ), location.pathname = "/documents/" + document_id + "/doctrines/" + doctrine_id + }, + error: function() { + $(".btn-close-x").trigger("click"), + $('.toast').addClass('bg-danger').show(), + $( ".toast-body" ).html( "Unexpected Error Problem Occurred" ) } }) } else { $.post("/api/doctrines", $.extend({ jurisprudence_ids: [document_id] }, params), function(data, status) { if(status === 'success') { + $(".btn-close-x").trigger("click") + $('.toast').addClass('bg-success').show() + $( ".toast-body" ).html( "Submitted Successfully" ), location.pathname = "/documents/" + document_id + "/doctrines/" + data.id } - }) + }, + $(".btn-close-x").trigger("click"), + $('.toast').addClass('bg-danger').show(), + $( ".toast-body" ).html( "Unexpected Error Problem Occurred" ) + ) } } } @@ -97,6 +112,8 @@ export default class extends ApplicationController { type: 'DELETE', success: function() { location.pathname = "/documents/" + document_id + $('.toast').addClass('bg-danger').show() + $( ".toast-body" ).html( "Deleted Successfully" ); } }) } diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1df3968..0c24dab 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -70,5 +70,13 @@ + + From ba95906f5cf5d99b33cea8238bd57d4b5f68ab9e Mon Sep 17 00:00:00 2001 From: janpaulo Date: Tue, 8 Mar 2022 07:21:26 +0800 Subject: [PATCH 2/2] Fix scroll into a footnotes --- app/javascript/packs/application.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/javascript/packs/application.js b/app/javascript/packs/application.js index 20378f0..8eb4cb9 100644 --- a/app/javascript/packs/application.js +++ b/app/javascript/packs/application.js @@ -36,6 +36,10 @@ $(document).on("ready turbolinks:load", function () { $('#sidenav').toggleClass('active'); }); + $("#toast-close").click(function(){ + $('.toast').hide(); + }); + $(".spinner-border").hide(); var default_config = { altFormat: "m/d/Y", altInput: true, enableTime: false, dateFormat: "Y-m-d", isMobile: true }; @@ -58,7 +62,7 @@ $(document).on("ready turbolinks:load", function () { a = $(this), b = $(a.attr('href')) if(b.length<=0)return event.preventDefault() - $('html, body, .tab-content').animate({ scrollTop: b.offset().top }, 700, 'linear') + document.getElementById(b[0].id).scrollIntoView( {behavior: "smooth", duration: 700 }) }) });