all files / spreadsheet/actions/ delete.js

83.1% Statements 59/71
60.34% Branches 35/58
100% Functions 9/9
83.1% Lines 59/71
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   119× 119×                                                                                           262× 4346× 4346×                   119×   119× 119×   119×     18525×        
define(["require", "exports", "../common/index", "../../workbook/common/index", "../../workbook/index"], function (require, exports, index_1, index_2, index_3) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Delete = (function () {
        function Delete(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        Delete.prototype.delete = function (args) {
            var isAction;
            if (args.isAction) {
                isAction = true;
                delete args.isAction;
            }
            if (isAction) {
                this.parent.notify(index_1.beginAction, { eventArgs: args, action: 'delete' });
            }
            if (args.modelType === 'Sheet') {
                var activeSheetDeleted = args.activeSheetIndex >= args.startIndex && args.activeSheetIndex <= args.endIndex;
                Iif (activeSheetDeleted) {
                    this.parent.setProperties({ activeSheetIndex: this.parent.skipHiddenSheets(args.startIndex < this.parent.sheets.length ? args.startIndex :
                            (args.startIndex ? args.startIndex - 1 : 0)) }, true);
                }
                this.parent.notify(index_1.refreshSheetTabs, null);
                Iif (activeSheetDeleted) {
                    this.parent.renderModule.refreshSheet();
                }
                index_1.focus(this.parent.element);
            }
            else if (args.modelType === 'Row') {
                Eif (!this.parent.scrollSettings.enableVirtualization || args.startIndex <= this.parent.viewport.bottomIndex) {
                    Iif (args.freezePane) {
                        this.parent.renderModule.refreshSheet();
                    }
                    else Eif (this.parent.scrollSettings.enableVirtualization) {
                        Iif (args.startIndex < this.parent.viewport.topIndex) {
                            this.parent.viewport.topIndex -= args.model.length;
                        }
                        this.parent.renderModule.refreshUI({
                            skipUpdateOnFirst: this.parent.viewport.topIndex === index_1.skipHiddenIdx(this.parent.getActiveSheet(), 0, true), rowIndex: this.parent.viewport.topIndex, refresh: 'Row',
                            colIndex: this.parent.viewport.leftIndex
                        });
                        this.parent.selectRange(this.parent.getActiveSheet().selectedRange);
                    }
                    else {
                        this.parent.renderModule.refreshUI({ skipUpdateOnFirst: true, refresh: 'Row', rowIndex: args.startIndex, colIndex: 0 });
                        this.parent.selectRange(this.parent.getActiveSheet().selectedRange);
                    }
                }
            }
            else {
                Eif (args.refreshSheet !== false && (!this.parent.scrollSettings.enableVirtualization ||
                    args.startIndex <= this.parent.viewport.rightIndex)) {
                    Iif (args.freezePane || args.refreshSheet === true) {
                        this.parent.renderModule.refreshSheet();
                    }
                    else Eif (this.parent.scrollSettings.enableVirtualization) {
                        Iif (args.startIndex < this.parent.viewport.leftIndex) {
                            this.parent.viewport.leftIndex -= args.model.length;
                        }
                        this.parent.renderModule.refreshUI({
                            skipUpdateOnFirst: this.parent.viewport.leftIndex === index_1.skipHiddenIdx(this.parent.getActiveSheet(), 0, true, 'columns'), rowIndex: this.parent.viewport.topIndex, refresh: 'Column',
                            colIndex: this.parent.viewport.leftIndex, insertDelete: true
                        });
                        this.parent.selectRange(this.parent.getActiveSheet().selectedRange);
                    }
                    else {
                        this.parent.renderModule.refreshUI({
                            skipUpdateOnFirst: true, refresh: 'Column', rowIndex: 0,
                            colIndex: args.startIndex, insertDelete: true
                        });
                        this.parent.selectRange(this.parent.getActiveSheet().selectedRange);
                    }
                }
                delete args.refreshSheet;
            }
            this.refreshImgElement(args.deletedModel.length, this.parent.activeSheetIndex, args.modelType, args.startIndex);
            if (isAction) {
                this.parent.notify(index_1.completeAction, { eventArgs: args, action: 'delete' });
            }
            else if (!args.isUndoRedo) {
                args.isMethod = true;
                this.parent.notify(index_2.triggerDataChange, { eventArgs: args, action: 'delete' });
            }
        };
        Delete.prototype.refreshImgElement = function (count, sheetIdx, modelType, index) {
            var sheet = this.parent.sheets[sheetIdx];
            var cell;
            var address = [0, 0, sheet.usedRange.rowIndex, sheet.usedRange.colIndex];
            for (var i = 0; i <= address[2]; i++) {
                for (var j = address[1]; j <= address[3]; j++) {
                    cell = index_3.getCell(i, j, sheet);
                    Iif (cell && cell.image && cell.image.length > 0) {
                        if ((modelType === 'Row' && i >= index) || (modelType === 'Column' && j >= index)) {
                            this.parent.notify(index_1.refreshImagePosition, {
                                rowIdx: i, colIdx: j, sheetIdx: sheetIdx, type: modelType, count: count, status: 'delete'
                            });
                        }
                    }
                }
            }
        };
        Delete.prototype.addEventListener = function () {
            this.parent.on(index_2.deleteAction, this.delete, this);
        };
        Delete.prototype.destroy = function () {
            this.removeEventListener();
            this.parent = null;
        };
        Delete.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(index_2.deleteAction, this.delete);
            }
        };
        Delete.prototype.getModuleName = function () {
            return 'delete';
        };
        return Delete;
    }());
    exports.Delete = Delete;
});