Browse Source

Add succes and error message for annotation and doctrines

pull/111/head
janpaulo 4 years ago
parent
commit
1321cca174
No known key found for this signature in database
GPG Key ID: 50CA753050F1541C
  1. 12
      app/javascript/controllers/annotations_controller.js
  2. 19
      app/javascript/controllers/doctrines_controller.js
  3. 8
      app/views/layouts/application.html.erb

12
app/javascript/controllers/annotations_controller.js

@ -81,13 +81,23 @@ export default class extends ApplicationController {
type: 'PUT', type: 'PUT',
data: params, data: params,
success: function() { success: function() {
$(".btn-close-x").trigger("click")
$('.toast').addClass('bg-success').show()
$( ".toast-body" ).html( "<span><b>Submitted Successfully</b></span>" ),
location.pathname = "/documents/" + current_document_id + "/doctrines/" + doctrine_id location.pathname = "/documents/" + current_document_id + "/doctrines/" + doctrine_id
},
error: function() {
$(".btn-close-x").trigger("click"),
$('.toast').addClass('bg-danger').show(),
$( ".toast-body" ).html( "<span><b>Unexpected Error Problem Occurred</b></span>" )
} }
}) })
} else { } else {
$.post("/api/doctrines/" + doctrine_id + "/annotations", params, function(result, status) { $.post("/api/doctrines/" + doctrine_id + "/annotations", params, function(result, status) {
if(status === "success") { if(status === "success") {
$(".btn-close-x").trigger("click") $(".btn-close-x").trigger("click")
$('.toast').addClass('bg-success').show()
$( ".toast-body" ).html( "<span><b>Submitted Successfully</b></span>" ),
location.pathname = "/documents/" + current_document_id + "/doctrines/" + doctrine_id 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, url: "/api/doctrines/" + doctrine_id + "/annotations/" + annotation_id,
type: 'DELETE', type: 'DELETE',
success: function() { success: function() {
$('.toast').addClass('bg-danger').show()
$( ".toast-body" ).html( "<span><b>Deleted Successfully</b></span>" )
location.pathname = "/documents/" + current_document_id + "/doctrines/" + doctrine_id location.pathname = "/documents/" + current_document_id + "/doctrines/" + doctrine_id
} }
}) })

19
app/javascript/controllers/doctrines_controller.js

@ -73,15 +73,30 @@ export default class extends ApplicationController {
type: 'PUT', type: 'PUT',
data: params, data: params,
success: function() { success: function() {
$(".btn-close-x").trigger("click")
$('.toast').addClass('bg-success').show()
$( ".toast-body" ).html( "<span><b>Submitted Successfully</b></span>" ),
location.pathname = "/documents/" + document_id + "/doctrines/" + doctrine_id location.pathname = "/documents/" + document_id + "/doctrines/" + doctrine_id
},
error: function() {
$(".btn-close-x").trigger("click"),
$('.toast').addClass('bg-danger').show(),
$( ".toast-body" ).html( "<span><b>Unexpected Error Problem Occurred</b></span>" )
} }
}) })
} else { } else {
$.post("/api/doctrines", $.extend({ jurisprudence_ids: [document_id] }, params), function(data, status) { $.post("/api/doctrines", $.extend({ jurisprudence_ids: [document_id] }, params), function(data, status) {
if(status === 'success') { if(status === 'success') {
$(".btn-close-x").trigger("click")
$('.toast').addClass('bg-success').show()
$( ".toast-body" ).html( "<span><b>Submitted Successfully</b></span>" ),
location.pathname = "/documents/" + document_id + "/doctrines/" + data.id location.pathname = "/documents/" + document_id + "/doctrines/" + data.id
} }
}) },
$(".btn-close-x").trigger("click"),
$('.toast').addClass('bg-danger').show(),
$( ".toast-body" ).html( "<span><b>Unexpected Error Problem Occurred</b></span>" )
)
} }
} }
} }
@ -97,6 +112,8 @@ export default class extends ApplicationController {
type: 'DELETE', type: 'DELETE',
success: function() { success: function() {
location.pathname = "/documents/" + document_id location.pathname = "/documents/" + document_id
$('.toast').addClass('bg-danger').show()
$( ".toast-body" ).html( "<span><b>Deleted Successfully</b></span>" );
} }
}) })
} }

8
app/views/layouts/application.html.erb

@ -70,5 +70,13 @@
</div> </div>
</div> </div>
</div> </div>
<div class="toast align-items-center text-white border-0" data-bs-autohide="true" role="alert" aria-live="assertive" aria-atomic="true" style="position: absolute;bottom: 20px;right: 10px;">
<div class="d-flex">
<div class="toast-body">
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" id="toast-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
</body> </body>
</html> </html>

Loading…
Cancel
Save