diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 8b4dcfa9a..4e9702628 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -138,11 +138,7 @@ $(document.body).ready(function () { }); }; - $("#notifications .alert").on("closed.bs.alert", function () { - $("#content-wrapper") - .addClass("alert-hidden") - .removeClass("alert-shown"); - }); + notificationAlertClose(); $('#main-menu .btn-activity') .on('ajax:before', function () { @@ -158,6 +154,18 @@ $(document.body).ready(function () { }); }); +$(document).ajaxComplete(function(){ + notificationAlertClose(); +}); + +function notificationAlertClose(){ + $("#notifications .alert").on("closed.bs.alert", function () { + $("#content-wrapper") + .addClass("alert-hidden") + .removeClass("alert-shown"); + }); +} + /* * Truncate long strings where is necessary */ diff --git a/app/assets/javascripts/samples/samples.js b/app/assets/javascripts/samples/samples.js index 0b547bf9c..9c6b82a37 100644 --- a/app/assets/javascripts/samples/samples.js +++ b/app/assets/javascripts/samples/samples.js @@ -45,6 +45,9 @@ $("#modal-create-sample-type").on("shown.bs.modal", function(event) { $("form#new_sample_type").on("ajax:success", function(ev, data, status) { $("#modal-create-sample-type").modal("hide"); updateSamplesTypesandGroups(); + sampleAlertMsg(data.flash); + currentMode = "viewMode"; + updateButtons(); }); $("form#new_sample_type").on("ajax:error", function(e, data, status, xhr) { @@ -73,6 +76,9 @@ $("#modal-create-sample-group").on("shown.bs.modal", function(event) { $("form#new_sample_group").on("ajax:success", function(ev, data, status) { $("#modal-create-sample-group").modal("hide"); updateSamplesTypesandGroups(); + sampleAlertMsg(data.flash); + currentMode = "viewMode"; + updateButtons(); }); $("form#new_sample_group").on("ajax:error", function(e, data, status, xhr) { @@ -141,6 +147,18 @@ function updateSamplesTypesandGroups() { }); } +function sampleAlertMsg(message) { + var html_snippet = '
' + + '
' + + '' + + '' + + ''+ message +'' + + '
' + + '
'; + $('#notifications').html(html_snippet); + $('#content-wrapper').addClass('alert-shown'); +} + function initTutorial() { var currentStep = parseInt(Cookies.get('current_tutorial_step'), 10); if (currentStep == 8) diff --git a/app/controllers/sample_groups_controller.rb b/app/controllers/sample_groups_controller.rb index d3a5632d8..f3319ba48 100644 --- a/app/controllers/sample_groups_controller.rb +++ b/app/controllers/sample_groups_controller.rb @@ -19,7 +19,12 @@ class SampleGroupsController < ApplicationController if @sample_group.save format.json { render json: { - id: @sample_group.id + id: @sample_group.id, + flash: t( + 'sample_groups.create.success_flash', + sample_group: @sample_group.name, + organization: @organization.name + ) }, status: :ok } diff --git a/app/controllers/sample_types_controller.rb b/app/controllers/sample_types_controller.rb index 6c6e7d6c8..783572a5c 100644 --- a/app/controllers/sample_types_controller.rb +++ b/app/controllers/sample_types_controller.rb @@ -17,14 +17,14 @@ class SampleTypesController < ApplicationController respond_to do |format| if @sample_type.save - flash[:success] = t( - "sample_types.create.success_flash", - sample_type: @sample_type.name, - organization: @organization.name - ) format.json { render json: { - id: @sample_type.id + id: @sample_type.id, + flash: t( + 'sample_types.create.success_flash', + sample_type: @sample_type.name, + organization: @organization.name + ) }, status: :ok }