all files / document-editor/implementation/restrict-editing/ enforce-protection-dialog.js

98.91% Statements 91/92
80% Branches 8/10
100% Functions 17/17
98.91% Lines 91/92
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   515× 515× 18× 18× 18×   18× 18× 18× 18× 18×               18× 18× 18×   515×   515×         515× 515×     44×           513× 513×     515× 515×                   515×       515×   515× 515×                           513× 513×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-popups", "@syncfusion/ej2-inputs", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1, ej2_popups_1, ej2_inputs_1, ej2_base_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var EnforceProtectionDialog = (function () {
        function EnforceProtectionDialog(documentHelper, owner) {
            var _this = this;
            this.show = function () {
                _this.localeValue = new ej2_base_1.L10n('documenteditor', _this.viewer.owner.defaultLocale);
                _this.localeValue.setLocale(_this.viewer.owner.locale);
                if (!_this.target) {
                    _this.initDialog(_this.localeValue);
                }
                _this.documentHelper.dialog.header = _this.localeValue.getConstant('Start Enforcing Protection');
                _this.documentHelper.dialog.height = 'auto';
                _this.documentHelper.dialog.content = _this.target;
                _this.documentHelper.dialog.width = 'auto';
                _this.documentHelper.dialog.buttons = [{
                        click: _this.okButtonClick,
                        buttonModel: { content: _this.localeValue.getConstant('Ok'), cssClass: 'e-flat', isPrimary: true }
                    },
                    {
                        click: _this.hideDialog,
                        buttonModel: { content: _this.localeValue.getConstant('Cancel'), cssClass: 'e-flat' }
                    }];
                _this.passwordTextBox.value = '';
                _this.confirmPasswordTextBox.value = '';
                _this.documentHelper.dialog.show();
            };
            this.hideDialog = function () {
                _this.passwordTextBox.value = '';
                _this.confirmPasswordTextBox.value = '';
                _this.documentHelper.dialog.hide();
            };
            this.okButtonClick = function () {
                if (_this.passwordTextBox.value !== _this.confirmPasswordTextBox.value) {
                    ej2_popups_1.DialogUtility.alert(_this.localeValue.getConstant('Password Mismatch'));
                }
                else {
                    _this.password = ej2_base_2.SanitizeHtmlHelper.sanitize(_this.passwordTextBox.value);
                    _this.viewer.owner.editorModule.addProtection(_this.password, _this.owner.protectionType);
                }
            };
            this.documentHelper = documentHelper;
            this.owner = owner;
        }
        Object.defineProperty(EnforceProtectionDialog.prototype, "viewer", {
            get: function () {
                return this.owner.viewer;
            },
            enumerable: true,
            configurable: true
        });
        EnforceProtectionDialog.prototype.initDialog = function (localValue) {
            this.target = ej2_base_1.createElement('div', { className: 'e-de-enforce' });
            var passwordContainer = ej2_base_1.createElement('div', { className: 'e-de-container-row' });
            this.passwordTextBox = ej2_base_1.createElement('input', { attrs: { type: 'password', autofocus: 'true' }, className: 'e-input' });
            passwordContainer.appendChild(this.passwordTextBox);
            var confirmPasswordcontainer = ej2_base_1.createElement('div');
            this.confirmPasswordTextBox = ej2_base_1.createElement('input', { attrs: { type: 'password' }, className: 'e-input' });
            confirmPasswordcontainer.appendChild(this.confirmPasswordTextBox);
            this.target.appendChild(passwordContainer);
            this.target.appendChild(confirmPasswordcontainer);
            new ej2_inputs_1.TextBox({ placeholder: localValue.getConstant('Enter new password'), floatLabelType: 'Always', cssClass: 'e-de-enforce-dlg-input' }, this.passwordTextBox);
            new ej2_inputs_1.TextBox({ placeholder: localValue.getConstant('Reenter new password to confirm'), floatLabelType: 'Always' }, this.confirmPasswordTextBox);
        };
        EnforceProtectionDialog.prototype.destroy = function () {
            this.documentHelper = undefined;
            this.owner = undefined;
        };
        return EnforceProtectionDialog;
    }());
    exports.EnforceProtectionDialog = EnforceProtectionDialog;
    var UnProtectDocumentDialog = (function () {
        function UnProtectDocumentDialog(documentHelper, owner) {
            var _this = this;
            this.show = function () {
                _this.localObj = new ej2_base_1.L10n('documenteditor', _this.viewer.owner.defaultLocale);
                _this.localObj.setLocale(_this.viewer.owner.locale);
                Eif (!_this.target) {
                    _this.initDialog(_this.localObj);
                }
                _this.documentHelper.dialog.header = 'Unprotect Document';
                _this.documentHelper.dialog.height = 'auto';
                _this.documentHelper.dialog.width = 'auto';
                _this.documentHelper.dialog.content = _this.target;
                _this.documentHelper.dialog.buttons = [{
                        click: _this.okButtonClick,
                        buttonModel: { content: _this.localObj.getConstant('Ok'), cssClass: 'e-flat', isPrimary: true }
                    },
                    {
                        click: _this.hideDialog,
                        buttonModel: { content: _this.localObj.getConstant('Cancel'), cssClass: 'e-flat' }
                    }];
                _this.documentHelper.dialog.dataBind();
                _this.passwordTextBox.value = '';
                _this.documentHelper.dialog.show();
            };
            this.okButtonClick = function () {
                var password = _this.passwordTextBox.value;
                var empty = '';
                Eif (password.length === empty.length && password === empty) {
                    ej2_popups_1.DialogUtility.alert(_this.localObj.getConstant('The password is incorrect'));
                    return;
                }
                _this.viewer.owner.editorModule.stopProtection(password);
            };
            this.hideDialog = function () {
                _this.passwordTextBox.value = '';
                _this.documentHelper.dialog.hide();
            };
            this.documentHelper = documentHelper;
            this.owner = owner;
        }
        Object.defineProperty(UnProtectDocumentDialog.prototype, "viewer", {
            get: function () {
                return this.owner.viewer;
            },
            enumerable: true,
            configurable: true
        });
        UnProtectDocumentDialog.prototype.initDialog = function (localValue) {
            var id = this.viewer.owner.containerId + '_enforce_protection';
            this.target = ej2_base_1.createElement('div', { id: id, className: 'e-de-enforce' });
            var container = ej2_base_1.createElement('div');
            var newPassWord = ej2_base_1.createElement('div', {
                className: 'e-de-unprotect-dlg-title',
                innerHTML: localValue.getConstant('Password')
            });
            this.passwordTextBox = ej2_base_1.createElement('input', {
                attrs: { type: 'password' },
                id: this.viewer.owner.containerId + '_display_text', className: 'e-input e-de-enforce-dlg-input'
            });
            container.appendChild(newPassWord);
            container.appendChild(this.passwordTextBox);
            this.target.appendChild(container);
        };
        UnProtectDocumentDialog.prototype.destroy = function () {
            this.documentHelper = undefined;
            this.owner = undefined;
        };
        return UnProtectDocumentDialog;
    }());
    exports.UnProtectDocumentDialog = UnProtectDocumentDialog;
});