all files / spreadsheet/actions/ protect-sheet.js

90.66% Statements 427/471
82.38% Branches 159/193
89.09% Functions 49/55
90.64% Lines 426/470
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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773   885× 885× 885×   885×   885× 885×   885× 885× 885× 885× 885× 885× 885× 885× 885× 885× 885× 885×   885× 12× 12× 12× 12× 12× 12× 12× 12× 12× 12× 12× 12×     37× 12× 12×       37× 37× 25×     12× 12× 12× 12×     25× 25× 25×               25×           25× 25× 25× 25× 25× 25× 25× 25× 25× 25× 25× 25× 25× 25×       25× 25× 25× 25× 25×           25×       25× 25×   25×     14×                   25× 25× 25× 25× 25×           73× 73×   73×     21× 21×   21× 13× 13× 13× 13× 13×   11×                                           19× 19× 19×               19× 19× 19×   1085× 1085× 1085× 1085×       1085×       1085× 1085× 1085× 1085× 1085× 1085× 1085× 1085× 1085× 57× 33×   24×     21×       1028×   1085× 1028×     1085× 1085×         1085× 1085× 57×   1085× 30×     16× 16× 16× 16×               16×         16× 16×   16× 16×   10×     12× 12× 12× 12×       12×       12× 12×   12× 12× 12×             12× 12×         12× 12× 12× 12× 12× 12× 12× 12× 12× 12× 12× 12× 12× 12× 12× 12× 12× 12× 12×   81× 81×             81×             81×             81×             81×                             30× 30× 30× 30× 30× 30×   30×   30×     30×   30×     12× 12×   12×   12×     12×         12×     11× 11× 11× 11× 11×   11×                                                                                                                                                                                                                                                                                   38× 38× 38× 38×       38×     31× 31× 31×     126650×        
define(["require", "exports", "../index", "../common/event", "../common/event", "../common/index", "@syncfusion/ej2-lists", "@syncfusion/ej2-base", "../common/index", "@syncfusion/ej2-buttons", "../../workbook/index"], function (require, exports, index_1, event_1, event_2, index_2, ej2_lists_1, ej2_base_1, index_3, ej2_buttons_1, index_4) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ProtectSheet = (function () {
        function ProtectSheet(parent) {
            this.password = '';
            this.parent = parent;
            this.init();
        }
        ProtectSheet.prototype.init = function () {
            this.addEventListener();
        };
        ProtectSheet.prototype.destroy = function () {
            this.removeEventListener();
            this.parent = null;
        };
        ProtectSheet.prototype.addEventListener = function () {
            this.parent.on(event_1.applyProtect, this.protect, this);
            this.parent.on(event_1.protectSheet, this.protectSheetHandler, this);
            this.parent.on(event_1.editAlert, this.editProtectedAlert, this);
            this.parent.on(event_1.protectWorkbook, this.protectWorkbook, this);
            this.parent.on(event_1.keyUp, this.KeyUpHandler, this);
            this.parent.on(event_2.unProtectWorkbook, this.unProtectWorkbook, this);
            this.parent.on(event_1.unProtectSheetPassword, this.unProtectSheetPassword, this);
            this.parent.on(event_2.getPassWord, this.getPassWord, this);
            this.parent.on(event_2.importProtectWorkbook, this.importProtectWorkbook, this);
            this.parent.on(event_1.setProtectWorkbook, this.protectWorkbookHandler, this);
            this.parent.on(event_1.removeWorkbookProtection, this.removeWorkbookProtection, this);
            this.parent.on(index_2.toggleProtect, this.toggleProtect, this);
        };
        ProtectSheet.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(event_1.applyProtect, this.protect);
                this.parent.off(event_1.protectSheet, this.protectSheetHandler);
                this.parent.off(event_1.editAlert, this.editProtectedAlert);
                this.parent.off(event_1.protectWorkbook, this.protectWorkbook);
                this.parent.off(event_1.keyUp, this.KeyUpHandler);
                this.parent.off(event_2.unProtectWorkbook, this.unProtectWorkbook);
                this.parent.off(event_1.unProtectSheetPassword, this.unProtectSheetPassword);
                this.parent.off(event_2.getPassWord, this.getPassWord);
                this.parent.off(event_2.importProtectWorkbook, this.importProtectWorkbook);
                this.parent.off(event_1.setProtectWorkbook, this.protectWorkbookHandler);
                this.parent.off(event_1.removeWorkbookProtection, this.removeWorkbookProtection);
                this.parent.off(index_2.toggleProtect, this.toggleProtect);
            }
        };
        ProtectSheet.prototype.protect = function (args) {
            if (args.isActive) {
                var sheet = this.parent.getActiveSheet();
                Iif (sheet.isImportProtected) {
                    sheet.isImportProtected = false;
                }
            }
            this.parent.notify(index_2.clearCopy, null);
            if (!args.isActive) {
                this.createDialogue();
            }
            else {
                this.parent.setSheetPropertyOnMute(index_4.getSheet(this.parent, args.sheetIndex), 'isProtected', false);
                this.parent.notify(index_3.updateToggleItem, { props: 'Protect' });
                this.parent.notify(event_1.protectSheet, args);
                this.parent.notify(index_2.protectSelection, null);
            }
        };
        ProtectSheet.prototype.createDialogue = function () {
            var _this = this;
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var listData = [
                { text: l10n.getConstant('SelectCells'), id: '1' },
                { text: l10n.getConstant('SelectUnlockedCells'), id: '6' },
                { text: l10n.getConstant('FormatCells'), id: '2' },
                { text: l10n.getConstant('FormatRows'), id: '3' },
                { text: l10n.getConstant('FormatColumns'), id: '4' },
                { text: l10n.getConstant('InsertLinks'), id: '5' }
            ];
            this.optionList = new ej2_lists_1.ListView({
                width: '250px',
                dataSource: listData,
                showCheckBox: true,
                select: this.dialogOpen.bind(this)
            });
            var dialogElem = this.parent.createElement('div', { className: 'e-sheet-password-dialog' });
            var pwdCont = this.parent.createElement('div', { className: 'e-sheet-password-content' });
            var textH = this.parent.createElement('div', { className: 'e-header' });
            textH.innerText = l10n.getConstant('SheetPassword');
            var pwdInput = this.parent.createElement('input', { className: 'e-input e-text', attrs: { 'type': 'password' } });
            pwdInput.setAttribute('placeholder', l10n.getConstant('EnterThePassword'));
            pwdCont.appendChild(pwdInput);
            pwdCont.insertBefore(textH, pwdInput);
            dialogElem.appendChild(pwdCont);
            var protectHeaderCntent = this.parent.createElement('div', { className: 'e-protect-content' });
            protectHeaderCntent.innerText = l10n.getConstant('ProtectAllowUser');
            this.parent.setSheetPropertyOnMute(this.parent.getActiveSheet(), 'isProtected', false);
            var checkbox = new ej2_buttons_1.CheckBox({ checked: true, label: l10n.getConstant('ProtectContent'), cssClass: 'e-protect-checkbox' });
            var listViewElement = this.parent.createElement('div', {
                className: 'e-protect-option-list',
                id: this.parent.element.id + '_option_list'
            });
            var headerContent = this.parent.createElement('div', { className: 'e-header-content' });
            headerContent.innerText = l10n.getConstant('ProtectSheet');
            var checkBoxElement = this.parent.createElement('input', { id: this.parent.element.id + '_protect_check', attrs: { type: 'checkbox' } });
            this.dialog = this.parent.serviceLocator.getService('dialog');
            this.dialog.show({
                header: headerContent.outerHTML,
                content: dialogElem.outerHTML + checkBoxElement.outerHTML + protectHeaderCntent.outerHTML + listViewElement.outerHTML,
                showCloseIcon: true, isModal: true,
                cssClass: 'e-protect-dlg',
                beforeOpen: function (args) {
                    var dlgArgs = {
                        dialogName: 'ProtectSheetDialog',
                        element: args.element, target: args.target, cancel: args.cancel
                    };
                    _this.parent.trigger('dialogBeforeOpen', dlgArgs);
                    if (dlgArgs.cancel) {
                        args.cancel = true;
                    }
                    index_2.focus(_this.parent.element);
                },
                beforeClose: function () {
                    ej2_base_1.EventHandler.remove(checkbox.element, 'click', _this.checkBoxClickHandler);
                },
                buttons: [{
                        click: this.selectOption.bind(this, this.dialog, this),
                        buttonModel: { content: l10n.getConstant('Ok'), isPrimary: true }
                    },
                    {
                        click: function () { return _this.dialog.hide(); },
                        buttonModel: { content: l10n.getConstant('Cancel') }
                    }]
            }, false);
            this.protectSheetDialog = this.dialog.dialogInstance;
            checkbox.appendTo('#' + this.parent.element.id + '_protect_check');
            this.optionList.appendTo('#' + this.parent.element.id + '_option_list');
            this.optionList.selectMultipleItems([{ id: '1' }, { id: '6' }]);
            ej2_base_1.EventHandler.add(checkbox.element, 'click', this.checkBoxClickHandler, this);
        };
        ProtectSheet.prototype.checkBoxClickHandler = function () {
            var ch = document.getElementById(this.parent.element.id + '_protect_check');
            if (ch.checked === false) {
                this.dialog.dialogInstance.element.getElementsByClassName('e-footer-content')[0].querySelector('button').disabled = true;
            }
            else {
                this.dialog.dialogInstance.element.getElementsByClassName('e-footer-content')[0].querySelector('button').disabled = false;
            }
        };
        ProtectSheet.prototype.dialogOpen = function (args) {
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            if (args.text === l10n.getConstant('SelectCells') && args.isChecked && args.isInteracted) {
                this.optionList.checkItem({ id: '6' });
            }
            if (args.text === l10n.getConstant('SelectUnlockedCells') && !args.isChecked && args.isInteracted) {
                this.optionList.uncheckItem({ id: '1' });
            }
        };
        ProtectSheet.prototype.selectOption = function () {
            var actSheet = this.parent.getActiveSheet();
            var pwd = this.parent.element.querySelector('.e-sheet-password-dialog').
                getElementsByClassName('e-sheet-password-content')[0].querySelector('.e-input');
            if (pwd.value.length === 0) {
                this.parent.setSheetPropertyOnMute(actSheet, 'isProtected', true);
                this.parent.setSheetPropertyOnMute(actSheet, 'password', pwd.value);
                this.updateProtectSheet(pwd.value);
                this.dialog.hide();
                if (!actSheet.protectSettings.selectCells && !actSheet.protectSettings.selectUnLockedCells) {
                    this.parent.notify(event_2.hideAutoFillElement, null);
                }
                else if (actSheet.protectSettings.selectUnLockedCells &&
                    index_2.isLockedCells(this.parent, index_4.getRangeIndexes(actSheet.selectedRange))) {
                    this.parent.notify(event_2.hideAutoFillElement, null);
                }
            }
            else {
                this.reEnterSheetPassword();
            }
        };
        ProtectSheet.prototype.selectSheetPassword = function () {
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var actSheet = this.parent.getActiveSheet();
            var pwd = this.parent.element.querySelector('.e-sheet-password-dialog').
                getElementsByClassName('e-sheet-password-content')[0].querySelector('.e-input');
            var cnfrmPwd = this.parent.element.querySelector('.e-reenterpwd-dialog').
                getElementsByClassName('e-reenterpwd-content')[0].querySelector('.e-input');
            var pwdSpan = this.parent.createElement('span', {
                className: 'e-reenterpwd-alert-span'
            });
            if (pwd.value === cnfrmPwd.value) {
                this.parent.setSheetPropertyOnMute(actSheet, 'isProtected', true);
                this.parent.setSheetPropertyOnMute(actSheet, 'password', pwd.value);
                this.updateProtectSheet(pwd.value);
                this.dialog.hide();
                Eif (this.protectSheetDialog) {
                    this.protectSheetDialog = null;
                }
                var sheetDlgPopup = document.querySelector('.e-protect-dlg.e-dialog');
                var sheetDlg = ej2_base_1.getComponent(sheetDlgPopup, 'dialog');
                sheetDlg.destroy();
                if (!actSheet.protectSettings.selectCells && !actSheet.protectSettings.selectUnLockedCells) {
                    this.parent.notify(event_2.hideAutoFillElement, null);
                }
            }
            else {
                Iif (pwd.value === '') {
                    pwdSpan.textContent = l10n.getConstant('PasswordAlertMsg');
                }
                else Iif (cnfrmPwd.value === '') {
                    pwdSpan.textContent = l10n.getConstant('ConfirmPasswordAlertMsg');
                }
                else Eif (pwd.value !== cnfrmPwd.value) {
                    pwdSpan.textContent = l10n.getConstant('PasswordAlert');
                }
                (this.parent.element.querySelector('.e-reenterpwd-dlg').querySelector('.e-reenterpwd-dialog')).appendChild(pwdSpan);
            }
        };
        ProtectSheet.prototype.updateProtectSheet = function (password) {
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var selectedItems = this.optionList.getSelectedItems();
            var protectSettings = {
                selectCells: selectedItems.text.indexOf(l10n.getConstant('SelectCells')) > -1,
                formatCells: selectedItems.text.indexOf(l10n.getConstant('FormatCells')) > -1,
                formatRows: selectedItems.text.indexOf(l10n.getConstant('FormatRows')) > -1,
                formatColumns: selectedItems.text.indexOf(l10n.getConstant('FormatColumns')) > -1,
                insertLink: selectedItems.text.indexOf(l10n.getConstant('InsertLinks')) > -1,
                selectUnLockedCells: selectedItems.text.indexOf(l10n.getConstant('SelectUnlockedCells')) > -1
            };
            this.parent.notify(index_4.protectsheetHandler, { protectSettings: protectSettings, password: password, triggerEvent: true });
            this.parent.notify(index_2.protectSelection, null);
            this.parent.notify(index_2.clearUndoRedoCollection, null);
        };
        ProtectSheet.prototype.protectSheetHandler = function (args) {
            var sheetIndex = ej2_base_1.isNullOrUndefined(args && args.sheetIndex) ? this.parent.activeSheetIndex : args.sheetIndex;
            var sheet = index_4.getSheet(this.parent, sheetIndex);
            var id = this.parent.element.id;
            var disableHomeBtnId = [id + '_undo', id + '_redo', id + '_cut', id + '_copy', id + '_paste', id + '_number_format',
                id + '_font_name', id + '_font_size', id + '_bold', id + '_italic', id + '_line-through', id + '_underline',
                id + '_font_color_picker', id + '_fill_color_picker', id + '_borders', id + '_merge_cells', id + '_text_align',
                id + '_vertical_align', id + '_wrap', id + '_sorting', id + '_clear', id + '_conditionalformatting'];
            var enableHomeBtnId = [id + '_cut', id + '_copy', id + '_number_format', id + '_font_name', id + '_font_size',
                id + '_bold', id + '_italic', id + '_line-through', id + '_underline', id + '_font_color_picker', id + '_fill_color_picker',
                id + '_borders', id + '_text_align', id + '_vertical_align', id + '_wrap', id + '_sorting',
                id + '_clear', id + '_conditionalformatting'];
            var enableFrmlaBtnId = [id + '_insert_function'];
            var enableInsertBtnId = [id + '_hyperlink', id + '_', id + '_chart'];
            var imageBtnId = [id + '_image'];
            var findBtnId = [id + '_find'];
            var dataValidationBtnId = [id + '_datavalidation'];
            var chartBtnId = [id + '_chart'];
            var sheetElement = document.getElementById(this.parent.element.id + '_sheet_panel');
            Eif (sheetElement) {
                if (sheet.isProtected) {
                    if (sheet.protectSettings.selectCells) {
                        sheetElement.classList.remove('e-protected');
                    }
                    else if (sheet.protectSettings.selectUnLockedCells && !index_2.isLockedCells(this.parent, index_4.getRangeIndexes(sheet.selectedRange))) {
                        sheetElement.classList.remove('e-protected');
                    }
                    else {
                        sheetElement.classList.add('e-protected');
                    }
                }
                else {
                    sheetElement.classList.add('e-protected');
                }
                if (!sheet.isProtected) {
                    sheetElement.classList.remove('e-protected');
                }
            }
            this.parent.dataBind();
            this.parent.notify(event_1.protectCellFormat, {
                disableHomeBtnId: disableHomeBtnId,
                enableHomeBtnId: enableHomeBtnId, enableFrmlaBtnId: enableFrmlaBtnId, enableInsertBtnId: enableInsertBtnId,
                findBtnId: findBtnId, dataValidationBtnId: dataValidationBtnId, imageBtnId: imageBtnId, chartBtnId: chartBtnId
            });
            this.parent.notify(event_1.enableFormulaInput, null);
            if (sheet.isProtected) {
                this.parent.notify(index_3.updateToggleItem, { props: 'Protect' });
            }
            if (args && args.triggerEvent) {
                this.parent.notify(event_1.completeAction, { action: 'protectSheet', eventArgs: { sheetIndex: sheetIndex, isProtected: sheet.isProtected, password: sheet.password, protectSettings: sheet.protectSettings.properties || sheet.protectSettings } });
            }
        };
        ProtectSheet.prototype.editProtectedAlert = function () {
            var _this = this;
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            this.dialog = this.parent.serviceLocator.getService('dialog');
            this.dialog.show({
                content: l10n.getConstant('EditAlert'),
                isModal: true,
                closeOnEscape: true,
                showCloseIcon: true,
                width: '400px',
                cssClass: 'e-editAlert-dlg',
                beforeOpen: function (args) {
                    var dlgArgs = {
                        dialogName: 'EditAlertDialog',
                        content: l10n.getConstant('EditAlert'),
                        element: args.element, target: args.target, cancel: args.cancel
                    };
                    _this.parent.trigger('dialogBeforeOpen', dlgArgs);
                    if (dlgArgs.cancel) {
                        args.cancel = true;
                        index_1.getUpdateUsingRaf(function () { return _this.dialog.destroyDialog(); });
                    }
                    _this.dialog.dialogInstance.content = dlgArgs.content;
                    index_2.focus(_this.parent.element);
                },
                close: function () { return index_2.focus(_this.parent.element); }
            });
        };
        ProtectSheet.prototype.protectWorkbook = function () {
            var _this = this;
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var dialogInst = this.parent.serviceLocator.getService(index_3.dialog);
            dialogInst.show({
                width: 323, isModal: true, showCloseIcon: true, cssClass: 'e-protectworkbook-dlg',
                header: l10n.getConstant('ProtectWorkbook'),
                beforeOpen: function (args) {
                    var dlgArgs = {
                        dialogName: 'ProtectWorkbook',
                        element: args.element, target: args.target, cancel: args.cancel
                    };
                    _this.parent.trigger('dialogBeforeOpen', dlgArgs);
                    if (dlgArgs.cancel) {
                        args.cancel = true;
                    }
                    dialogInst.dialogInstance.content = _this.passwordProtectContent();
                    dialogInst.dialogInstance.dataBind();
                    _this.parent.element.focus();
                },
                buttons: [{
                        buttonModel: {
                            content: l10n.getConstant('Ok'), isPrimary: true
                        },
                        click: function () {
                            _this.alertMessage();
                            _this.dlgClickHandler(dialogInst);
                        }
                    }]
            });
        };
        ProtectSheet.prototype.passwordProtectContent = function () {
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var dialogElem = this.parent.createElement('div', { className: 'e-password-dialog' });
            var pwdCont = this.parent.createElement('div', { className: 'e-password-content' });
            var cnfrmPwdCont = this.parent.createElement('div', { className: 'e-password-content' });
            var textH = this.parent.createElement('div', { className: 'e-header' });
            textH.innerText = l10n.getConstant('Password');
            var urlH = this.parent.createElement('div', { className: 'e-header' });
            urlH.innerText = l10n.getConstant('ConfirmPassword');
            var pwdInput = this.parent.createElement('input', { className: 'e-input e-text', attrs: { 'type': 'password' } });
            var cnfrmPwdInput = this.parent.createElement('input', { className: 'e-input e-text', attrs: { 'type': 'password' } });
            pwdInput.setAttribute('placeholder', l10n.getConstant('EnterThePassword'));
            cnfrmPwdInput.setAttribute('placeholder', l10n.getConstant('EnterTheConfirmPassword'));
            pwdCont.appendChild(pwdInput);
            pwdCont.insertBefore(textH, pwdInput);
            cnfrmPwdCont.appendChild(cnfrmPwdInput);
            cnfrmPwdCont.insertBefore(urlH, cnfrmPwdInput);
            dialogElem.appendChild(cnfrmPwdCont);
            dialogElem.insertBefore(pwdCont, cnfrmPwdCont);
            return dialogElem;
        };
        ProtectSheet.prototype.KeyUpHandler = function (e) {
            var trgt = e.target;
            if (trgt.classList.contains('e-text') && ej2_base_1.closest(trgt, '.e-password-content')) {
                if (ej2_base_1.closest(trgt, '.e-password-dialog') && ej2_base_1.closest(trgt, '.e-password-dialog').
                    getElementsByClassName('e-password-content')[1] === trgt.parentElement) {
                    var dlgEle = ej2_base_1.closest(trgt, '.e-protectworkbook-dlg');
                    var ftrEle = dlgEle.getElementsByClassName('e-footer-content')[0];
                    var okBtn = ftrEle.firstChild;
                    if (trgt.value !== '') {
                        okBtn.removeAttribute('disabled');
                    }
                    else {
                        okBtn.setAttribute('disabled', 'true');
                    }
                }
            }
            if (trgt.classList.contains('e-text') && ej2_base_1.closest(trgt, '.e-unprotectpwd-content')) {
                Eif (ej2_base_1.closest(trgt, '.e-unprotectpwd-dialog') && ej2_base_1.closest(trgt, '.e-unprotectpwd-dialog').
                    getElementsByClassName('e-unprotectpwd-content')[0] === trgt.parentElement) {
                    var dlgElement = ej2_base_1.closest(trgt, '.e-unprotectworkbook-dlg');
                    var ftrElement = dlgElement.getElementsByClassName('e-footer-content')[0];
                    var okButton = ftrElement.firstChild;
                    if (trgt.value !== '') {
                        okButton.removeAttribute('disabled');
                    }
                    else {
                        okButton.setAttribute('disabled', 'true');
                    }
                }
            }
            if (trgt.classList.contains('e-text') && ej2_base_1.closest(trgt, '.e-reenterpwd-content')) {
                Eif (ej2_base_1.closest(trgt, '.e-reenterpwd-dialog') && ej2_base_1.closest(trgt, '.e-reenterpwd-dialog').
                    getElementsByClassName('e-reenterpwd-content')[0] === trgt.parentElement) {
                    var dlgCnt = ej2_base_1.closest(trgt, '.e-reenterpwd-dlg');
                    var ftrCnt = dlgCnt.getElementsByClassName('e-footer-content')[0];
                    var okBtnElem = ftrCnt.firstChild;
                    if (trgt.value !== '') {
                        okBtnElem.removeAttribute('disabled');
                    }
                    else {
                        okBtnElem.setAttribute('disabled', 'true');
                    }
                }
            }
            if (trgt.classList.contains('e-text') && ej2_base_1.closest(trgt, '.e-unprotectsheetpwd-content')) {
                Eif (ej2_base_1.closest(trgt, '.e-unprotectsheetpwd-dialog') && ej2_base_1.closest(trgt, '.e-unprotectsheetpwd-dialog').
                    getElementsByClassName('e-unprotectsheetpwd-content')[0] === trgt.parentElement) {
                    var dlg = ej2_base_1.closest(trgt, '.e-unprotectworksheet-dlg');
                    var ftr = dlg.getElementsByClassName('e-footer-content')[0];
                    var btn = ftr.firstChild;
                    if (trgt.value !== '') {
                        btn.removeAttribute('disabled');
                    }
                    else {
                        btn.setAttribute('disabled', 'true');
                    }
                }
            }
            Iif (trgt.classList.contains('e-text') && ej2_base_1.closest(trgt, '.e-importprotectpwd-content')) {
                if (ej2_base_1.closest(trgt, '.e-importprotectpwd-dialog') && ej2_base_1.closest(trgt, '.e-importprotectpwd-dialog').
                    getElementsByClassName('e-importprotectpwd-content')[0] === trgt.parentElement) {
                    var dlgElem = ej2_base_1.closest(trgt, '.e-importprotectworkbook-dlg');
                    var ftrElem = dlgElem.getElementsByClassName('e-footer-content')[0];
                    var btn = ftrElem.firstChild;
                    if (trgt.value !== '') {
                        btn.removeAttribute('disabled');
                    }
                    else {
                        btn.setAttribute('disabled', 'true');
                    }
                }
            }
        };
        ProtectSheet.prototype.alertMessage = function () {
            var spanElem = this.parent.element.querySelector('.e-pwd-alert-span');
            var unpotectSpanElem = this.parent.element.querySelector('.e-unprotectpwd-alert-span');
            var importpotectSpanElem = this.parent.element.querySelector('.e-importprotectpwd-alert-span');
            var protectSheetSpanElem = this.parent.element.querySelector('.e-reenterpwd-alert-span');
            var unProtectSheetSpanElem = this.parent.element.querySelector('.e-unprotectsheetpwd-alert-span');
            if (spanElem) {
                spanElem.remove();
            }
            if (unpotectSpanElem) {
                unpotectSpanElem.remove();
            }
            Iif (importpotectSpanElem) {
                importpotectSpanElem.remove();
            }
            if (protectSheetSpanElem) {
                protectSheetSpanElem.remove();
            }
            if (unProtectSheetSpanElem) {
                unProtectSheetSpanElem.remove();
            }
        };
        ProtectSheet.prototype.dlgClickHandler = function (dialogInst) {
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var pwdVal = this.parent.element.querySelector('.e-password-dialog').
                getElementsByClassName('e-password-content')[0].querySelector('.e-input');
            var cnfrmPwd = this.parent.element.querySelector('.e-password-dialog').
                getElementsByClassName('e-password-content')[1].querySelector('.e-input');
            var pwdSpan = this.parent.createElement('span', {
                className: 'e-pwd-alert-span'
            });
            if (pwdVal.value === cnfrmPwd.value) {
                dialogInst.hide();
                this.parent.notify(index_3.updateToggleItem, { props: 'Protectworkbook' });
                this.protectWorkbookHandler({ password: pwdVal.value });
                this.parent.notify(event_1.completeAction, { action: 'protectWorkbook', eventArgs: { isProtected: true, password: pwdVal.value } });
            }
            else if (pwdVal.value === '') {
                pwdSpan.textContent = l10n.getConstant('PasswordAlertMsg');
            }
            else if (cnfrmPwd.value === '') {
                pwdSpan.textContent = l10n.getConstant('ConfirmPasswordAlertMsg');
            }
            else Eif (pwdVal.value !== cnfrmPwd.value) {
                pwdSpan.textContent = l10n.getConstant('PasswordAlert');
            }
            if (dialogInst.dialogInstance) {
                (this.parent.element.querySelector('.e-protectworkbook-dlg').querySelector('.e-dlg-content')).appendChild(pwdSpan);
            }
        };
        ProtectSheet.prototype.protectWorkbookHandler = function (args) {
            this.parent.password = args.password;
            this.parent.isProtected = true;
            Eif (this.parent.showSheetTabs) {
                this.parent.element.querySelector('.e-add-sheet-tab').setAttribute('disabled', 'true');
                this.parent.element.querySelector('.e-add-sheet-tab').classList.add('e-disabled');
            }
            this.parent.notify(index_3.updateToggleItem, { props: 'Protectworkbook' });
        };
        ProtectSheet.prototype.unProtectWorkbook = function () {
            var _this = this;
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var dialogInst = this.parent.serviceLocator.getService(index_3.dialog);
            dialogInst.show({
                width: 323, isModal: true, showCloseIcon: true, cssClass: 'e-unprotectworkbook-dlg',
                header: l10n.getConstant('UnprotectWorkbook'),
                beforeOpen: function (args) {
                    var dlgArgs = {
                        dialogName: 'UnprotectWorkbook',
                        element: args.element, target: args.target, cancel: args.cancel
                    };
                    _this.parent.trigger('dialogBeforeOpen', dlgArgs);
                    if (dlgArgs.cancel) {
                        args.cancel = true;
                    }
                    dialogInst.dialogInstance.content = _this.unProtectPasswordContent();
                    dialogInst.dialogInstance.dataBind();
                    _this.parent.element.focus();
                },
                buttons: [{
                        buttonModel: {
                            content: l10n.getConstant('Ok'), isPrimary: true, disabled: true
                        },
                        click: function () {
                            _this.alertMessage();
                            _this.unprotectdlgOkClick(dialogInst);
                        }
                    }]
            });
        };
        ProtectSheet.prototype.unProtectsheet = function (isImportedSheet) {
            var _this = this;
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var dialogInst = this.parent.serviceLocator.getService(index_3.dialog);
            dialogInst.show({
                width: 323, isModal: true, showCloseIcon: true, cssClass: 'e-unprotectworksheet-dlg',
                header: l10n.getConstant('UnprotectWorksheet'),
                beforeOpen: function (args) {
                    var dlgArgs = {
                        dialogName: 'UnProtectSheet',
                        element: args.element, target: args.target, cancel: args.cancel
                    };
                    _this.parent.trigger('dialogBeforeOpen', dlgArgs);
                    if (dlgArgs.cancel) {
                        args.cancel = true;
                    }
                    dialogInst.dialogInstance.content = _this.unProtectSheetPasswordContent();
                    dialogInst.dialogInstance.dataBind();
                    _this.parent.element.focus();
                },
                buttons: [{
                        buttonModel: {
                            content: l10n.getConstant('Ok'), isPrimary: true, disabled: this.parent.allowOpen && this.parent.openModule.isImportedFile &&
                                (this.parent.openModule.unProtectSheetIdx.indexOf(this.parent.activeSheetIndex) === -1) ? false : true
                        },
                        click: function () {
                            _this.alertMessage();
                            _this.unprotectSheetdlgOkClick(dialogInst, isImportedSheet);
                        }
                    }]
            });
        };
        ProtectSheet.prototype.reEnterSheetPassword = function () {
            var _this = this;
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var dialogInst = this.parent.serviceLocator.getService(index_3.dialog);
            dialogInst.show({
                width: 323, isModal: true, showCloseIcon: true, cssClass: 'e-reenterpwd-dlg',
                header: l10n.getConstant('ConfirmPassword'),
                beforeOpen: function (args) {
                    var dlgArgs = {
                        dialogName: 'Re-enterPassword',
                        element: args.element, target: args.target, cancel: args.cancel
                    };
                    _this.parent.trigger('dialogBeforeOpen', dlgArgs);
                    if (dlgArgs.cancel) {
                        args.cancel = true;
                    }
                    dialogInst.dialogInstance.content = _this.reEnterSheetPasswordContent();
                    dialogInst.dialogInstance.dataBind();
                    var focusEle = _this.parent.element.querySelector('.e-protect-dlg.e-dialog .e-footer-content .e-btn') ||
                        _this.parent.element;
                    index_2.focus(focusEle);
                },
                close: function () {
                    _this.dialog.dialogInstance = _this.protectSheetDialog;
                },
                buttons: [{
                        buttonModel: {
                            content: l10n.getConstant('Ok'), isPrimary: true, disabled: true
                        },
                        click: function () {
                            _this.alertMessage();
                            _this.selectSheetPassword();
                        }
                    }]
            });
        };
        ProtectSheet.prototype.unProtectPasswordContent = function () {
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var dlgElem = this.parent.createElement('div', { className: 'e-unprotectpwd-dialog' });
            var pwdCont = this.parent.createElement('div', { className: 'e-unprotectpwd-content' });
            var textHeader = this.parent.createElement('div', { className: 'e-header' });
            textHeader.innerText = l10n.getConstant('EnterThePassword');
            var pwdInputElem = this.parent.createElement('input', { className: 'e-input e-text', attrs: { 'type': 'password' } });
            pwdCont.appendChild(pwdInputElem);
            pwdCont.insertBefore(textHeader, pwdInputElem);
            dlgElem.appendChild(pwdCont);
            return dlgElem;
        };
        ProtectSheet.prototype.reEnterSheetPasswordContent = function () {
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var dialogElem = this.parent.createElement('div', { className: 'e-reenterpwd-dialog' });
            var pwdCont = this.parent.createElement('div', { className: 'e-reenterpwd-content' });
            var textH = this.parent.createElement('div', { className: 'e-header' });
            textH.innerText = l10n.getConstant('ReEnterPassword');
            var pwdInput = this.parent.createElement('input', { className: 'e-input e-text', attrs: { 'type': 'password' } });
            pwdCont.appendChild(pwdInput);
            pwdCont.insertBefore(textH, pwdInput);
            dialogElem.appendChild(pwdCont);
            return dialogElem;
        };
        ProtectSheet.prototype.unProtectSheetPasswordContent = function () {
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var dialogCnt = this.parent.createElement('div', { className: 'e-unprotectsheetpwd-dialog' });
            var pwdCnt = this.parent.createElement('div', { className: 'e-unprotectsheetpwd-content' });
            var textH = this.parent.createElement('div', { className: 'e-header' });
            textH.innerText = l10n.getConstant('EnterThePassword');
            var pwdInput = this.parent.createElement('input', { className: 'e-input e-text', attrs: { 'type': 'password' } });
            pwdCnt.appendChild(pwdInput);
            pwdCnt.insertBefore(textH, pwdInput);
            dialogCnt.appendChild(pwdCnt);
            return dialogCnt;
        };
        ProtectSheet.prototype.unprotectdlgOkClick = function (dialogInst) {
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var pwd = this.parent.element.querySelector('.e-unprotectpwd-dialog').
                getElementsByClassName('e-unprotectpwd-content')[0].querySelector('.e-input');
            if (this.parent.password === pwd.value) {
                dialogInst.hide();
                this.removeWorkbookProtection();
                this.parent.notify(event_1.completeAction, { action: 'protectWorkbook', eventArgs: { isProtected: false } });
            }
            else {
                var pwdSpan = this.parent.createElement('span', { className: 'e-unprotectpwd-alert-span' });
                pwdSpan.innerText = l10n.getConstant('UnprotectPasswordAlert');
                (this.parent.element.querySelector('.e-unprotectworkbook-dlg').querySelector('.e-dlg-content')).appendChild(pwdSpan);
            }
        };
        ProtectSheet.prototype.removeWorkbookProtection = function () {
            this.parent.password = '';
            this.parent.isProtected = false;
            Eif (this.parent.showSheetTabs) {
                this.parent.element.querySelector('.e-add-sheet-tab').removeAttribute('disabled');
                this.parent.element.querySelector('.e-add-sheet-tab').classList.remove('e-disabled');
            }
            var elem = document.getElementById(this.parent.element.id + '_protectworkbook');
            if (elem) {
                elem.classList.remove('e-active');
            }
            this.parent.notify(index_3.updateToggleItem, { props: 'Protectworkbook' });
        };
        ProtectSheet.prototype.unprotectSheetdlgOkClick = function (dialogInst, isImportedSheet) {
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var sheet = this.parent.getActiveSheet();
            var pwd = this.parent.element.querySelector('.e-unprotectsheetpwd-dialog').
                getElementsByClassName('e-unprotectsheetpwd-content')[0].querySelector('.e-input');
            Iif (isImportedSheet && sheet.password.length === 0) {
                var impArgs = {
                    sheetPassword: pwd.value,
                    sheetIndex: this.parent.activeSheetIndex
                };
                this.parent.open(impArgs);
            }
            else {
                if (sheet.password === pwd.value) {
                    dialogInst.hide();
                    this.unProtectSheetPassword();
                }
                else {
                    var pwdSpan = this.parent.createElement('span', { className: 'e-unprotectsheetpwd-alert-span' });
                    pwdSpan.innerText = l10n.getConstant('UnprotectPasswordAlert');
                    (this.parent.element.querySelector('.e-unprotectworksheet-dlg').querySelector('.e-dlg-content')).appendChild(pwdSpan);
                }
            }
        };
        ProtectSheet.prototype.unProtectSheetPassword = function () {
            var sheet = this.parent.getActiveSheet();
            var sheetIdx = this.parent.activeSheetIndex;
            this.parent.setSheetPropertyOnMute(sheet, 'isProtected', !sheet.isProtected);
            this.parent.setSheetPropertyOnMute(sheet, 'password', '');
            var isActive = sheet.isProtected ? false : true;
            this.parent.notify(event_1.applyProtect, { isActive: isActive, id: this.parent.element.id + '_protect', sheetIndex: sheetIdx, triggerEvent: true });
            Iif (this.parent.allowOpen && this.parent.openModule.isImportedFile &&
                this.parent.openModule.unProtectSheetIdx.indexOf(sheetIdx) === -1) {
                this.parent.openModule.unProtectSheetIdx.push(sheetIdx);
            }
        };
        ProtectSheet.prototype.getPassWord = function (args) {
            args.passWord = this.password;
        };
        ProtectSheet.prototype.importProtectWorkbook = function (fileArgs) {
            var _this = this;
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var dialogInst = this.parent.serviceLocator.getService(index_3.dialog);
            dialogInst.show({
                width: 323, isModal: true, showCloseIcon: true, cssClass: 'e-importprotectworkbook-dlg',
                header: l10n.getConstant('UnprotectWorkbook'),
                beforeOpen: function (args) {
                    var dlgArgs = {
                        dialogName: 'ImportProtectWorkbook',
                        element: args.element, target: args.target, cancel: args.cancel
                    };
                    _this.parent.trigger('dialogBeforeOpen', dlgArgs);
                    if (dlgArgs.cancel) {
                        args.cancel = true;
                    }
                    dialogInst.dialogInstance.content = _this.importProtectPasswordContent(fileArgs);
                    dialogInst.dialogInstance.dataBind();
                    _this.parent.element.focus();
                },
                buttons: [{
                        buttonModel: {
                            content: l10n.getConstant('Ok'), isPrimary: true, disabled: true
                        },
                        click: function () {
                            _this.alertMessage();
                            _this.importOkClick(fileArgs);
                        }
                    }]
            });
        };
        ProtectSheet.prototype.importProtectPasswordContent = function (args) {
            var l10n = this.parent.serviceLocator.getService(index_3.locale);
            var dialogElem = this.parent.createElement('div', { className: 'e-importprotectpwd-dialog' });
            var pwdCont = this.parent.createElement('div', { className: 'e-importprotectpwd-content' });
            var textSpan = this.parent.createElement('span', { className: 'e-header' });
            textSpan.innerText = '"' + args.file.name + '"' + ' ' + l10n.getConstant('IsProtected');
            var pwdInput = this.parent.createElement('input', { className: 'e-input e-text', attrs: { 'type': 'password' } });
            pwdInput.setAttribute('placeholder', l10n.getConstant('EnterThePassword'));
            pwdCont.appendChild(textSpan);
            pwdCont.appendChild(pwdInput);
            dialogElem.appendChild(pwdCont);
            return dialogElem;
        };
        ProtectSheet.prototype.importOkClick = function (args) {
            var pwd = this.parent.element.querySelector('.e-importprotectpwd-dialog').
                getElementsByClassName('e-importprotectpwd-content')[0].querySelector('.e-input');
            this.parent.password = pwd.value;
            var impArgs = {
                file: args.file,
                password: pwd.value
            };
            this.parent.open(impArgs);
        };
        ProtectSheet.prototype.toggleProtect = function () {
            var isActive;
            var parentId = this.parent.element.id;
            var sheet = this.parent.getActiveSheet();
            Iif (sheet.isProtected && this.parent.allowOpen && sheet.isImportProtected && this.parent.openModule.isImportedFile &&
                this.parent.openModule.unProtectSheetIdx.indexOf(this.parent.activeSheetIndex) === -1) {
                this.unProtectsheet(true);
            }
            else if (sheet.password && sheet.password.length > 0) {
                this.unProtectsheet();
            }
            else {
                this.parent.setSheetPropertyOnMute(sheet, 'isProtected', !sheet.isProtected);
                isActive = sheet.isProtected ? false : true;
                this.parent.notify(event_1.applyProtect, { isActive: isActive, id: parentId + '_protect', sheetIndex: this.parent.activeSheetIndex, triggerEvent: true });
            }
        };
        ProtectSheet.prototype.getModuleName = function () {
            return 'protectSheet';
        };
        return ProtectSheet;
    }());
    exports.ProtectSheet = ProtectSheet;
});