all files / diagram/load-utility/ modelProperties.js

98.21% Statements 220/224
90% Branches 90/100
100% Functions 25/25
98.21% Lines 220/224
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 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360   1308× 1308× 1308× 1308× 1308× 1308× 1308×   26× 26× 26× 26× 26× 25×       26× 16×     10×   26× 26× 26×   26× 26× 26× 26× 26× 19×       26× 26× 26×         26×   26× 26× 26× 26× 26× 26× 26× 26× 26× 26× 26×   26× 25×         26× 25×         26× 26×       26× 26× 26× 26× 26× 26×             26× 26× 26× 26× 26× 26× 26× 26× 26× 26× 26×                 26× 26× 26× 26×   52× 52× 52× 52× 52× 52× 52×   26× 26× 26× 26× 26× 26× 26×     26× 26× 25×   26× 25×   26× 25×   26× 25×   26× 25×   26× 25×   26×   52× 52× 52× 52× 52× 52×   26×                           26×                     26× 26× 26× 26× 26×     26× 26×       26×   26×         26×                                 26×   22×   21×     26× 26× 26× 26× 26× 26× 26× 26× 26× 26× 26× 26×   26× 26× 25×   26× 25×   26× 25×   26×     26× 25×   26×   26× 26× 25×   26× 25×   26× 25×   26×     26× 25×   26× 25×   26× 25×   26× 25×   26× 25×   26×     26×   26× 26× 23×   26× 23×   26×   26×   26×   26×     46813×        
define(["require", "exports", "../enum/enum", "./connectorProperties", "./labelProperties", "./nodeProperties", "./portProperties"], function (require, exports, enum_1, connectorProperties_1, labelProperties_1, nodeProperties_1, portProperties_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Ej1Serialization = (function () {
        function Ej1Serialization(diagram) {
            this.labelProperties = new labelProperties_1.LabelProperties(this);
            this.connectorProperties = new connectorProperties_1.ConnectorProperties(this.labelProperties);
            this.portProperties = new portProperties_1.PortProperties(this);
            this.nodeProperties = new nodeProperties_1.NodeProperties(this.labelProperties, this.portProperties);
            this.convertedData = {};
            this.items = [];
            this.diagram = diagram;
        }
        Ej1Serialization.prototype.getSerializedData = function (data) {
            this.convertedData.mode = 'SVG';
            this.convertedData.basicElements = [];
            this.convertedData.width = data.width;
            this.convertedData.height = data.height;
            if (data.nodes && data.nodes.length > 0) {
                this.nodeProperties.renderNodesCollection(this.convertedData, data);
            }
            else {
                this.convertedData.nodes = data.nodes;
            }
            if (data.connectors && data.connectors.length > 0) {
                this.connectorProperties.renderConnectorsCollection(this.convertedData, data);
            }
            else {
                this.convertedData.connectors = data.connectors;
            }
            Eif (data.defaultSettings !== undefined) {
                this.convertedData.getNodeDefaults = this.getNodeDefaults(data.defaultSettings.node);
                this.convertedData.getConnectorDefaults = this.getConnectorDefaults(data.defaultSettings.connector);
            }
            this.setLayers(this.convertedData, data);
            this.setDataSourceSettings(this.convertedData, data);
            this.setRulerSettings(this.convertedData, data);
            this.setSnapSettings(this.convertedData, data);
            if (data.snapSettings.enableSnapToObject) {
                this.convertedData.snapSettings.constraints = this.convertedData.snapSettings.constraints | enum_1.SnapConstraints.SnapToObject;
            }
            else {
                this.convertedData.snapSettings.constraints = this.convertedData.snapSettings.constraints & ~enum_1.SnapConstraints.SnapToObject;
            }
            Eif (data.pageSettings.backgroundImage === undefined) {
                data.pageSettings.pageBackgroundColor = 'transparent';
                data.pageSettings.backgroundImage = {
                    source: '',
                    scale: 'meet',
                    alignment: 'xmidymid'
                };
                data.pageSettings.showPageBreak = false;
            }
            this.setScrollSettings(this.convertedData, data);
            this.setPageSettings(this.convertedData, data);
            this.setContextMenu(this.convertedData, data);
            this.setTooltip(this.convertedData, data);
            this.setModelLayout(this.convertedData, data);
            this.setSelectedItems(this.convertedData, data);
            this.convertedData.constraints = this.setDiagramConstraints(data.constraints);
            this.convertedData.tool = this.setDiagramTool(data.tool);
            this.convertedData.drawType = data.drawType;
            this.convertedData.commandManager = data.commandManager;
            return this.convertedData;
        };
        Ej1Serialization.prototype.getNodeDefaults = function (node) {
            if (node) {
                return this.nodeProperties.convertToNode(node);
            }
            else {
                return null;
            }
        };
        Ej1Serialization.prototype.getConnectorDefaults = function (connector) {
            if (connector) {
                return this.connectorProperties.convertToConnector(connector);
            }
            else {
                return null;
            }
        };
        Ej1Serialization.prototype.setLayers = function (convertedData, data) {
            convertedData.layers = [];
            if (data.layers.length > 0) {
                for (var i = 0; i < data.layers.length; i++) {
                    var newLayer = {};
                    var layer = data.layers[parseInt(i.toString(), 10)];
                    newLayer.id = layer.name;
                    newLayer.visible = layer.visible;
                    newLayer.lock = layer.lock;
                    newLayer.objects = layer.objects;
                    convertedData.layers.push(newLayer);
                }
            }
        };
        Ej1Serialization.prototype.setDataSourceSettings = function (convertedData, data) {
            convertedData.dataSourceSettings = {};
            convertedData.dataSourceSettings.id = data.dataSourceSettings.id;
            convertedData.dataSourceSettings.dataManager = data.dataSourceSettings.dataSource;
            convertedData.dataSourceSettings.root = data.dataSourceSettings.root;
            convertedData.dataSourceSettings.parentId = data.dataSourceSettings.parent;
            convertedData.dataSourceSettings.crudAction = {
                read: data.dataSourceSettings.crudAction.read,
                create: data.dataSourceSettings.crudAction.create,
                update: data.dataSourceSettings.crudAction.update,
                destroy: data.dataSourceSettings.crudAction.destroy,
                customFields: data.dataSourceSettings.customFields
            };
            Eif (data.dataSourceSettings.connectionDataSource) {
                convertedData.dataSourceSettings.connectionDataSource = {};
                convertedData.dataSourceSettings.connectionDataSource.id = data.dataSourceSettings.connectionDataSource.id;
                convertedData.dataSourceSettings.connectionDataSource.dataManager = data.dataSourceSettings.connectionDataSource.dataSource;
                convertedData.dataSourceSettings.connectionDataSource.sourceID = data.dataSourceSettings.connectionDataSource.sourceNode;
                convertedData.dataSourceSettings.connectionDataSource.targetID = data.dataSourceSettings.connectionDataSource.targetNode;
                convertedData.dataSourceSettings.connectionDataSource.sourcePointX = data.dataSourceSettings.connectionDataSource.sourcePointX;
                convertedData.dataSourceSettings.connectionDataSource.sourcePointY = data.dataSourceSettings.connectionDataSource.sourcePointY;
                convertedData.dataSourceSettings.connectionDataSource.targetPointX = data.dataSourceSettings.connectionDataSource.targetPointX;
                convertedData.dataSourceSettings.connectionDataSource.targetPointY = data.dataSourceSettings.connectionDataSource.targetPointY;
                convertedData.dataSourceSettings.connectionDataSource.crudAction = {
                    read: data.dataSourceSettings.connectionDataSource.crudAction.read,
                    create: data.dataSourceSettings.connectionDataSource.crudAction.create,
                    update: data.dataSourceSettings.connectionDataSource.crudAction.update,
                    destroy: data.dataSourceSettings.connectionDataSource.crudAction.destroy,
                    customFields: data.dataSourceSettings.connectionDataSource.customFields
                };
            }
        };
        Ej1Serialization.prototype.setRulerSettings = function (convertedData, data) {
            convertedData.rulerSettings = {};
            convertedData.rulerSettings.showRulers = data.rulerSettings.showRulers;
            convertedData.rulerSettings.horizontalRuler = this.setRulerProperties(data.rulerSettings.horizontalRuler);
            convertedData.rulerSettings.verticalRuler = this.setRulerProperties(data.rulerSettings.verticalRuler);
        };
        Ej1Serialization.prototype.setRulerProperties = function (ruler) {
            var rulerProperties = {};
            rulerProperties.interval = ruler.interval;
            rulerProperties.segmentWidth = ruler.segmentWidth;
            rulerProperties.markerColor = ruler.markerColor;
            rulerProperties.thickness = ruler.thickness;
            rulerProperties.arrangeTick = ruler.arrangeTick;
            return rulerProperties;
        };
        Ej1Serialization.prototype.setSnapSettings = function (convertedData, data) {
            convertedData.snapSettings = {};
            Eif (data.snapSettings) {
                convertedData.snapSettings.horizontalGridLines = this.setGridLines(data.snapSettings.horizontalGridLines);
                convertedData.snapSettings.verticalGridLines = this.setGridLines(data.snapSettings.verticalGridLines);
                convertedData.snapSettings.snapAngle = data.snapSettings.snapAngle;
                convertedData.snapSettings.snapObjectDistance = data.snapSettings.snapObjectDistance;
                convertedData.snapSettings.constraints = this.setSnapConstraints(data.snapSettings.snapConstraints);
            }
        };
        Ej1Serialization.prototype.setSnapConstraints = function (constraints) {
            var snapConstraints = enum_1.SnapConstraints.None;
            if (constraints & enum_1.SnapConstraints.ShowHorizontalLines) {
                snapConstraints = snapConstraints | enum_1.SnapConstraints.ShowHorizontalLines;
            }
            if (constraints & enum_1.SnapConstraints.ShowVerticalLines) {
                snapConstraints = snapConstraints | enum_1.SnapConstraints.ShowVerticalLines;
            }
            if (constraints & enum_1.SnapConstraints.ShowLines) {
                snapConstraints = snapConstraints | enum_1.SnapConstraints.ShowLines;
            }
            if (constraints & enum_1.SnapConstraints.SnapToHorizontalLines) {
                snapConstraints = snapConstraints | enum_1.SnapConstraints.SnapToHorizontalLines;
            }
            if (constraints & enum_1.SnapConstraints.SnapToVerticalLines) {
                snapConstraints = snapConstraints | enum_1.SnapConstraints.SnapToVerticalLines;
            }
            if (constraints & enum_1.SnapConstraints.SnapToLines) {
                snapConstraints = snapConstraints | enum_1.SnapConstraints.SnapToLines;
            }
            return snapConstraints;
        };
        Ej1Serialization.prototype.setGridLines = function (gridlines) {
            var gridLinesProperties = {};
            gridLinesProperties.lineColor = gridlines.lineColor;
            gridLinesProperties.lineDashArray = gridlines.lineDashArray;
            gridLinesProperties.lineIntervals = gridlines.lineInterval;
            gridLinesProperties.snapIntervals = gridlines.snapInterval;
            return gridLinesProperties;
        };
        Ej1Serialization.prototype.setScrollSettings = function (convertedData, data) {
            convertedData.scrollSettings = {
                horizontalOffset: data.scrollSettings.horizontalOffset,
                verticalOffset: data.scrollSettings.verticalOffset,
                currentZoom: data.scrollSettings.currentZoom,
                viewPortWidth: data.scrollSettings.viewPortWidth,
                viewPortHeight: data.scrollSettings.viewPortHeight,
                minZoom: data.scrollSettings.minZoom,
                maxZoom: data.scrollSettings.maxZoom,
                scrollLimit: (data.pageSettings.scrollLimit).charAt(0).toUpperCase() + (data.pageSettings.scrollLimit).slice(1),
                scrollableArea: data.pageSettings.scrollableArea,
                canAutoScroll: data.enableAutoScroll,
                autoScrollBorder: data.pageSettings.autoScrollBorder
            };
        };
        Ej1Serialization.prototype.setPageSettings = function (convertedData, data) {
            convertedData.pageSettings = {
                width: data.pageSettings.pageWidth,
                height: data.pageSettings.pageHeight,
                margin: { left: data.pageSettings.pageMargin, right: data.pageSettings.pageMargin, top: data.pageSettings.pageMargin, bottom: data.pageSettings.pageMargin },
                orientation: (data.pageSettings.pageOrientation).charAt(0).toUpperCase() + (data.pageSettings.pageOrientation).slice(1),
                boundaryConstraints: (data.pageSettings.boundaryConstraints).charAt(0).toUpperCase() + (data.pageSettings.boundaryConstraints).slice(1),
                background: { color: data.pageSettings.pageBackgroundColor, source: data.backgroundImage.source, scale: data.backgroundImage.scale, align: data.backgroundImage.align },
                multiplePage: data.pageSettings.multiplePage,
                showPageBreaks: data.pageSettings.showPageBreak
            };
        };
        Ej1Serialization.prototype.setContextMenu = function (convertedData, data) {
            convertedData.contextMenuSettings = {};
            convertedData.contextMenuSettings.show = data.enableContextMenu;
            Eif (data.contextMenu !== undefined) {
                convertedData.contextMenuSettings.showCustomMenuOnly = data.contextMenu.showCustomMenuItemsOnly;
                convertedData.contextMenuSettings.items = this.getContextMenuItems(data.contextMenu.items);
            }
        };
        Ej1Serialization.prototype.getContextMenuItems = function (contextMenuItems) {
            var menuItem = {};
            for (var i = 0; i < contextMenuItems.length; i++) {
                var oldMenuItem = contextMenuItems[parseInt(i.toString(), 10)];
                menuItem.id = oldMenuItem.name;
                menuItem.text = oldMenuItem.text;
                this.items.push(menuItem);
                Iif (contextMenuItems.subItems && contextMenuItems.subItems.length > 0) {
                    this.getContextMenuItems(contextMenuItems.subItems);
                }
            }
            return this.items;
        };
        Ej1Serialization.prototype.setTooltip = function (convertedData, data) {
            convertedData.tooltip = {
                content: data.tooltip.templateId,
                relativeMode: data.tooltip.relativeMode
            };
        };
        Ej1Serialization.prototype.setModelLayout = function (convertedData, data) {
            convertedData.layout = {
                fixedNode: data.layout.fixedNode,
                horizontalSpacing: data.layout.horizontalSpacing,
                verticalSpacing: data.layout.verticalSpacing,
                maxIteration: data.layout.maxIteration,
                springFactor: data.layout.springFactor,
                springLength: data.layout.springLength,
                margin: { left: data.layout.margin.left, right: data.layout.margin.right, top: data.layout.margin.top, bottom: data.layout.margin.bottom },
                horizontalAlignment: (data.layout.horizontalAlignment).charAt(0).toUpperCase() + (data.layout.horizontalAlignment).slice(1),
                verticalAlignment: (data.layout.verticalAlignment).charAt(0).toUpperCase() + (data.layout.verticalAlignment).slice(1),
                orientation: data.layout.orientation === 'toptobottom' ? 'TopToBottom' : data.layout.orientation === 'bottomtotop' ? 'BottomToTop' : data.layout.orientation === 'righttoleft' ? 'RightToLeft' : 'LeftToRight',
                connectorSegments: data.layout.getConnectorSegments,
                type: (data.layout.type).charAt(0).toUpperCase() + (data.layout.type).slice(1),
                getLayoutInfo: data.layout.getLayoutInfo,
                bounds: data.layout.bounds,
                root: data.layout.root
            };
            if (convertedData.layout && convertedData.layout.type === 'Hierarchicaltree') {
                convertedData.layout.type = 'HierarchicalTree';
            }
            else if (convertedData.layout && convertedData.layout.type === 'Organizationalchart') {
                convertedData.layout.type = 'OrganizationalChart';
            }
            else if (convertedData.layout && convertedData.layout.type === 'Radialtree') {
                convertedData.layout.type = 'RadialTree';
            }
        };
        Ej1Serialization.prototype.setSelectedItems = function (convertedData, data) {
            convertedData.selectedItems = {};
            var nodes = [];
            var connectors = [];
            convertedData.selectedItems.nodes = nodes;
            convertedData.selectedItems.connectors = connectors;
            convertedData.selectedItems.offsetX = data.selectedItems.offsetX;
            convertedData.selectedItems.offsetY = data.selectedItems.offsetY;
            convertedData.selectedItems.width = data.selectedItems.width;
            convertedData.selectedItems.height = data.selectedItems.height;
            convertedData.selectedItems.rotateAngle = data.selectedItems.rotateAngle;
            convertedData.selectedItems.constraints = this.setSelectorConstraints(data.selectedItems.constraints);
            convertedData.selectedItems.userHandles = data.selectedItems.userHandles;
        };
        Ej1Serialization.prototype.setSelectorConstraints = function (constraints) {
            var selectorConstraints = enum_1.SelectorConstraints.None;
            if (constraints & enum_1.SelectorConstraints.ConnectorSourceThumb) {
                selectorConstraints = selectorConstraints | enum_1.SelectorConstraints.Rotate;
            }
            if (constraints & enum_1.SelectorConstraints.ResizeAll) {
                selectorConstraints = selectorConstraints | enum_1.SelectorConstraints.ResizeAll;
            }
            if (constraints & enum_1.SelectorConstraints.ResizeSouthEast) {
                selectorConstraints = selectorConstraints | enum_1.SelectorConstraints.UserHandle;
            }
            Iif (constraints & enum_1.SelectorConstraints.ToolTip) {
                selectorConstraints = selectorConstraints | enum_1.SelectorConstraints.ToolTip;
            }
            if (constraints & enum_1.SelectorConstraints.All) {
                selectorConstraints = selectorConstraints | enum_1.SelectorConstraints.All;
            }
            return selectorConstraints;
        };
        Ej1Serialization.prototype.setDiagramConstraints = function (constraints) {
            var diagramConstraints = enum_1.DiagramConstraints.None;
            if (constraints & enum_1.DiagramConstraints.UserInteraction) {
                diagramConstraints = diagramConstraints | enum_1.DiagramConstraints.UserInteraction;
            }
            if (constraints & enum_1.DiagramConstraints.ApiUpdate) {
                diagramConstraints = diagramConstraints | enum_1.DiagramConstraints.ApiUpdate;
            }
            if (constraints & enum_1.DiagramConstraints.PageEditable) {
                diagramConstraints = diagramConstraints | enum_1.DiagramConstraints.PageEditable;
            }
            Iif (constraints & enum_1.DiagramConstraints.LineRouting) {
                diagramConstraints = diagramConstraints | enum_1.DiagramConstraints.Bridging;
            }
            if (constraints & enum_1.DiagramConstraints.Zoom) {
                diagramConstraints = diagramConstraints | enum_1.DiagramConstraints.Zoom;
            }
            if (constraints & enum_1.DiagramConstraints.PanX) {
                diagramConstraints = diagramConstraints | enum_1.DiagramConstraints.PanX;
            }
            if (constraints & enum_1.DiagramConstraints.PanY) {
                diagramConstraints = diagramConstraints | enum_1.DiagramConstraints.PanY;
            }
            if (constraints & enum_1.DiagramConstraints.Pan) {
                diagramConstraints = diagramConstraints | enum_1.DiagramConstraints.Pan;
            }
            if (constraints & enum_1.DiagramConstraints.UndoRedo) {
                diagramConstraints = diagramConstraints | enum_1.DiagramConstraints.UndoRedo;
            }
            Iif (constraints & enum_1.DiagramConstraints.ZoomTextEdit) {
                diagramConstraints = diagramConstraints | enum_1.DiagramConstraints.ZoomTextEdit;
            }
            return diagramConstraints;
        };
        Ej1Serialization.prototype.setDiagramTool = function (tool) {
            var diagramTool = enum_1.DiagramTools.None;
            if (tool & enum_1.DiagramTools.MultipleSelect) {
                diagramTool = diagramTool | enum_1.DiagramTools.SingleSelect;
            }
            if (tool & enum_1.DiagramTools.ZoomPan) {
                diagramTool = diagramTool | enum_1.DiagramTools.MultipleSelect;
            }
            if (tool & enum_1.DiagramTools.DrawOnce) {
                diagramTool = diagramTool | enum_1.DiagramTools.ZoomPan;
            }
            if (tool & enum_1.DiagramTools.ContinuousDraw) {
                diagramTool = diagramTool | enum_1.DiagramTools.DrawOnce;
            }
            if (tool & enum_1.DiagramTools.ContinuousDraw) {
                diagramTool = diagramTool | enum_1.DiagramTools.ContinuousDraw;
            }
            return diagramTool;
        };
        Ej1Serialization.prototype.destroy = function () {
        };
        Ej1Serialization.prototype.getModuleName = function () {
            return 'Ej1Serialization';
        };
        return Ej1Serialization;
    }());
    exports.Ej1Serialization = Ej1Serialization;
});