diff --git a/app/assets/javascripts/samples/sample_datatable.js b/app/assets/javascripts/samples/sample_datatable.js index dc5c18d96..985c3b6c5 100644 --- a/app/assets/javascripts/samples/sample_datatable.js +++ b/app/assets/javascripts/samples/sample_datatable.js @@ -336,7 +336,7 @@ function onClickEdit() { }, error: function (e, data, status, xhr) { if (e.status == 403) { - showAlertMessage(I18n.t("samples.js.permission_error")); + sampleAlertMsg(I18n.t("samples.js.permission_error"), "danger"); changeToViewMode(); updateButtons(); } @@ -398,19 +398,21 @@ function onClickSave() { dataType: "json", data: data, success: function (data) { + sampleAlertMsg(data.flash, "success"); onClickCancel(); }, error: function (e, eData, status, xhr) { var data = e.responseJSON; clearAllErrors(); + sampleAlertMsgHide(); if (e.status == 404) { - showAlertMessage(I18n.t("samples.js.not_found_error")); + sampleAlertMsg(I18n.t("samples.js.not_found_error"), "danger"); changeToViewMode(); updateButtons(); } else if (e.status == 403) { - showAlertMessage(I18n.t("samples.js.permission_error")); + sampleAlertMsg(I18n.t("samples.js.permission_error"), "danger"); changeToViewMode(); updateButtons(); } @@ -610,7 +612,7 @@ function onClickAddSample() { }, error: function (e, eData, status, xhr) { if (e.status == 403) - showAlertMessage(I18n.t("samples.js.permission_error")); + sampleAlertMsg(I18n.t("samples.js.permission_error"), "danger"); changeToViewMode(); updateButtons(); } @@ -704,10 +706,4 @@ function changeToEditMode() { // Table specific stuff table.button(0).enable(false); -} - -// Shows alert and changes -function showAlertMessage(msg) { - $("#alert-container").append("
Error! " + msg + "
"); -} - +} \ No newline at end of file diff --git a/app/assets/javascripts/samples/samples.js b/app/assets/javascripts/samples/samples.js index 625bc795e..f60928d08 100644 --- a/app/assets/javascripts/samples/samples.js +++ b/app/assets/javascripts/samples/samples.js @@ -45,7 +45,7 @@ $("#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); + sampleAlertMsg(data.flash, "success"); currentMode = "viewMode"; updateButtons(); }); @@ -76,7 +76,7 @@ $("#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); + sampleAlertMsg(data.flash, "success"); currentMode = "viewMode"; updateButtons(); }); @@ -147,18 +147,31 @@ function updateSamplesTypesandGroups() { }); } -function sampleAlertMsg(message) { - var html_snippet = '
' + +function sampleAlertMsg(message, type) { + var alertType, glyphSign; + if (type == 'success') { + alertType = ' alert-success '; + glyphSign = ' glyphicon-ok-sign '; + } else if (type == 'danger') { + alertType = ' alert-danger '; + glyphSign = ' glyphicon-exclamation-sign '; + } + var htmlSnippet = '
' + '
' + '' + - '' + + '' + ''+ message +'' + '
' + '
'; - $('#notifications').html(html_snippet); + $('#notifications').html(htmlSnippet); $('#content-wrapper').addClass('alert-shown'); } +function sampleAlertMsgHide() { + $('#notifications').html('
'); + $('#content-wrapper').removeClass('alert-shown'); +} + function initTutorial() { var currentStep = parseInt(Cookies.get('current_tutorial_step'), 10); if (currentStep == 8) diff --git a/app/controllers/samples_controller.rb b/app/controllers/samples_controller.rb index e20b081b8..5622d9572 100644 --- a/app/controllers/samples_controller.rb +++ b/app/controllers/samples_controller.rb @@ -80,7 +80,17 @@ class SamplesController < ApplicationController errors.delete_if { |k, v| v.blank? } if errors.empty? - format.json { render json: {}, status: :ok } + format.json do + render json: { + id: sample.id, + flash: t( + 'samples.create.success_flash', + sample: sample.name, + organization: @organization.name + ) + }, + status: :ok + end else format.json { render json: errors, status: :bad_request } end @@ -227,7 +237,17 @@ class SamplesController < ApplicationController # Now we can destroy empty scfs scf_to_delete.map(&:destroy) - format.json { render json: {}, status: :ok } + format.json do + render json: { + id: sample.id, + flash: t( + 'samples.update.success_flash', + sample: sample.name, + organization: @organization.name + ) + }, + status: :ok + end else format.json { render json: errors, status: :bad_request } end diff --git a/config/locales/en.yml b/config/locales/en.yml index b6db4dc51..09a2f255e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -909,7 +909,7 @@ en: create: "Edit sample" scf_does_not_exist: "This field does not exists." create: - success_flash: "Successfully added sample to team %{organization}" + success_flash: "Successfully added sample %{sample} to team %{organization}" update: success_flash: "Successfully updated sample %{sample} to team %{organization}" destroy: