Move flash message creation JS code to helper method [SCI-1087]

This commit is contained in:
Oleksii Kriuchykhin 2017-03-17 17:56:58 +01:00
parent 2a33391f4b
commit c715902058
3 changed files with 39 additions and 31 deletions

View file

@ -224,6 +224,32 @@ var HelperModule = (function(){
}
}
helpers.flashAlertMsg = function(message, type) {
var alertType;
var glyphSign;
$('#notifications').html('');
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 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' + glyphSign + '"></span>' +
'<span>' + message + '</span>' +
'</div>' +
'</div>';
$('#notifications').html(htmlSnippet);
$('#content-wrapper').addClass('alert-shown');
helpers.hideFlashMsg();
}
$( document ).ready(function() {
helpers.treeLinkTruncation();
helpers.hideFlashMsg();

View file

@ -503,7 +503,9 @@ function onClickEdit() {
},
error: function (e, data, status, xhr) {
if (e.status == 403) {
sampleAlertMsg(I18n.t("samples.js.permission_error"), "danger");
HelperModule.flashAlertMsg(
I18n.t('samples.js.permission_error'), 'danger'
);
changeToViewMode();
updateButtons();
}
@ -565,7 +567,7 @@ function onClickSave() {
dataType: "json",
data: data,
success: function (data) {
sampleAlertMsg(data.flash, "success");
HelperModule.flashAlertMsg(data.flash, 'success');
onClickCancel();
},
error: function (e, eData, status, xhr) {
@ -573,12 +575,16 @@ function onClickSave() {
clearAllErrors();
if (e.status == 404) {
sampleAlertMsg(I18n.t("samples.js.not_found_error"), "danger");
HelperModule.flashAlertMsg(
I18n.t('samples.js.not_found_error'), 'danger'
);
changeToViewMode();
updateButtons();
}
else if (e.status == 403) {
sampleAlertMsg(I18n.t("samples.js.permission_error"), "danger");
HelperModule.flashAlertMsg(
I18n.t('samples.js.permission_error'), 'danger'
);
changeToViewMode();
updateButtons();
}
@ -794,7 +800,9 @@ function onClickAddSample() {
},
error: function (e, eData, status, xhr) {
if (e.status == 403)
sampleAlertMsg(I18n.t("samples.js.permission_error"), "danger");
HelperModule.flashAlertMsg(
I18n.t('samples.js.permission_error'), 'danger'
);
changeToViewMode();
updateButtons();
}

View file

@ -53,32 +53,6 @@ function updateSamplesTypesandGroups() {
});
}
function sampleAlertMsg(message, type) {
var alertType;
var glyphSign;
$('#notifications').html('');
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 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' + glyphSign + '"></span>' +
'<span>' + message + '</span>' +
'</div>' +
'</div>';
$('#notifications').html(htmlSnippet);
$('#content-wrapper').addClass('alert-shown');
HelperModule.hideFlashMsg();
}
/**
* Initializes tutorial
*/