all files / spreadsheet/actions/ insert.js

88.41% Statements 61/69
79.55% Branches 35/44
100% Functions 9/9
88.41% Lines 61/69
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   120× 120×   20× 20×   20×   20× 20×     11× 11× 11×       11×     11×             11×   11×                                 20× 20×   14× 12× 12×     20× 20× 20× 20× 736× 12909× 12909×               120×   120× 120×   120×     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 Insert = (function () {
        function Insert(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        Insert.prototype.insert = function (args) {
            var isAction;
            if (args.isAction) {
                isAction = true;
                delete args.isAction;
            }
            if (isAction) {
                this.parent.notify(index_1.beginAction, { eventArgs: args, action: 'insert' });
            }
            this.parent.notify(index_2.beforeInsert, args);
            switch (args.modelType) {
                case 'Sheet':
                    this.parent.notify(index_1.insertSheetTab, { startIdx: args.index, endIdx: args.index + (args.model.length - 1), preventUpdate: !isAction });
                    this.parent.renderModule.refreshSheet();
                    index_1.focus(this.parent.element);
                    break;
                case 'Row':
                    Eif (!this.parent.scrollSettings.enableVirtualization || args.index <= this.parent.viewport.bottomIndex) {
                        Eif (this.parent.scrollSettings.enableVirtualization) {
                            Iif (args.freezePane) {
                                this.parent.renderModule.refreshSheet();
                                break;
                            }
                            Iif (args.index < 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, colIndex: this.parent.viewport.leftIndex, refresh: 'Row'
                            });
                        }
                        else {
                            this.parent.renderModule.refreshUI({ skipUpdateOnFirst: true, rowIndex: args.index, colIndex: 0, refresh: 'Row' });
                        }
                        this.parent.selectRange(this.parent.getActiveSheet().selectedRange);
                    }
                    break;
                case 'Column':
                    Eif (!this.parent.scrollSettings.enableVirtualization || args.index <= this.parent.viewport.rightIndex) {
                        Iif (args.freezePane) {
                            this.parent.renderModule.refreshSheet();
                            break;
                        }
                        Eif (this.parent.scrollSettings.enableVirtualization) {
                            Iif (args.index < 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, colIndex: this.parent.viewport.leftIndex, refresh: 'Column'
                            });
                        }
                        else {
                            this.parent.renderModule.refreshUI({
                                skipUpdateOnFirst: true, rowIndex: 0, colIndex: args.index, refresh: 'Column'
                            });
                        }
                        this.parent.selectRange(this.parent.getActiveSheet().selectedRange);
                    }
                    break;
            }
            this.refreshImgElement(args.model.length, this.parent.activeSheetIndex, args.modelType, args.index);
            if (isAction) {
                this.parent.notify(index_1.completeAction, { eventArgs: args, action: 'insert' });
            }
            else if (!args.isUndoRedo) {
                args.isMethod = true;
                this.parent.notify(index_2.triggerDataChange, { eventArgs: args, action: 'insert' });
            }
        };
        Insert.prototype.refreshImgElement = function (count, sheetIdx, modelType, index) {
            var sheet = this.parent.sheets[sheetIdx];
            var cellObj;
            var indexes = [0, 0, sheet.usedRange.rowIndex, sheet.usedRange.colIndex];
            for (var i = 0; i <= indexes[2]; i++) {
                for (var j = indexes[1]; j <= indexes[3]; j++) {
                    cellObj = index_3.getCell(i, j, sheet);
                    if (cellObj && cellObj.image && cellObj.image.length > 0) {
                        Eif ((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: 'insert'
                            });
                        }
                    }
                }
            }
        };
        Insert.prototype.addEventListener = function () {
            this.parent.on(index_2.insert, this.insert, this);
        };
        Insert.prototype.destroy = function () {
            this.removeEventListener();
            this.parent = null;
        };
        Insert.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(index_2.insert, this.insert);
            }
        };
        Insert.prototype.getModuleName = function () {
            return 'insert';
        };
        return Insert;
    }());
    exports.Insert = Insert;
});