mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-11 01:44:34 +08:00
Move flash message creation JS code to helper method [SCI-1087]
This commit is contained in:
parent
2a33391f4b
commit
c715902058
3 changed files with 39 additions and 31 deletions
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue