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

93.44% Statements 57/61
80% Branches 28/35
100% Functions 15/15
93.1% Lines 54/58
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          14×   14× 14×                       14×                                                                                               53× 53× 53×            
/* 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.PROTECT_GROUP = '_protect_group';
    exports.PROTECT_DOCUMENT_ID = '_protect_document';
    exports.READ_ONLY_ID = '_read_only';
    exports.RESTRICT_EDITING_ID = '_restrict_editing';
    var ProtectGroup = (function (_super) {
        __extends(ProtectGroup, _super);
        function ProtectGroup(container) {
            return _super.call(this, container) || this;
        }
        ProtectGroup.prototype.getGroupModel = function () {
            var locale = this.localObj;
            var protectItems = [
                {
                    id: this.ribbonId + exports.PROTECT_DOCUMENT_ID + '_readonly',
                    text: locale.getConstant('Read Only'),
                    iconCss: 'e-icons e-de-read-only'
                },
                {
                    id: this.ribbonId + exports.PROTECT_DOCUMENT_ID + '_restrict',
                    text: locale.getConstant('Restrict Editing'),
                    iconCss: 'e-icons e-de-restrict-edit'
                }
            ];
            return {
                id: this.ribbonId + exports.PROTECT_GROUP,
                header: locale.getConstant('Protect'),
                orientation: 'Rows',
                keyTip: 'ZR',
                enableGroupOverflow: true,
                overflowHeader: locale.getConstant('Protect'),
                collections: [
                    {
                        items: [
                            {
                                id: this.ribbonId + exports.PROTECT_DOCUMENT_ID,
                                type: 'DropDown',
                                dropDownSettings: {
                                    content: locale.getConstant('Protect Document'),
                                    items: protectItems,
                                    iconCss: 'e-icons e-de-ctnr-lock',
                                    select: this.protectDocumentDropdownHandler.bind(this),
                                    beforeItemRender: this.onBeforeRenderProtectDropdown.bind(this)
                                },
                                ribbonTooltipSettings: {
                                    title: locale.getConstant('Protect Document'),
                                    content: locale.getConstant('Control what types of changes can be made to the document')
                                }
                            }
                        ]
                    }
                ]
            };
        };
        ProtectGroup.prototype.protectDocumentDropdownHandler = function (args) {
            var id = args.item.id;
            Eif (args.item && id) {
                if (id === this.ribbonId + exports.PROTECT_DOCUMENT_ID + '_readonly') {
                    this.container.restrictEditing = !this.container.restrictEditing;
                    this.updateReadOnlyIcon(args.element);
                }
                else Eif (id === this.ribbonId + exports.PROTECT_DOCUMENT_ID + '_restrict') {
                    this.documentEditor.documentHelper.restrictEditingPane.showHideRestrictPane(true);
                }
            }
        };
        ProtectGroup.prototype.onBeforeRenderProtectDropdown = function (args) {
            var selectedIcon = args.element.getElementsByClassName('e-menu-icon')[0];
            Iif (!selectedIcon) {
                return;
            }
            if (args.item.id === this.ribbonId + exports.PROTECT_DOCUMENT_ID + '_readonly') {
                this.toggleSelectedIcon(selectedIcon, this.documentEditor.isReadOnly);
            }
            else Eif (args.item.id === this.ribbonId + exports.PROTECT_DOCUMENT_ID + '_restrict') {
                var restrictPane = document.getElementsByClassName('e-de-restrict-pane')[0];
                Iif (restrictPane) {
                    var isRestrictPaneVisible = !(restrictPane.style.display === 'none');
                    this.toggleSelectedIcon(selectedIcon, isRestrictPaneVisible);
                }
            }
        };
        ProtectGroup.prototype.updateReadOnlyIcon = function (menuElement) {
            var selectedIcon = menuElement.getElementsByClassName('e-menu-icon')[0];
            Eif (selectedIcon) {
                this.toggleSelectedIcon(selectedIcon, this.documentEditor.isReadOnly);
            }
        };
        ProtectGroup.prototype.toggleSelectedIcon = function (icon, isSelected) {
            if (isSelected) {
                icon.classList.add('e-de-selected-item');
            }
            else {
                icon.classList.remove('e-de-selected-item');
            }
        };
        ProtectGroup.prototype.updateSelection = function () {
            var isReadOnly = this.documentEditor.isReadOnly;
            var readOnlyElement = document.getElementById(this.ribbonId + exports.READ_ONLY_ID);
            Iif (readOnlyElement) {
                readOnlyElement.classList.toggle('e-active', isReadOnly);
            }
        };
        return ProtectGroup;
    }(ribbon_interfaces_1.RibbonGroupBase));
    exports.ProtectGroup = ProtectGroup;
});