Skip to content
Snippets Groups Projects
Commit 9fabd459 authored by Iryna Lagno's avatar Iryna Lagno
Browse files

MAGETWO-39509: Success/Error messages processing

parent 12bbd395
No related merge requests found
......@@ -24,15 +24,15 @@ define(
return function (isApplied, isLoading) {
var quoteId = quote.getQuoteId();
var url = urlManager.getCancelCouponUrl(quoteId);
var message = $t('Your coupon was successfully removed');
messageList.clear();
return storage.delete(
url,
false
).done(
function (response) {
isLoading(false);
var deferred = $.Deferred();
isLoading(false);
getTotalsAction([], deferred);
$.when(deferred).done(function() {
isApplied(false);
......@@ -40,6 +40,7 @@ define(
paymentService.getAvailablePaymentMethods()
);
});
messageList.addSuccessMessage({'message': message});
}
).fail(
function (response) {
......
......@@ -17,14 +17,15 @@ define(
'Magento_Checkout/js/model/error-processor',
'Magento_Ui/js/model/messageList',
'mage/storage',
'Magento_Checkout/js/action/get-totals'
'Magento_Checkout/js/action/get-totals',
'mage/translate'
],
function (ko, $, quote, urlManager, paymentService, errorProcessor, messageList, storage, getTotalsAction) {
function (ko, $, quote, urlManager, paymentService, errorProcessor, messageList, storage, getTotalsAction, $t) {
'use strict';
return function (couponCode, isApplied, isLoading) {
var quoteId = quote.getQuoteId();
var url = urlManager.getApplyCouponUrl(couponCode, quoteId);
messageList.clear();
var message = $t('Your coupon was successfully applied');
return storage.put(
url,
{},
......@@ -32,16 +33,16 @@ define(
).done(
function (response) {
if (response) {
var deferred = $.Deferred();
isLoading(false);
isApplied(true);
var deferred = $.Deferred();
getTotalsAction([], deferred);
$.when(deferred).done(function() {
paymentService.setPaymentMethods(
paymentService.getAvailablePaymentMethods()
);
});
messageList.addSuccessMessage({'message': message});
}
}
).fail(
......
......@@ -2,7 +2,14 @@
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
define(['uiComponent', '../model/messageList'], function (Component, messages) {
define(
[
'ko',
'jquery',
'uiComponent',
'../model/messageList'
],
function (ko, $, Component, messages) {
'use strict';
return Component.extend({
......@@ -12,13 +19,26 @@ define(['uiComponent', '../model/messageList'], function (Component, messages) {
defaults: {
template: 'Magento_Ui/messages'
},
isHidden: ko.observable(false),
initialize: function () {
this._super();
var self = this;
this.isHidden.subscribe(function () {
if (self.isHidden()) {
setTimeout(function () {
$('#message').hide('blind', {}, 500)
}, 5000);
}
});
},
/**
*
* @returns {*}
*/
isVisible: function () {
return this.errorList().length || this.successList().length;
return this.isHidden(this.errorList().length || this.successList().length);
},
/**
* Remove all errors
......
......@@ -4,7 +4,7 @@
* See COPYING.txt for license details.
*/
-->
<div class="messages" data-bind="visible: isVisible(), click: removeAll">
<div id="message" class="messages" data-bind="visible: isVisible(), click: removeAll">
<!-- ko foreach: errorList -->
<div class="message message-error error">
<div data-ui-id="checkout-cart-validationmessages-message-error" data-bind="text: $data"></div>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment