all files / document/ pdf-document-template.js

76.09% Statements 70/92
52.5% Branches 21/40
60.61% Functions 20/33
76.09% Lines 70/92
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       110×                 110×                 110×                 110×                 38×                 38×                 38×                 38×                 72×                 72×                 72×                 72×               110×     110× 110× 110× 38×     72×   110×   110×     110× 110× 110× 38×     72×   110×   110×     110× 110× 110× 38×     72×   110×   110×     110× 110× 110× 38×     72×   110×   440× 440× 440×       440×   440× 440×                        
define(["require", "exports", "./../pages/enum"], function (require, exports, enum_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfDocumentTemplate = (function () {
        function PdfDocumentTemplate() {
        }
        Object.defineProperty(PdfDocumentTemplate.prototype, "left", {
            get: function () {
                return this.leftTemplate;
            },
            set: function (value) {
                this.leftTemplate = this.checkElement(value, enum_1.TemplateType.Left);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocumentTemplate.prototype, "top", {
            get: function () {
                return this.topTemplate;
            },
            set: function (value) {
                this.topTemplate = this.checkElement(value, enum_1.TemplateType.Top);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocumentTemplate.prototype, "right", {
            get: function () {
                return this.rightTemplate;
            },
            set: function (value) {
                this.rightTemplate = this.checkElement(value, enum_1.TemplateType.Right);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocumentTemplate.prototype, "bottom", {
            get: function () {
                return this.bottomTemplate;
            },
            set: function (value) {
                this.bottomTemplate = this.checkElement(value, enum_1.TemplateType.Bottom);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocumentTemplate.prototype, "EvenLeft", {
            get: function () {
                return this.evenLeft;
            },
            set: function (value) {
                this.evenLeft = this.checkElement(value, enum_1.TemplateType.Left);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocumentTemplate.prototype, "EvenTop", {
            get: function () {
                return this.evenTop;
            },
            set: function (value) {
                this.evenTop = this.checkElement(value, enum_1.TemplateType.Top);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocumentTemplate.prototype, "EvenRight", {
            get: function () {
                return this.evenRight;
            },
            set: function (value) {
                this.evenRight = this.checkElement(value, enum_1.TemplateType.Right);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocumentTemplate.prototype, "EvenBottom", {
            get: function () {
                return this.evenBottom;
            },
            set: function (value) {
                this.evenBottom = this.checkElement(value, enum_1.TemplateType.Bottom);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocumentTemplate.prototype, "OddLeft", {
            get: function () {
                return this.oddLeft;
            },
            set: function (value) {
                this.oddLeft = this.checkElement(value, enum_1.TemplateType.Left);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocumentTemplate.prototype, "OddTop", {
            get: function () {
                return this.oddTop;
            },
            set: function (value) {
                this.oddTop = this.checkElement(value, enum_1.TemplateType.Top);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocumentTemplate.prototype, "OddRight", {
            get: function () {
                return this.oddRight;
            },
            set: function (value) {
                this.oddRight = this.checkElement(value, enum_1.TemplateType.Right);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocumentTemplate.prototype, "OddBottom", {
            get: function () {
                return this.oddBottom;
            },
            set: function (value) {
                this.oddBottom = this.checkElement(value, enum_1.TemplateType.Bottom);
            },
            enumerable: true,
            configurable: true
        });
        PdfDocumentTemplate.prototype.getLeft = function (page) {
            Iif (page == null) {
                throw new Error('ArgumentNullException:page');
            }
            var template = null;
            var even = this.isEven(page);
            if (even) {
                template = (this.EvenLeft != null) ? this.EvenLeft : this.left;
            }
            else {
                template = (this.OddLeft != null) ? this.OddLeft : this.left;
            }
            return template;
        };
        PdfDocumentTemplate.prototype.getTop = function (page) {
            Iif (page == null) {
                throw new Error('ArgumentNullException:page');
            }
            var template = null;
            var even = this.isEven(page);
            if (even) {
                template = (this.EvenTop != null) ? this.EvenTop : this.top;
            }
            else {
                template = (this.OddTop != null) ? this.OddTop : this.top;
            }
            return template;
        };
        PdfDocumentTemplate.prototype.getRight = function (page) {
            Iif (page == null) {
                throw new Error('ArgumentNullException:page');
            }
            var template = null;
            var even = this.isEven(page);
            if (even) {
                template = (this.EvenRight != null) ? this.EvenRight : this.right;
            }
            else {
                template = (this.OddRight != null) ? this.OddRight : this.right;
            }
            return template;
        };
        PdfDocumentTemplate.prototype.getBottom = function (page) {
            Iif (page == null) {
                throw new Error('ArgumentNullException:page');
            }
            var template = null;
            var even = this.isEven(page);
            if (even) {
                template = (this.EvenBottom != null) ? this.EvenBottom : this.bottom;
            }
            else {
                template = (this.OddBottom != null) ? this.OddBottom : this.bottom;
            }
            return template;
        };
        PdfDocumentTemplate.prototype.isEven = function (page) {
            var pages = page.section.document.pages;
            var index = 0;
            Iif (pages.pageCollectionIndex.containsKey(page)) {
                index = pages.pageCollectionIndex.getValue(page) + 1;
            }
            else {
                index = pages.indexOf(page) + 1;
            }
            var even = ((index % 2) === 0);
            return even;
        };
        PdfDocumentTemplate.prototype.checkElement = function (templateElement, type) {
            if (templateElement != null) {
                if ((typeof templateElement.type !== 'undefined') && (templateElement.type !== enum_1.TemplateType.None)) {
                    throw new Error('NotSupportedException:Can not reassign the template element. Please, create new one.');
                }
                templateElement.type = type;
            }
            return templateElement;
        };
        return PdfDocumentTemplate;
    }());
    exports.PdfDocumentTemplate = PdfDocumentTemplate;
});