all files / document-editor/implementation/format/ cell-format.js

92.73% Statements 153/165
98.08% Branches 51/52
97.14% Functions 34/35
92.73% Lines 153/165
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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283   5345× 5345× 5345× 5345× 5345× 5345×     13602×     1930×           13105×     1929×           11930×     1931×           11975×     1932×           14189×     12722×           162605×     2499×           204023×     2589×           18794×     3519×           10973×     2458×           37402×     2502×         498759× 498759× 144503× 144503× 144503×     354256×   34011× 6957×   34011× 3278×     30733× 30733×   9622×   21111×     3278× 3278× 3278× 3278× 3278× 3278× 3278× 3278× 3278× 3278× 3278× 3278×   32780× 32780× 3278×     361213× 361213×   12784× 12784×   12807× 12807×   12818× 12818×   12890× 12890×   780× 780×   121032× 121032×   152372× 152372×   238× 238×   7314× 7314×   28178× 28178×   361213×   7613×         1761× 1744×   1761× 1744×   1761× 1628×   1761× 1761× 1761×   13× 13× 13× 13× 13× 13× 13× 13× 13× 13× 13× 13×   545557× 545396× 545396×   161×   1763× 1762× 1760× 1760× 1760× 1760× 1760× 1760× 1760× 1760× 1760× 1760×   1762× 1761× 1761×   1762× 1761× 1761×                                        
define(["require", "exports", "@syncfusion/ej2-base", "../../base/dictionary", "../../base/unique-format", "../../base/unique-formats", "./borders", "./shading"], function (require, exports, ej2_base_1, dictionary_1, unique_format_1, unique_formats_1, borders_1, shading_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WCellFormat = (function () {
        function WCellFormat(node) {
            this.uniqueCellFormat = undefined;
            this.borders = new borders_1.WBorders(this);
            this.shading = new shading_1.WShading(this);
            this.ownerBase = node;
            this.borders = new borders_1.WBorders(this);
            this.shading = new shading_1.WShading(this);
        }
        Object.defineProperty(WCellFormat.prototype, "leftMargin", {
            get: function () {
                return this.getPropertyValue('leftMargin');
            },
            set: function (value) {
                this.setPropertyValue('leftMargin', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "rightMargin", {
            get: function () {
                return this.getPropertyValue('rightMargin');
            },
            set: function (value) {
                this.setPropertyValue('rightMargin', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "topMargin", {
            get: function () {
                return this.getPropertyValue('topMargin');
            },
            set: function (value) {
                this.setPropertyValue('topMargin', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "bottomMargin", {
            get: function () {
                return this.getPropertyValue('bottomMargin');
            },
            set: function (value) {
                this.setPropertyValue('bottomMargin', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "cellWidth", {
            get: function () {
                return this.getPropertyValue('cellWidth');
            },
            set: function (value) {
                this.setPropertyValue('cellWidth', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "columnSpan", {
            get: function () {
                return this.getPropertyValue('columnSpan');
            },
            set: function (value) {
                this.setPropertyValue('columnSpan', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "rowSpan", {
            get: function () {
                return this.getPropertyValue('rowSpan');
            },
            set: function (value) {
                this.setPropertyValue('rowSpan', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "preferredWidth", {
            get: function () {
                return this.getPropertyValue('preferredWidth');
            },
            set: function (value) {
                this.setPropertyValue('preferredWidth', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "verticalAlignment", {
            get: function () {
                return this.getPropertyValue('verticalAlignment');
            },
            set: function (value) {
                this.setPropertyValue('verticalAlignment', value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(WCellFormat.prototype, "preferredWidthType", {
            get: function () {
                return this.getPropertyValue('preferredWidthType');
            },
            set: function (value) {
                this.setPropertyValue('preferredWidthType', value);
            },
            enumerable: true,
            configurable: true
        });
        WCellFormat.prototype.getPropertyValue = function (property) {
            var hasValue = this.hasValue(property);
            if (hasValue) {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(WCellFormat.uniqueFormatType, property);
                Eif (!ej2_base_1.isNullOrUndefined(this.uniqueCellFormat) && this.uniqueCellFormat.propertiesHash.containsKey(propertyType)) {
                    return this.uniqueCellFormat.propertiesHash.get(propertyType);
                }
            }
            return WCellFormat.getPropertyDefaultValue(property);
        };
        WCellFormat.prototype.setPropertyValue = function (property, value) {
            if (ej2_base_1.isNullOrUndefined(value) || value === '') {
                value = WCellFormat.getPropertyDefaultValue(property);
            }
            if (ej2_base_1.isNullOrUndefined(this.uniqueCellFormat)) {
                this.initializeUniqueCellFormat(property, value);
            }
            else {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(this.uniqueCellFormat.uniqueFormatType, property);
                if (this.uniqueCellFormat.propertiesHash.containsKey(propertyType) &&
                    this.uniqueCellFormat.propertiesHash.get(propertyType) === value) {
                    return;
                }
                this.uniqueCellFormat = WCellFormat.uniqueCellFormats.updateUniqueFormat(this.uniqueCellFormat, property, value);
            }
        };
        WCellFormat.prototype.initializeUniqueCellFormat = function (property, propValue) {
            var uniqueCellFormatTemp = new dictionary_1.Dictionary();
            this.addUniqueCellFormat('leftMargin', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('topMargin', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('bottomMargin', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('rightMargin', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('cellWidth', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('columnSpan', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('rowSpan', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('preferredWidth', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('verticalAlignment', property, propValue, uniqueCellFormatTemp);
            this.addUniqueCellFormat('preferredWidthType', property, propValue, uniqueCellFormatTemp);
            this.uniqueCellFormat = WCellFormat.uniqueCellFormats.addUniqueFormat(uniqueCellFormatTemp, WCellFormat.uniqueFormatType);
        };
        WCellFormat.prototype.addUniqueCellFormat = function (property, modifiedProperty, propValue, uniqueCellFormatTemp) {
            var propertyType = unique_format_1.WUniqueFormat.getPropertyType(WCellFormat.uniqueFormatType, property);
            if (property === modifiedProperty) {
                uniqueCellFormatTemp.add(propertyType, propValue);
            }
        };
        WCellFormat.getPropertyDefaultValue = function (property) {
            var value = undefined;
            switch (property) {
                case 'leftMargin':
                    value = undefined;
                    break;
                case 'topMargin':
                    value = undefined;
                    break;
                case 'bottomMargin':
                    value = undefined;
                    break;
                case 'rightMargin':
                    value = undefined;
                    break;
                case 'cellWidth':
                    value = 0;
                    break;
                case 'columnSpan':
                    value = 1;
                    break;
                case 'rowSpan':
                    value = 1;
                    break;
                case 'preferredWidth':
                    value = 0;
                    break;
                case 'verticalAlignment':
                    value = 'Top';
                    break;
                case 'preferredWidthType':
                    value = 'Point';
                    break;
            }
            return value;
        };
        WCellFormat.prototype.containsMargins = function () {
            return (!ej2_base_1.isNullOrUndefined(this.leftMargin)
                || !ej2_base_1.isNullOrUndefined(this.rightMargin)
                || !ej2_base_1.isNullOrUndefined(this.bottomMargin)
                || !ej2_base_1.isNullOrUndefined(this.topMargin));
        };
        WCellFormat.prototype.destroy = function () {
            if (!ej2_base_1.isNullOrUndefined(this.borders)) {
                this.borders.destroy();
            }
            if (!ej2_base_1.isNullOrUndefined(this.shading)) {
                this.shading.destroy();
            }
            if (!ej2_base_1.isNullOrUndefined(this.uniqueCellFormat)) {
                WCellFormat.uniqueCellFormats.remove(this.uniqueCellFormat);
            }
            this.uniqueCellFormat = undefined;
            this.borders = undefined;
            this.shading = undefined;
        };
        WCellFormat.prototype.cloneFormat = function () {
            var format = new WCellFormat(undefined);
            format.verticalAlignment = this.verticalAlignment;
            format.leftMargin = this.leftMargin;
            format.rightMargin = this.rightMargin;
            format.topMargin = this.topMargin;
            format.bottomMargin = this.bottomMargin;
            format.preferredWidth = this.preferredWidth;
            format.preferredWidthType = this.preferredWidthType;
            format.cellWidth = this.cellWidth;
            format.borders = ej2_base_1.isNullOrUndefined(this.borders) ? undefined : this.borders.cloneFormat();
            format.shading = ej2_base_1.isNullOrUndefined(this.shading) ? undefined : this.shading.cloneFormat();
            return format;
        };
        WCellFormat.prototype.hasValue = function (property) {
            if (!ej2_base_1.isNullOrUndefined(this.uniqueCellFormat)) {
                var propertyType = unique_format_1.WUniqueFormat.getPropertyType(this.uniqueCellFormat.uniqueFormatType, property);
                return this.uniqueCellFormat.propertiesHash.containsKey(propertyType);
            }
            return false;
        };
        WCellFormat.prototype.copyFormat = function (format) {
            if (!ej2_base_1.isNullOrUndefined(format)) {
                if (!ej2_base_1.isNullOrUndefined(format.uniqueCellFormat)) {
                    this.cellWidth = format.cellWidth;
                    this.leftMargin = format.leftMargin;
                    this.topMargin = format.topMargin;
                    this.rightMargin = format.rightMargin;
                    this.bottomMargin = format.bottomMargin;
                    this.preferredWidth = format.preferredWidth;
                    this.columnSpan = format.columnSpan;
                    this.rowSpan = format.rowSpan;
                    this.preferredWidthType = format.preferredWidthType;
                    this.verticalAlignment = format.verticalAlignment;
                }
                if (!ej2_base_1.isNullOrUndefined(format.shading)) {
                    this.shading = new shading_1.WShading(this);
                    this.shading.copyFormat(format.shading);
                }
                if (!ej2_base_1.isNullOrUndefined(format.borders)) {
                    this.borders = new borders_1.WBorders(this);
                    this.borders.copyFormat(format.borders);
                }
            }
        };
        WCellFormat.prototype.initializeCellBorders = function () {
            this.borders.left.lineStyle = 'Single';
            this.borders.left.lineWidth = 0.5;
            this.borders.right.lineStyle = 'Single';
            this.borders.right.lineWidth = 0.5;
            this.borders.top.lineStyle = 'Single';
            this.borders.top.lineWidth = 0.5;
            this.borders.bottom.lineStyle = 'Single';
            this.borders.bottom.lineWidth = 0.5;
            this.borders.horizontal.lineStyle = 'Single';
            this.borders.horizontal.lineWidth = 0.5;
            this.borders.vertical.lineStyle = 'Single';
            this.borders.vertical.lineWidth = 0.5;
        };
        WCellFormat.clear = function () {
            this.uniqueCellFormats.clear();
        };
        WCellFormat.uniqueCellFormats = new unique_formats_1.WUniqueFormats();
        WCellFormat.uniqueFormatType = 4;
        return WCellFormat;
    }());
    exports.WCellFormat = WCellFormat;
});