all files / spreadsheet/services/ dialog.js

97.92% Statements 47/48
100% Branches 24/24
88.89% Functions 8/9
97.92% Lines 47/48
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   1050×   540× 540× 540× 540× 540× 540×             540× 547× 535× 535× 28× 28× 27×         540× 466× 448× 170×     540× 540× 353× 353×         540× 540× 540× 540× 540× 540× 512×     466× 448× 448×   454× 426× 117× 117×   426×              
define(["require", "exports", "@syncfusion/ej2-popups", "@syncfusion/ej2-base", "../common/index"], function (require, exports, ej2_popups_1, ej2_base_1, index_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Dialog = (function () {
        function Dialog(parent) {
            this.parent = parent;
        }
        Dialog.prototype.show = function (dialogModel, cancelBtn) {
            var _this = this;
            var btnContent;
            cancelBtn = ej2_base_1.isNullOrUndefined(cancelBtn) ? true : false;
            var beforeOpenHandler = dialogModel.beforeOpen || null;
            var closeHandler = dialogModel.close || null;
            var model = {
                header: 'Spreadsheet',
                cssClass: this.parent.cssClass,
                target: this.parent.element,
                buttons: [],
                allowDragging: true
            };
            dialogModel.beforeOpen = function (args) {
                if (beforeOpenHandler) {
                    beforeOpenHandler(args);
                    if (args.cancel) {
                        _this.hide(true);
                        if (!args.preventFocus) {
                            index_1.focus(_this.parent.element);
                        }
                    }
                }
            };
            dialogModel.close = function () {
                _this.destroyDialog();
                if (closeHandler) {
                    closeHandler();
                }
            };
            ej2_base_1.extend(model, dialogModel);
            if (cancelBtn) {
                btnContent = this.parent.serviceLocator.getService(index_1.locale).getConstant(model.buttons.length ? 'Cancel' : 'Ok');
                model.buttons.push({
                    buttonModel: { content: btnContent, isPrimary: model.buttons.length === 0 },
                    click: this.hide.bind(this)
                });
            }
            var div = this.parent.createElement('div');
            document.body.appendChild(div);
            this.dialogInstance = new ej2_popups_1.Dialog(model);
            this.dialogInstance.createElement = this.parent.createElement;
            this.dialogInstance.appendTo(div);
            if (this.dialogInstance) {
                this.dialogInstance.refreshPosition();
            }
        };
        Dialog.prototype.destroyDialog = function () {
            this.dialogInstance.destroy();
            ej2_base_1.remove(this.dialogInstance.element);
            this.dialogInstance = null;
        };
        Dialog.prototype.hide = function (disableAnimation) {
            if (this.dialogInstance) {
                if (disableAnimation) {
                    this.dialogInstance.animationSettings.effect = 'None';
                    this.dialogInstance.dataBind();
                }
                this.dialogInstance.hide();
            }
        };
        Dialog.prototype.destroy = function () {
            this.parent = null;
        };
        return Dialog;
    }());
    exports.Dialog = Dialog;
});