all files / document-editor/implementation/dialogs/ content-control-popup.js

38.71% Statements 48/124
38.46% Branches 15/39
41.18% Functions 7/17
38.71% Lines 48/124
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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167   1741× 1741× 1741× 1741×       1741×         1741×     1741× 904× 904×     904×           1741×                                                                                                                                 1739×     1739× 1739× 1739× 1739×   1739×     1739×       1739×     1739×       1739×       1739×       1739×       1739×       1739×       1739×       1739×       1739× 1739× 1739× 1739× 1739× 1739× 1739×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-buttons", "@syncfusion/ej2-popups", "@syncfusion/ej2-dropdowns"], function (require, exports, ej2_base_1, ej2_buttons_1, ej2_popups_1, ej2_dropdowns_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ContentControlPopUp = (function () {
        function ContentControlPopUp(owner) {
            var _this = this;
            this.applyDropDownFormFieldValueHandler = this.onapplyDropDownFormFieldValue.bind(this);
            this.closeButtonClickedHandler = this.onCloseButtonClicked.bind(this);
            this.applyDropDownFormFieldValue = function () {
                _this.owner.editorModule.dropDownChange(_this.contenControl, _this.ddlInstance.text);
                _this.hidePopup();
            };
            this.enableDisableDatePickerOkButton = function (args) {
                if (args.isInteracted) {
                    _this.dataPickerOkButton.disabled = false;
                }
            };
            this.closeButton = function () {
                _this.hidePopup();
            };
            this.hidePopup = function () {
                _this.contenControl = undefined;
                Iif (_this.target) {
                    _this.target.style.display = 'none';
                }
                Iif (_this.popupObject) {
                    _this.popupObject.hide();
                    _this.popupObject.destroy();
                    _this.popupObject = undefined;
                }
            };
            this.owner = owner;
        }
        ContentControlPopUp.prototype.initPopup = function () {
            this.popupElement = ej2_base_1.createElement('div', { className: 'e-de-form-popup' });
            this.popupElement.appendChild(this.initDropDownList());
            this.target = this.popupElement;
            this.owner.documentHelper.viewerContainer.appendChild(this.popupElement);
        };
        ContentControlPopUp.prototype.initDropDownList = function () {
            this.dropDownDiv = ej2_base_1.createElement('div', { className: 'e-de-ddl-field' });
            var dropDownInput = ej2_base_1.createElement('input', { className: 'e-de-txt-form' });
            var ddl = new ej2_dropdowns_1.DropDownList({ fields: { text: 'value' } });
            this.dropDownInput = dropDownInput;
            this.textBoxButtonDiv = ej2_base_1.createElement('div', { className: 'e-de-cmt-action-button' });
            this.textBoxOkButton = ej2_base_1.createElement('button');
            this.textBoxCancelButton = ej2_base_1.createElement('button');
            this.textBoxOkButton.addEventListener('click', this.applyDropDownFormFieldValueHandler);
            this.textBoxCancelButton.addEventListener('click', this.closeButtonClickedHandler);
            this.dropDownDiv.appendChild(dropDownInput);
            this.textBoxButtonDiv.appendChild(this.textBoxOkButton);
            this.textBoxButtonDiv.appendChild(this.textBoxCancelButton);
            this.dropDownDiv.appendChild(this.textBoxButtonDiv);
            ddl.appendTo(dropDownInput);
            new ej2_buttons_1.Button({ cssClass: 'e-de-save e-primary', iconCss: 'e-de-save-icon' }, this.textBoxOkButton);
            new ej2_buttons_1.Button({ cssClass: 'e-de-cancel', iconCss: 'e-de-cancel-icon' }, this.textBoxCancelButton);
            this.ddlInstance = ddl;
            return this.dropDownDiv;
        };
        ContentControlPopUp.prototype.onapplyDropDownFormFieldValue = function () {
            this.applyDropDownFormFieldValue();
        };
        ContentControlPopUp.prototype.showPopUp = function (formField) {
            var _this = this;
            if (formField) {
                this.contenControl = formField;
                if (ej2_base_1.isNullOrUndefined(this.target)) {
                    this.initPopup();
                }
                ej2_base_1.classList(this.target, [], ['e-de-txt-form', 'e-de-num-form', 'e-de-date-form', 'e-de-ddl-form']);
                ej2_base_1.classList(this.target, ['e-de-ddl-form'], []);
                this.ddlInstance.refresh();
                var convertedItems = formField.contentControlProperties.contentControlListItems.map(function (item) {
                    var convertedItem = {};
                    for (var prop in item) {
                        convertedItem["" + prop] = item["" + prop];
                    }
                    return convertedItem;
                });
                this.ddlInstance.dataSource = convertedItems;
                setTimeout(function () {
                    _this.ddlInstance.showPopup();
                }, 50);
                var left = this.owner.selectionModule.getLeftInternal(formField.line, formField, 0);
                var lineHeight = formField.line.height * this.owner.documentHelper.zoomFactor;
                var position = this.owner.selectionModule.getTooltipPosition(formField.line, left, this.target, true);
                if (!this.popupObject) {
                    this.popupObject = new ej2_popups_1.Popup(this.target, {
                        height: 'auto',
                        width: 'auto',
                        relateTo: this.owner.documentHelper.viewerContainer.parentElement,
                        position: { X: position.x, Y: position.y + lineHeight }
                    });
                }
                this.target.style.display = 'block';
                this.popupObject.show();
            }
        };
        ContentControlPopUp.prototype.onCloseButtonClicked = function () {
            this.closeButton();
        };
        ContentControlPopUp.prototype.destroy = function () {
            Iif (this.contenControl) {
                this.contenControl.destroy();
            }
            this.removeEvents();
            this.removeElements();
            this.contenControl = undefined;
            this.owner = undefined;
        };
        ContentControlPopUp.prototype.removeEvents = function () {
            Iif (this.textBoxOkButton) {
                this.textBoxOkButton.removeEventListener('click', this.applyDropDownFormFieldValueHandler);
            }
            Iif (this.textBoxCancelButton) {
                this.textBoxCancelButton.removeEventListener('click', this.closeButtonClickedHandler);
            }
        };
        ContentControlPopUp.prototype.removeElements = function () {
            Iif (this.target) {
                this.target.remove();
            }
            Iif (this.dataPickerOkButton && this.dataPickerOkButton.element && this.dataPickerOkButton.element.parentNode) {
                this.dataPickerOkButton.destroy();
                this.dataPickerOkButton = undefined;
            }
            Iif (this.ddlInstance) {
                this.ddlInstance.destroy();
                this.ddlInstance = undefined;
            }
            Iif (this.dataPickerOkButton) {
                this.dataPickerOkButton.destroy();
                this.dataPickerOkButton = undefined;
            }
            Iif (this.popupElement) {
                this.popupElement.remove();
                this.popupElement = undefined;
            }
            Iif (this.dropDownDiv) {
                this.dropDownDiv.remove();
                this.dropDownDiv = undefined;
            }
            Iif (this.textBoxButtonDiv) {
                this.textBoxButtonDiv.remove();
                this.textBoxButtonDiv = undefined;
            }
            Iif (this.textBoxOkButton) {
                this.textBoxOkButton.remove();
                this.textBoxOkButton = undefined;
            }
            Iif (this.textBoxCancelButton) {
                this.textBoxCancelButton.remove();
                this.textBoxCancelButton = undefined;
            }
            this.target = undefined;
            this.dropDownInput = undefined;
            this.ddlInstance = undefined;
            this.dropDownDiv = undefined;
            this.textBoxButtonDiv = undefined;
            this.textBoxOkButton = undefined;
            this.textBoxCancelButton = undefined;
        };
        return ContentControlPopUp;
    }());
    exports.ContentControlPopUp = ContentControlPopUp;
});