fixes notifications when creating sample types and groups

This commit is contained in:
Mojca Lorber 2016-08-18 16:05:15 +02:00
parent 58930f3456
commit 5695842fe3
4 changed files with 36 additions and 7 deletions

View file

@ -45,6 +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);
});
$("form#new_sample_type").on("ajax:error", function(e, data, status, xhr) {
@ -73,6 +74,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);
});
$("form#new_sample_group").on("ajax:error", function(e, data, status, xhr) {
@ -141,6 +143,17 @@ function updateSamplesTypesandGroups() {
});
}
function sampleAlertMsg(message) {
var html_snippet = '<div class="alert alert-success alert-dismissable samples-flash-alert ">' +
'<div class="container">' +
'<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' +
'<span class="glyphicon glyphicon-ok-sign"></span>' +
'<span>'+ message +'</span>' +
'</div>' +
'</div>';
$('#notifications').html(html_snippet);
}
function initTutorial() {
var currentStep = parseInt(Cookies.get('current_tutorial_step'), 10);
if (currentStep == 8)

View file

@ -16,4 +16,10 @@
.alert {
position: inherit !important;
}
}
.samples-flash-alert {
position: relative;
top: 50px;
z-index: 1000;
}

View file

@ -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
}

View file

@ -17,14 +17,19 @@ 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
)
# 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
}