revamp flash directive to transmit to NotificationsHelper

This is only a temporary reworking as it is now wrong to use a directive
pull/3392/head
Jens Ulferts 9 years ago
parent f935f44ca2
commit 58565e11c3
  1. 34
      frontend/app/ui_components/flash-message-directive.js
  2. 1
      frontend/app/ui_components/index.js
  3. 6
      frontend/app/work_packages/helpers/api-helper.js

@ -27,34 +27,30 @@
//++ //++
// TODO move to UI components // TODO move to UI components
module.exports = function($rootScope, $timeout, ConfigurationService) { module.exports = function($rootScope, $timeout, ConfigurationService, NotificationsService) {
return { return {
restrict: 'E', restrict: 'E',
replace: true, replace: true,
scope: {}, scope: {},
templateUrl: '/templates/components/flash_message.html', templateUrl: '/templates/components/flash_message.html',
link: function(scope, element, attrs) { link: function() {
$rootScope.$on('flashMessage', function(event, message) { $rootScope.$on('flashMessage', function(event, message) {
scope.message = message;
scope.flashType = 'notice';
scope.flashId = 'flash-notice';
var fadeOutTime = attrs.fadeOutTime || 3000;
if (message.isError) { if (message.isError) {
scope.flashType = "errorExplanation"; if (message.text.length > 1) {
scope.flashId = "errorExplanation"; NotificationsService.addError(message.text, []);
}
else {
NotificationsService.addError('', message.text);
}
} }
else {
// not using $timeout to allow capybara to not wait until timeout is done with if (message.text.length > 1) {
// scope apply NotificationsService.addSuccess(message.text, []);
if (!ConfigurationService.accessibilityModeEnabled() && !message.isPermanent) { }
setTimeout(function() { else {
scope.$apply(function() { NotificationsService.addSuccess('', message.text);
scope.message = undefined; }
});
}, fadeOutTime);
} }
}); });
} }

@ -53,6 +53,7 @@ angular.module('openproject.uiComponents')
'$rootScope', '$rootScope',
'$timeout', '$timeout',
'ConfigurationService', 'ConfigurationService',
'NotificationsService',
require('./flash-message-directive') require('./flash-message-directive')
]) ])
.directive('expandableSearch', ['ENTER_KEY', require('./expandable-search')]) .directive('expandableSearch', ['ENTER_KEY', require('./expandable-search')])

@ -41,7 +41,7 @@ module.exports = function() {
} else { } else {
var response = JSON.parse(error.responseText); var response = JSON.parse(error.responseText);
var messages = []; var messages = [];
var message; // var message;
if (ApiHelper.isMultiErrorMessage(response)) { if (ApiHelper.isMultiErrorMessage(response)) {
angular.forEach(response._embedded.errors, function(error) { angular.forEach(response._embedded.errors, function(error) {
@ -51,9 +51,9 @@ module.exports = function() {
messages.push(response.message); messages.push(response.message);
} }
message = messages.join(' '); // message = messages.join(' ');
return message; return messages;
} }
}, },

Loading…
Cancel
Save