All files / web/bundles/pimui/js init-layout.js

52.46% Statements 32/61
22.22% Branches 4/18
40% Functions 6/15
52.46% Lines 32/61

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152    1183x               1183x 1183x             1183x             1183x 1183x 1183x   1183x 3725x 3725x 3725x       1183x 3725x   3725x 3725x   3725x         3725x     1183x 1183x                 1183x 3725x 3725x     1183x 1183x                     1183x               1183x   1183x         1183x 5x 5x 5x             1183x                                                                                                  
'use strict';
 
define(['jquery', 'backbone', 'underscore', 'pim/router', 'oro/translator', 'oro/app', 'oro/mediator', 'oro/layout',
        'pim/dialog', 'oro/messenger', 'bootstrap', 'jquery-setup'
], function ($, Backbone, _, router, __, app, mediator, layout, Dialog, messenger) {
 
 
    /* ============================================================
     * from layout.js
     * ============================================================ */
    return function () {
        mediator.once('tab:changed', function () {
            setTimeout(function () {
                // emulates 'document ready state' for selenium tests
                document['page-rendered'] = true;
                mediator.trigger('page-rendered');
            }, 50);
        });
        layout.init();
 
        /* ============================================================
         * from height_fix.js
         * ============================================================ */
 
        /* dynamic height for central column */
        var debugBar = $('.sf-toolbar');
        var anchor = $('#bottom-anchor');
        var content = false;
 
        var initializeContent = function () {
            Eif (!content) {
                content = $('.scrollable-container').filter(':parents(.ui-widget)');
                content.css('overflow', 'auto');
            }
        };
 
        var adjustHeight = function () {
            initializeContent();
 
            var debugBarHeight = debugBar.length && debugBar.is(':visible') ? debugBar.height() : 0;
            var anchorTop = anchor.position().top;
 
            $(content.get().reverse()).each(function (pos, el) {
                el = $(el);
                el.height(anchorTop - el.position().top - debugBarHeight);
            });
 
            layout.adjustScrollspy();
        };
 
        var tries = 0;
        var waitForDebugBar = function () {
            if (debugBar.children().length) {
                window.setTimeout(adjustHeight, 500);
            } else if (tries < 100) {
                tries += 1;
                window.setTimeout(waitForDebugBar, 500);
            }
        };
 
        var adjustReloaded = function () {
            content = false;
            adjustHeight();
        };
 
        Eif (!anchor.length) {
            anchor = $('<div id="bottom-anchor"/>')
                .css({
                    position: 'fixed',
                    bottom: '0',
                    left: '0',
                    width: '1px',
                    height: '1px'
                })
                .appendTo($(document.body));
        }
 
        mediator.once('page-rendered', function () {
            if (debugBar.length) {
                waitForDebugBar();
            } else {
                adjustHeight();
            }
        });
 
        $(window).on('resize', adjustHeight);
 
        mediator.bind('route_complete', adjustReloaded);
 
        /* ============================================================
         * from form_buttons.js
         * ============================================================ */
        $(document).on('click', '.action-button', function () {
            var actionInput = $('input[name = "input_action"]');
            actionInput.val($(this).attr('data-action'));
            $('#' + actionInput.attr('data-form-id')).submit();
        });
 
        /* ============================================================
         * from remove.confirm.js
         * ============================================================ */
 
        $(document).on('click', '.remove-button', function () {
            var el = $(this);
            var message = el.data('message');
            const subTitle = el.data('subtitle');
 
            const doDelete = function () {
                router.showLoadingMask();
 
                $.ajax({
                    url: el.data('url'),
                    type: 'DELETE',
                    success: function () {
                        el.trigger('removesuccess');
                        messenger.enqueueMessage(
                            'success',
                            el.data('success-message'),
                            { 'hashNavEnabled': true }
                        );
                        if (el.data('redirect')) {
                            $.isActive(true);
                            Backbone.history.navigate('#' + el.data('redirect'));
                        } else {
                            router.hideLoadingMask();
                        }
                    },
                    error: function () {
                        router.hideLoadingMask();
 
                        messenger.notify(
                            'error',
                            el.data('error-message') ||
                                __('Unexpected error occurred. Please contact system administrator.'),
                            { flash: false }
                        );
                    }
                });
            };
 
            this.confirmModal = Dialog.confirmDelete(
                message,
                __('pim_common.confirm_deletion'),
                doDelete,
                subTitle
            );
 
            return false;
        });
    };
});