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

100% Statements 59/59
95.45% Branches 21/22
100% Functions 12/12
100% Lines 59/59
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   1216× 1216×   78× 78× 78× 78× 78×         78× 13× 13× 13×     78× 78× 78× 323× 203×       14× 14× 14×   14× 14× 14× 14× 14×   1213× 1213×   1216× 1216× 1216×   1213× 24× 24× 24×     38× 38× 38× 38× 38×     38× 1226× 8772×     38× 37×     175974×        
define(["require", "exports", "../base/index", "../common/index", "../common/index", "../common/index", "../common/index", "@syncfusion/ej2-base"], function (require, exports, index_1, index_2, index_3, index_4, index_5, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WorkbookProtectSheet = (function () {
        function WorkbookProtectSheet(workbook) {
            this.parent = workbook;
            this.addEventListener();
        }
        WorkbookProtectSheet.prototype.protectsheetHandler = function (args) {
            var _this = this;
            var sheetIndex = ej2_base_1.isNullOrUndefined(args.sheetIndex) ? this.parent.activeSheetIndex : args.sheetIndex;
            var sheet = index_1.getSheet(this.parent, sheetIndex);
            this.parent.setSheetPropertyOnMute(sheet, 'isProtected', true);
            this.parent.setSheetPropertyOnMute(sheet, 'protectSettings', {
                selectCells: args.protectSettings.selectCells, formatCells: args.protectSettings.formatCells,
                formatColumns: args.protectSettings.formatColumns, formatRows: args.protectSettings.formatRows,
                insertLink: args.protectSettings.insertLink, selectUnLockedCells: args.protectSettings.selectUnLockedCells
            });
            if (args.password && args.password.length > 0) {
                index_2.generateHashSaltValue(args.password).then(function (res) {
                    _this.parent.setSheetPropertyOnMute(sheet, 'hashValue', res.hashValue);
                    _this.parent.setSheetPropertyOnMute(sheet, 'saltValue', res.saltValue);
                });
            }
            this.parent.notify(index_3.protectSheetWorkBook, { sheetIndex: sheetIndex, triggerEvent: args.triggerEvent });
            this.parent.notify(index_3.updateToggle, { props: 'Protect' });
            sheet.columns.forEach(function (column) {
                if (column && ej2_base_1.isUndefined(column.isLocked)) {
                    column.isLocked = true;
                }
            });
        };
        WorkbookProtectSheet.prototype.unprotectsheetHandler = function (args) {
            var sheet = this.parent.getActiveSheet();
            Eif (!ej2_base_1.isNullOrUndefined(args.sheet)) {
                sheet = this.parent.sheets[args.sheet];
            }
            sheet.protectSettings.formatCells = sheet.protectSettings.formatColumns = false;
            sheet.protectSettings.formatRows = sheet.protectSettings.selectCells = false;
            this.parent.setSheetPropertyOnMute(sheet, 'isProtected', false);
            this.parent.notify(index_3.protectSheetWorkBook, sheet.protectSettings);
            this.parent.notify(index_3.updateToggle, { props: 'Protect' });
        };
        WorkbookProtectSheet.prototype.destroy = function () {
            this.removeEventListener();
            this.parent = null;
        };
        WorkbookProtectSheet.prototype.addEventListener = function () {
            this.parent.on(index_3.protectsheetHandler, this.protectsheetHandler, this);
            this.parent.on(index_4.unprotectsheetHandler, this.unprotectsheetHandler, this);
            this.parent.on(index_3.setLockCells, this.lockCells, this);
        };
        WorkbookProtectSheet.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(index_3.protectsheetHandler, this.protectsheetHandler);
                this.parent.off(index_3.setLockCells, this.lockCells);
                this.parent.off(index_4.unprotectsheetHandler, this.unprotectsheetHandler);
            }
        };
        WorkbookProtectSheet.prototype.lockCells = function (args) {
            var addressInfo = this.parent.getAddressInfo(args.range);
            var indexes = index_5.getSwapRange(addressInfo.indices);
            var sheet = index_1.getSheet(this.parent, addressInfo.sheetIndex);
            var isLocked = args.isLocked ? args.isLocked : false;
            if (indexes[0] === 0 && indexes[2] === sheet.rowCount - 1) {
                for (var i = indexes[1]; i <= indexes[3]; i++) {
                    index_1.setColumn(sheet, i, { isLocked: args.isLocked });
                }
            }
            for (var i = indexes[0]; i <= indexes[2]; i++) {
                for (var j = indexes[1]; j <= indexes[3]; j++) {
                    index_1.setCell(i, j, sheet, { isLocked: isLocked }, true);
                }
            }
            if (args.triggerEvent) {
                this.parent.notify('actionComplete', { action: 'lockCells', eventArgs: args });
            }
        };
        WorkbookProtectSheet.prototype.getModuleName = function () {
            return 'workbookProtectSheet';
        };
        return WorkbookProtectSheet;
    }());
    exports.WorkbookProtectSheet = WorkbookProtectSheet;
});