all files / grid/renderer/ dialog-edit-renderer.js

98.63% Statements 72/73
92.59% Branches 25/27
100% Functions 12/12
98.63% Lines 72/73
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         11×       11× 11× 11× 11× 11×   11×                               11×             16× 16× 16× 16× 11× 11×     11× 11× 11×   11×   88×   80× 80×         80× 80× 80× 80× 80×              
define(["require", "exports", "@syncfusion/ej2-popups", "@syncfusion/ej2-base", "../base/constant", "../base/util"], function (require, exports, ej2_popups_1, ej2_base_1, events, util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var DialogEditRender = (function () {
        function DialogEditRender(parent, serviceLocator) {
            this.parent = parent;
            this.serviceLocator = serviceLocator;
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(events.dialogDestroy, this.destroy, this);
            this.parent.on(events.destroy, this.destroy, this);
        }
        DialogEditRender.prototype.setLocaleObj = function () {
            this.l10n = this.serviceLocator.getService('localization');
        };
        DialogEditRender.prototype.addNew = function (elements, args) {
            this.isEdit = false;
            this.createDialog(elements, args);
        };
        DialogEditRender.prototype.update = function (elements, args) {
            this.isEdit = true;
            this.createDialog(elements, args);
        };
        DialogEditRender.prototype.createDialog = function (elements, args) {
            var gObj = this.parent;
            this.dialog = ej2_base_1.createElement('div', { id: gObj.element.id + '_dialogEdit_wrapper', styles: 'width: auto' });
            gObj.element.appendChild(this.dialog);
            this.setLocaleObj();
            var position = this.parent.element.getBoundingClientRect().height < 400 ?
                { X: 'center', Y: 'top' } : { X: 'center', Y: 'center' };
            this.dialogObj = args.dialog = new ej2_popups_1.Dialog({
                header: this.isEdit ? this.l10n.getConstant('EditFormTitle') + args.primaryKeyValue[0] :
                    this.l10n.getConstant('AddFormTitle'), isModal: true, visible: true, cssClass: 'e-edit-dialog',
                content: this.getEditElement(elements, args),
                showCloseIcon: true,
                allowDragging: true,
                position: position,
                close: this.dialogClose.bind(this),
                closeOnEscape: true, width: gObj.editSettings.template ? 'auto' : '330px',
                target: gObj.element, animationSettings: { effect: 'None' },
                buttons: [{
                        click: this.btnClick.bind(this),
                        buttonModel: { content: this.l10n.getConstant('SaveButton'), cssClass: 'e-primary', isPrimary: true }
                    },
                    { click: this.btnClick.bind(this), buttonModel: { cssClass: 'e-flat', content: this.l10n.getConstant('CancelButton') } }]
            });
            this.dialogObj.appendTo(this.dialog);
        };
        DialogEditRender.prototype.btnClick = function (e) {
            if (this.l10n.getConstant('CancelButton').toLowerCase() === e.target.innerText.trim().toLowerCase()) {
                this.dialogClose();
            }
            else {
                this.parent.endEdit();
            }
        };
        DialogEditRender.prototype.dialogClose = function () {
            this.parent.closeEdit();
            this.destroy();
        };
        DialogEditRender.prototype.destroy = function (args) {
            this.parent.notify(events.destroyForm, {});
            this.parent.isEdit = false;
            this.parent.notify(events.toolbarRefresh, {});
            if (this.dialog && !this.dialogObj.isDestroyed) {
                this.dialogObj.destroy();
                ej2_base_1.remove(this.dialog);
            }
        };
        DialogEditRender.prototype.getEditElement = function (elements, args) {
            var gObj = this.parent;
            var div = ej2_base_1.createElement('div', { className: this.isEdit ? 'e-editedrow' : 'e-insertedrow' });
            var form = args.form =
                ej2_base_1.createElement('form', { id: gObj.element.id + 'EditForm', className: 'e-gridform' });
            if (this.parent.editSettings.template) {
                var dummyData = ej2_base_1.extend({}, args.rowData, { isAdd: !this.isEdit }, true);
                util_1.appendChildren(form, this.parent.getEditTemplate()(dummyData, this.parent, 'editSettingsTemplate'));
                div.appendChild(form);
                return div;
            }
            var table = ej2_base_1.createElement('table', { className: 'e-table', attrs: { cellspacing: '6px' } });
            var tbody = ej2_base_1.createElement('tbody');
            var cols = gObj.getColumns();
            for (var i = 0; i < cols.length; i++) {
                if (!cols[i].visible || cols[i].commands || cols[i].commandsTemplate) {
                    continue;
                }
                var tr = ej2_base_1.createElement('tr');
                var dataCell = ej2_base_1.createElement('td', {
                    className: 'e-rowcell', attrs: {
                        style: 'text-align:' + (this.parent.enableRtl ? 'right' : 'left') + ';width:190px'
                    }
                });
                var label = ej2_base_1.createElement('label', { innerHTML: cols[i].field });
                elements[cols[i].uid].classList.remove('e-input');
                dataCell.appendChild(elements[cols[i].uid]);
                tr.appendChild(dataCell);
                tbody.appendChild(tr);
            }
            table.appendChild(tbody);
            form.appendChild(table);
            div.appendChild(form);
            return div;
        };
        DialogEditRender.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.dialogDestroy, this.destroy);
            this.parent.off(events.destroy, this.destroy);
        };
        return DialogEditRender;
    }());
    exports.DialogEditRender = DialogEditRender;
});