all files / integrations/ dialog.js

100% Statements 73/73
95.24% Branches 20/21
100% Functions 21/21
100% Lines 71/71
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 1371×   1× 1× 15× 15× 15× 15× 6× 6×   15× 11×     7×                                       11× 11×     4×     1× 1× 11×   1×   1× 15×     15× 15× 15×   11× 11× 11×   11×       5× 4×   5×           3×       11× 8× 8× 5×     11×   15×   1×   1× 9× 1×     1× 13× 10×   13× 13× 13×   1× 13× 33× 2× 1×     33× 1× 1×       13× 33×     1×   1× 4× 4× 4× 4× 4× 4× 4× 4× 2×   4× 4×      
define(["require", "exports", "@syncfusion/ej2-popups", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/classes", "../base/constant", "../base/utils"], function (require, exports, ej2_popups_1, ej2_base_1, ej2_base_2, CLS, constant_1, utils_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function createDialog(parent, text, e) {
        var options = getOptions(parent, text, e);
        var dialogId = parent.element.id + constant_1.DIALOG_ID;
        var dialogElement = parent.element.querySelector('#' + dialogId);
        if (!dialogElement) {
            dialogElement = ej2_base_1.createElement('div', { id: dialogId });
            parent.element.appendChild(dialogElement);
        }
        if (ej2_base_1.isNullOrUndefined(parent.dialogObj)) {
            parent.dialogObj = new ej2_popups_1.Dialog({
                beforeOpen: keydownAction.bind(this, parent, options.dialogName),
                beforeClose: function (args) {
                    triggerPopupBeforeClose(parent, parent.dialogObj, args, options.dialogName);
                },
                header: options.header,
                content: options.content,
                buttons: options.buttons,
                animationSettings: { effect: 'None' },
                showCloseIcon: true,
                closeOnEscape: true,
                visible: true,
                allowDragging: true,
                isModal: true,
                target: document.body,
                cssClass: getCssClass(parent, parent.isMobile ? CLS.MOB_POPUP : CLS.ROOT_POPUP),
                width: '350px',
                open: options.open,
                close: options.close,
                enableRtl: parent.enableRtl,
                enableHtmlSanitizer: parent.enableHtmlSanitizer,
                locale: parent.locale
            });
            parent.dialogObj.isStringTemplate = true;
            parent.dialogObj.appendTo(dialogElement);
        }
        else {
            changeOptions(parent, options);
        }
    }
    exports.createDialog = createDialog;
    function getCssClass(parent, defaultClass) {
        return parent.cssClass ? (defaultClass + ' ' + parent.cssClass) : defaultClass;
    }
    function triggerPopupBeforeClose(parent, dlgModule, args, dialogName) {
    }
    function getOptions(parent, text, e) {
        var options = {
            header: '', content: '', buttons: [], dialogName: ''
        };
        options.open = function () { triggerPopupOpen(parent, parent.dialogObj, options.dialogName); };
        options.close = function () { triggerPopupClose(parent, parent.dialogObj, options.dialogName); };
        switch (text) {
            case 'WebMcpConfirm':
                options.dialogName = 'WebMcpConfirm';
                options.header = utils_1.getLocaleText(parent, 'Header-WebMcp-Confirmation');
                options.content = '<div class="e-ribbon-webmcp-confirm-message">' +
                    e.message + '</div>';
                options.buttons = [
                    {
                        buttonModel: { isPrimary: true, content: utils_1.getLocaleText(parent, 'Button-Yes') },
                        click: function () {
                            if (typeof parent.webMcpConfirmSettle === 'function') {
                                parent.webMcpConfirmSettle(true);
                            }
                            parent.dialogObj.hide();
                        }
                    },
                    {
                        buttonModel: { content: utils_1.getLocaleText(parent, 'Button-No') },
                        click: function () {
                            parent.dialogObj.hide();
                        }
                    }
                ];
                options.close = function () {
                    triggerPopupClose(parent, parent.dialogObj, options.dialogName);
                    if (typeof parent.webMcpConfirmSettle === 'function') {
                        parent.webMcpConfirmSettle(false);
                    }
                };
                break;
        }
        return options;
    }
    function triggerPopupOpen(parent, dlgModule, dialogName) {
    }
    function triggerPopupClose(parent, dlgModule, dialogName) {
        if (dialogName !== 'WebMcpConfirm') {
            parent.restoreFocus();
        }
    }
    function keydownAction(parent, dialogName, args) {
        if (dialogName === 'WebMcpConfirm') {
            args.maxHeight = (window.innerHeight - 20) + 'px';
        }
        var btnElement = ej2_base_2.selectAll('.e-btn', parent.dialogObj.element);
        preventKeydown(btnElement);
        triggerPopupBeforeOpen(parent, parent.dialogObj, args, dialogName);
    }
    function preventKeydown(btnElement) {
        var _loop_1 = function (btnCount) {
            btnElement[btnCount].onkeydown = function (e) {
                if (e.keyCode === 13) {
                    e.preventDefault();
                }
            };
            btnElement[btnCount].onkeyup = function (e) {
                Eif (e.keyCode === 13) {
                    btnElement[btnCount].click();
                }
            };
        };
        for (var btnCount = 0; btnCount < btnElement.length; btnCount++) {
            _loop_1(btnCount);
        }
    }
    function triggerPopupBeforeOpen(parent, dlgModule, args, dialogName) {
    }
    function changeOptions(parent, options) {
        parent.dialogObj.header = options.header;
        parent.dialogObj.content = options.content;
        parent.dialogObj.buttons = options.buttons;
        parent.dialogObj.enableRtl = parent.enableRtl;
        parent.dialogObj.open = options.open;
        parent.dialogObj.close = options.close;
        parent.dialogObj.beforeOpen = keydownAction.bind(this, parent, options.dialogName);
        parent.dialogObj.beforeClose = function (args) {
            triggerPopupBeforeClose(parent, parent.dialogObj, args, options.dialogName);
        };
        parent.dialogObj.dataBind();
        parent.dialogObj.show();
    }
});