mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-04 19:53:19 +08:00
Merge pull request #109 from mlorb/ml_sci_286
fixes notification when adding new sample [SCI-286]
This commit is contained in:
commit
905acfd43d
4 changed files with 49 additions and 20 deletions
|
@ -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("<div class='alert alert-danger'> <strong>Error!</strong> " + msg + "</div>");
|
||||
}
|
||||
|
||||
}
|
|
@ -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 = '<div class="alert alert-success alert-dismissable alert-floating">' +
|
||||
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 = '<div class="alert' + alertType + '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 class="glyphicon' + glyphSign + '"></span>' +
|
||||
'<span>'+ message +'</span>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
$('#notifications').html(html_snippet);
|
||||
$('#notifications').html(htmlSnippet);
|
||||
$('#content-wrapper').addClass('alert-shown');
|
||||
}
|
||||
|
||||
function sampleAlertMsgHide() {
|
||||
$('#notifications').html('<div></div>');
|
||||
$('#content-wrapper').removeClass('alert-shown');
|
||||
}
|
||||
|
||||
function initTutorial() {
|
||||
var currentStep = parseInt(Cookies.get('current_tutorial_step'), 10);
|
||||
if (currentStep == 8)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 <strong>%{organization}</strong>"
|
||||
success_flash: "Successfully added sample <strong>%{sample}</strong> to team <strong>%{organization}</strong>"
|
||||
update:
|
||||
success_flash: "Successfully updated sample <strong>%{sample}</strong> to team <strong>%{organization}</strong>"
|
||||
destroy:
|
||||
|
|
Loading…
Reference in a new issue