0
define([
    'jquery',
    'Magento_Ui/js/modal/modal',
    'mage/cookies'
], function ($, modal) {
    'use strict';

    if(!$.cookie('popup_cookie') ) {

        $.widget('devall.popupManager', {

             /**
             *
             * @private
             */

            _create: function () {
                var self = this,
                    popup_newsletter_options = {
                        type: 'popup',
                        responsive: true,
                        innerScroll: true,
                        title: this.options.popupTitle,
                        buttons: false,
                        modalClass: 'popup-devnewsletter'
                    };
                var expDate = new Date();

                expDate.setTime(expDate.getTime() + (3650000 * 60 * 1000));
                $.cookie('popup_cookie', 1, {expires: expDate});

                modal(popup_newsletter_options, this.element);
                setTimeout(function () {
                    self._setStyleCss();
                    self.element.modal('openModal');
                }, 3000);
                this.element.find('form').submit(function () {
                    if ($(this).validation('isValid')) {
                        console.log("Hello 1!");
                        $.ajax({
                            url: $(this).attr('action'),
                            cache: true,
                            data: $(this).serialize(),
                            dataType: 'json',
                            type: 'POST',
                            showLoader: true,
                        }).done(function (data) {
                            console.log("Hello 2!");

                            self.element.find('.popup-manager .messages').html(data.message);
                            if (data.error) {
                                self.element.find('.messages .message').addClass('message-error error');
                                self.element.modal('closeModal');
                                self.element.find('.messages .message').addClass('message-success success');
                                // var cookieExpires = new Date(new Date().getTime() + this.options.cookieLifetime * 1000);

                                setTimeout(function () {
                                    self.element.modal('closeModal');
                                }, 1000);
                            }
                            self.element.find('.messages').show();

                            setTimeout(function () {
                                self.element.find('.messages').hide();
                            }, 5000);
                        }).fail(function (data) {
                            alert("Error");
                        })

                    }
                    return false;
                });


                this._resetStyleCss();
            },

            /**
             * Set width of the popup
             * @private
             */
            _setStyleCss: function (width) {

                width = width || 400;

                if (window.innerWidth > 786) {
                    this.element.parent().parent('.modal-inner-wrap').css({'max-width': width + 'px'});
                }
            },

            /**
             * Reset width of the popup
             * @private
             */
            _resetStyleCss: function () {
                var self = this;
                $(window).resize(function () {
                    if (window.innerWidth <= 786) {
                        self.element.parent().parent('.modal-inner-wrap').css({'max-width': 'initial'});
                    } else {
                        self._setStyleCss(self.options.innerWidth);
                    }
                });
            },

        });


        return $.devall.popupManager;
    }

    return 0;

});
0

action had no argument, I was calling $block->getacctionurl() instead of $viewmodel->getacctionurl();

  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review – Jai Nov 4 at 15:36
  • actually I am an author as well. – Giga Todadze Nov 5 at 8:36
  • Got that. You can add detail answer here If issue is sorted out and if this is just an update then i would suggest to edit the question. Good luck. – Jai Nov 5 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.