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

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

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

Loading…
Cancel
Save