all files / document-editor-container/ribbon/review-tab/ comments-group.js

96.43% Statements 81/84
81.82% Branches 36/44
100% Functions 18/18
96.3% Lines 78/81
11 statements, 6 functions, 9 branches Ignored     
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          14× 14× 14×   14× 14×                                                                                                                                                                                                                         53× 53× 53× 53× 53×   53×         10×   43× 43×   53× 28× 28× 28× 28× 28×     25× 25× 25× 25×     28× 28×       28×       43× 43× 37×              
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "../ribbon-interfaces"], function (require, exports, ribbon_interfaces_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.COMMENTS_GROUP = '_comments_group';
    exports.NEW_COMMENT_ID = '_new_comment';
    exports.PREVIOUS_COMMENT_ID = '_previous_comment';
    exports.NEXT_COMMENT_ID = '_next_comment';
    exports.DELETE_COMMENT_ID = '_delete_comment';
    exports.DELETE_ALL_COMMENTS_ID = '_delete_all_comments';
    exports.SHOW_COMMENTS_ID = '_show_comments';
    var CommentsGroup = (function (_super) {
        __extends(CommentsGroup, _super);
        function CommentsGroup(container) {
            var _this = _super.call(this, container) || this;
            _this.showComments = true;
            return _this;
        }
        CommentsGroup.prototype.getGroupModel = function () {
            var locale = this.localObj;
            return {
                id: this.ribbonId + exports.COMMENTS_GROUP,
                header: locale.getConstant('Comments'),
                enableGroupOverflow: true,
                overflowHeader: locale.getConstant('Comments'),
                collections: [{
                        items: [
                            {
                                id: this.ribbonId + exports.NEW_COMMENT_ID,
                                type: 'Button',
                                keyTip: 'C',
                                buttonSettings: {
                                    content: locale.getConstant('New Comment'),
                                    iconCss: 'e-icons e-de-cnt-cmt-add',
                                    isToggle: false,
                                    clicked: this.newCommentHandler.bind(this)
                                },
                                ribbonTooltipSettings: {
                                    content: locale.getConstant('Insert a comment at the cursor position')
                                }
                            }
                        ]
                    }, {
                        items: [
                            {
                                id: this.ribbonId + exports.PREVIOUS_COMMENT_ID,
                                type: 'Button',
                                keyTip: 'V',
                                buttonSettings: {
                                    content: locale.getConstant('Previous'),
                                    iconCss: 'e-icons e-de-ctnr-previous-comment',
                                    isToggle: false,
                                    clicked: this.previousCommentHandler.bind(this)
                                },
                                ribbonTooltipSettings: {
                                    content: locale.getConstant('Go to the previous comment')
                                }
                            },
                            {
                                id: this.ribbonId + exports.NEXT_COMMENT_ID,
                                type: 'Button',
                                keyTip: 'N',
                                buttonSettings: {
                                    content: locale.getConstant('Next'),
                                    iconCss: 'e-icons e-de-ctnr-next-comment',
                                    isToggle: false,
                                    clicked: this.nextCommentHandler.bind(this)
                                },
                                ribbonTooltipSettings: {
                                    content: locale.getConstant('Go to the next comment')
                                }
                            }
                        ]
                    }, {
                        items: [
                            {
                                id: this.ribbonId + exports.SHOW_COMMENTS_ID,
                                type: 'Button',
                                keyTip: 'K',
                                buttonSettings: {
                                    content: locale.getConstant('Show Comments'),
                                    iconCss: 'e-comment-show e-icons',
                                    isToggle: true,
                                    clicked: this.showCommentsHandler.bind(this)
                                },
                                ribbonTooltipSettings: {
                                    content: locale.getConstant('Show or hide comments')
                                }
                            },
                            {
                                id: this.ribbonId + exports.DELETE_COMMENT_ID,
                                type: 'DropDown',
                                keyTip: 'D',
                                dropDownSettings: {
                                    content: locale.getConstant('Delete'),
                                    items: [
                                        {
                                            id: this.ribbonId + exports.DELETE_COMMENT_ID + '_delete',
                                            text: locale.getConstant('Delete'),
                                            iconCss: 'e-icons e-de-ctnr-close-comment'
                                        },
                                        {
                                            id: this.ribbonId + exports.DELETE_ALL_COMMENTS_ID,
                                            text: locale.getConstant('Delete All'),
                                            iconCss: 'e-icons e-de-ctnr-delete-all-comments'
                                        }
                                    ],
                                    iconCss: 'e-icons e-de-ctnr-close-comment',
                                    select: this.deleteCommentDropdownHandler.bind(this)
                                },
                                ribbonTooltipSettings: {
                                    content: locale.getConstant('Delete comments')
                                }
                            }
                        ]
                    }]
            };
        };
        CommentsGroup.prototype.newCommentHandler = function () {
            this.container.documentEditor.editorModule.isUserInsert = true;
            this.container.documentEditor.editorModule.insertComment('');
            this.container.documentEditor.editorModule.isUserInsert = false;
        };
        CommentsGroup.prototype.previousCommentHandler = function () {
            this.documentEditor.selection.navigatePreviousComment();
        };
        CommentsGroup.prototype.nextCommentHandler = function () {
            this.documentEditor.selection.navigateNextComment();
        };
        CommentsGroup.prototype.deleteCommentDropdownHandler = function (args) {
            var item = args.item;
            Eif (item && item.id) {
                Eif (item.id === this.ribbonId + exports.DELETE_ALL_COMMENTS_ID) {
                    this.documentEditor.editor.deleteAllComments();
                }
                else if (item.id === this.ribbonId + exports.DELETE_COMMENT_ID + '_delete') {
                    this.documentEditor.editor.deleteComment();
                }
            }
        };
        CommentsGroup.prototype.showCommentsHandler = function () {
            this.showComments = !this.showComments;
            this.documentEditor.showComments = this.showComments;
            var showCommentsElement = document.getElementById(this.ribbonId + exports.SHOW_COMMENTS_ID);
            Eif (showCommentsElement) {
                showCommentsElement.classList.toggle('e-active', this.showComments);
            }
        };
        CommentsGroup.prototype.updateSelection = function () {
            var hasComments = this.documentEditor.documentHelper.comments.length > 0;
            var isCommentSelected = this.documentEditor.documentHelper.currentSelectedComment !== undefined;
            var ribbon = this.container.ribbon.ribbon;
            var currentContext = this.documentEditor.selection.contextType;
            var isInHeaderFooter = currentContext.indexOf('Header') >= 0
                || currentContext.indexOf('Footer') >= 0;
            if (isInHeaderFooter
                || this.container.documentEditor.selection.isinEndnote
                || this.container.documentEditor.selection.isinFootnote
                || this.container.documentEditor.commentReviewPane.commentPane.isEditMode
                || !this.container.enableComment) {
                ribbon.disableGroup(this.ribbonId + exports.COMMENTS_GROUP);
            }
            else Eif (!this.container.restrictEditing) {
                ribbon.enableGroup(this.ribbonId + exports.COMMENTS_GROUP);
            }
            if (hasComments && this.container.enableComment) {
                ribbon.enableItem(this.ribbonId + exports.PREVIOUS_COMMENT_ID);
                ribbon.enableItem(this.ribbonId + exports.NEXT_COMMENT_ID);
                ribbon.enableItem(this.ribbonId + exports.DELETE_COMMENT_ID);
                ribbon.enableItem(this.ribbonId + exports.SHOW_COMMENTS_ID);
                this.updateDeleteMenuItemState(ribbon.getItem(this.ribbonId + exports.DELETE_COMMENT_ID), isCommentSelected);
            }
            else {
                ribbon.disableItem(this.ribbonId + exports.PREVIOUS_COMMENT_ID);
                ribbon.disableItem(this.ribbonId + exports.NEXT_COMMENT_ID);
                ribbon.disableItem(this.ribbonId + exports.DELETE_COMMENT_ID);
                ribbon.disableItem(this.ribbonId + exports.SHOW_COMMENTS_ID);
            }
        };
        CommentsGroup.prototype.updateDeleteMenuItemState = function (dropDownItem, isCommentSelected) {
            Eif (dropDownItem) {
                Iif (!isCommentSelected) {
                    dropDownItem.dropDownSettings.items[0].disabled = true;
                }
                else {
                    dropDownItem.dropDownSettings.items[0].disabled = false;
                }
            }
        };
        CommentsGroup.prototype.enableDisableCommentGroup = function (enable) {
            var ribbon = this.container.ribbon.ribbon;
            if (enable) {
                ribbon.enableGroup(this.ribbonId + exports.COMMENTS_GROUP);
            }
            else {
                ribbon.disableGroup(this.ribbonId + exports.COMMENTS_GROUP);
            }
        };
        return CommentsGroup;
    }(ribbon_interfaces_1.RibbonGroupBase));
    exports.CommentsGroup = CommentsGroup;
});