Merge pull request #76 from mlorb/ml_sci_286

fixes notifications when creating new sample type or group [SCI-286]
This commit is contained in:
mlorb 2016-08-22 08:54:28 +02:00 committed by GitHub
commit 0832466d20
4 changed files with 43 additions and 12 deletions

View file

@ -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
*/

View file

@ -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 = '<div class="alert alert-success alert-dismissable alert-floating">' +
'<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);
$('#content-wrapper').addClass('alert-shown');
}
function initTutorial() {
var currentStep = parseInt(Cookies.get('current_tutorial_step'), 10);
if (currentStep == 8)

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