mirror of
https://github.com/Febbweiss/CloudBudget-AngularJS.git
synced 2026-03-04 22:35:38 +00:00
First commit
This commit is contained in:
53
public/js/services/flash.service.js
Normal file
53
public/js/services/flash.service.js
Normal file
@@ -0,0 +1,53 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
angular
|
||||
.module('cloudbudget')
|
||||
.factory('FlashService', FlashService);
|
||||
|
||||
FlashService.$inject = ['$rootScope'];
|
||||
|
||||
function FlashService($rootScope) {
|
||||
var service = {};
|
||||
|
||||
service.success = success;
|
||||
service.error = error;
|
||||
|
||||
initService();
|
||||
|
||||
return service;
|
||||
|
||||
function initService() {
|
||||
$rootScope.$on('$locationChangeStart', function() {
|
||||
clearFlashMessage();
|
||||
});
|
||||
|
||||
function clearFlashMessage() {
|
||||
var flash = $rootScope.flash;
|
||||
if( flash ) {
|
||||
if( !flash.keepAfterLocationChange ) {
|
||||
delete $rootScope.flash;
|
||||
} else {
|
||||
flash.keepAfterLocationChange = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function success(message, keepAfterLocationChange) {
|
||||
$rootScope.flash = {
|
||||
message: message,
|
||||
type: 'success',
|
||||
keepAfterLocationChange: keepAfterLocationChange
|
||||
};
|
||||
}
|
||||
|
||||
function error(message, keepAfterLocationChange) {
|
||||
$rootScope.flash = {
|
||||
message: message,
|
||||
type: 'error',
|
||||
keepAfterLocationChange: keepAfterLocationChange
|
||||
};
|
||||
}
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user