all files / spreadsheet/services/ action-events.js

65.75% Statements 48/73
88.64% Branches 39/44
43.75% Functions 7/16
65.75% Lines 48/73
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   885× 885×                                                                               8145× 8145× 8145× 8145× 265× 265×   8145× 146× 146×   8145× 8145× 8145×       789×   8145× 6821×   8145× 265×   8145× 146×     8150× 8150× 8150× 8150× 8150×   8150× 7652×   8150×   885× 885× 885×   885× 885× 885×        
define(["require", "exports", "../../workbook/index", "../../workbook/index", "../common/index", "../common/index"], function (require, exports, index_1, index_2, index_3, index_4) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ActionEvents = (function () {
        function ActionEvents(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        ActionEvents.prototype.initializeActionBegin = function () {
            var _this = this;
            var cellFormat = this.parent.beforeCellFormat;
            this.parent.beforeCellFormat = function (args) {
                _this.actionEventHandler({ evtArgs: args, evtFunc: cellFormat, actionType: 'begin', eventType: 'format' });
            };
            var beforeOpen = this.parent.beforeOpen;
            this.parent.beforeOpen = function (args) {
                _this.actionEventHandler({ evtArgs: args, evtFunc: beforeOpen, actionType: 'begin', eventType: 'beforeOpen' });
            };
            var beforeSave = this.parent.beforeSave;
            this.parent.beforeSave = function (args) {
                _this.actionEventHandler({ evtArgs: args, evtFunc: beforeSave, actionType: 'begin', eventType: 'beforeSave' });
            };
            var beforeSort = this.parent.beforeSort;
            this.parent.beforeSort = function (args) {
                _this.actionEventHandler({ evtArgs: args, evtFunc: beforeSort, actionType: 'begin', eventType: 'beforeSort' });
            };
        };
        ActionEvents.prototype.initializeActionComplete = function () {
            var _this = this;
            var sortComplete = this.parent.sortComplete;
            this.parent.sortComplete = function (args) {
                _this.actionEventHandler({ evtArgs: args, evtFunc: sortComplete, actionType: 'complete', eventType: 'sorting' });
            };
            var cellSave = this.parent.cellSave;
            this.parent.cellSave = function (args) {
                _this.actionEventHandler({ evtArgs: args, evtFunc: cellSave, actionType: 'complete', eventType: 'cellSave' });
            };
        };
        ActionEvents.prototype.actionEventHandler = function (args) {
            if (args.evtFunc) {
                args.evtFunc.apply(this, [args]);
            }
            if (args.actionType === 'begin') {
                this.actionBeginHandler({ eventArgs: args.evtArgs, action: args.eventType });
            }
            else {
                this.actionCompleteHandler({ eventArgs: args.evtArgs, action: args.eventType });
            }
        };
        ActionEvents.prototype.actionBeginHandler = function (args) {
            var preventAction = args.preventAction;
            delete args.preventAction;
            var actionArgs = { action: args.action };
            if (args.isUndo) {
                actionArgs.isUndo = true;
                delete args.isUndo;
            }
            if (args.isRedo) {
                actionArgs.isUndo = false;
                delete args.isRedo;
            }
            actionArgs.args = args;
            this.parent.trigger('actionBegin', actionArgs);
            if (!preventAction && !this.parent.isPrintingProcessing && (args.action === 'clipboard' || args.action === 'format' ||
                args.action === 'cellSave' || args.action === 'addNote' || args.action === 'editNote' || args.action === 'deleteNote' || args.action === 'beforeWrap' || args.action === 'beforeReplace' || args.action === 'filter'
                || args.action === 'beforeClear' || args.action === 'beforeInsertImage' || args.action === 'beforeInsertChart' || args.action === 'chartDesign'
                || args.action === 'cellDelete' || args.action === 'autofill' || args.action === 'removeValidation' || args.action === 'hyperlink' || args.action === 'removeHyperlink' || args.action === 'deleteImage')) {
                this.parent.notify(index_4.setActionData, { args: args });
            }
            if (preventAction) {
                args.preventAction = true;
            }
            if (actionArgs.isUndo) {
                args.isUndo = true;
            }
            if (actionArgs.isUndo === false) {
                args.isRedo = true;
            }
        };
        ActionEvents.prototype.actionCompleteHandler = function (args) {
            var preventAction = args.preventAction;
            delete args.preventAction;
            this.parent.notify(index_1.triggerDataChange, args);
            Eif (!args.preventEventTrigger) {
                this.parent.trigger('actionComplete', args);
            }
            if (!preventAction && args.action !== 'undoRedo' && args.action !== 'gotoSheet') {
                this.parent.notify(index_4.updateUndoRedoCollection, { args: args });
            }
            this.parent.notify(index_3.positionAutoFillElement, null);
        };
        ActionEvents.prototype.addEventListener = function () {
            this.parent.on(index_3.completeAction, this.actionCompleteHandler, this);
            this.parent.on(index_2.beginAction, this.actionBeginHandler, this);
            this.parent.on(index_4.spreadsheetDestroyed, this.removeEventListener, this);
        };
        ActionEvents.prototype.removeEventListener = function () {
            this.parent.off(index_3.completeAction, this.actionCompleteHandler);
            this.parent.off(index_2.beginAction, this.actionBeginHandler);
            this.parent.off(index_4.spreadsheetDestroyed, this.removeEventListener);
        };
        return ActionEvents;
    }());
    exports.ActionEvents = ActionEvents;
});