forked from tobiashochguertel/c4-draw.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c4.js
589 lines (571 loc) · 29.6 KB
/
c4.js
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
/**
* Draw.io Plugin to create C4 Architecture Diagramms
*
* LOAD C4 SHAPE LIBRARY:
*
* https://raw.githubusercontent.com/tobiashochguertel/draw-io/master/C4-drawIO.xml
*/
Draw.loadPlugin(function (ui) {
var sidebar_id = 'c4';
var sidebar_title = 'C4 Notation';
var c4Utils = {};
c4Utils.isC4 = function (cell) {
return (cell &&
cell.hasOwnProperty('c4') &&
(cell.c4 !== null));
};
c4Utils.isC4Model = function (cell) {
return (c4Utils.isC4(cell) &&
cell &&
cell.hasOwnProperty('value') &&
(cell.value &&
cell.value.hasAttribute('c4Type'))
);
};
c4Utils.isC4Person = function (cell) {
return (c4Utils.isC4(cell) &&
(cell.hasOwnProperty('value') &&
cell.value.length === 0 ) &&
cell.getChildCount() === 2 &&
cell.getChildAt(0).value.getAttribute('c4Type') === 'body');
};
c4Utils.isC4SoftwareSystem = function (cell) {
return (c4Utils.isC4(cell) &&
cell.getAttribute('c4Type') === 'SoftwareSystem');
};
c4Utils.isC4SoftwareSystemDependency = function (cell) {
return (c4Utils.isC4(cell) &&
cell.getAttribute('c4Type') === 'SoftwareSystemDependency');
};
c4Utils.isC4Relationship = function (cell) {
return (c4Utils.isC4(cell) &&
cell.getAttribute('c4Type') === 'Relationship');
};
c4Utils.createSettingsIcon = function () {
var img = mxUtils.createImage('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAXCAYAAADgKtSgAAACpklEQVRIS7VVMU9TURg9nWiZoF0k1MQmlKCREhhowUHaScpWdYHoINUORoKTiT+AhMnE6IDigraL2g10amGhxaFGMJHQJiWxBJcWJl6Zas4H9/leH4VKwl2a13vv+c73nfN911ar1Wq4oGVrBpzxq9VDnYLd3gKbzXYmpabAs2s5bBWKCAwOIPstJ7/dXs/5wNMrGfh6e+BytgvA4pcU3J0d6PNdRWp5FZpWxdhoSPbKlT2sb2wieHPIEszC/H08iQNNQ6m0i1DwBhwOu4BPP3kgwUo7u+CZ4MiwBMlkc3C52tDqcODeRMQUwAROVvlCEbHohFz8mFyUw2SpsuA3A/AsAblHAnPzcXi7PAiNDOsBTOBMce5tAk+nJuWCceUL2/qnt+uKaY9EXrx8h9jDcRMJS1nIqFLZx51IWAB+rP+SsjB11p2sy+V9YUwNuD4ll+B0tplY838LuHLG/YnbOnA9I5WhCrAQ/4zuLg8C/gFrzenjjZ+bKO38QWYtp4s3M/vakqq6rQI8f/ZYHPNmPoE+3zW4Oy+h93qP9IEwV+Ixutfrkbpt5YtIr6yKuI0W60z29DwD5PNF6Ye7kTHRTAf/Xdo1NQbB6Rzl55MCUAs6xNhQvHfZ3WEGpyhkTSecm3lhW9jTDDpz1pxdRifQHUrA/6k5LUz30FHsbr3mxpTr3bL0NYVHUbN/lYDhW0d2PNUtRvDGPm+XWlKbcnnP5POmwE/rUAqlVv1EpNtmZl9hemqycYcezZZtxKLjMlsoMld4NGiZLenljIj2b7YkxAwNZwuBmKKmHUrqAX8/WtVUPGZF0Rc+JBEaGcKBVkV27TtcrnY4HC1gVxvXiY8FM6BQzcxzBmPJjIxVgKZfIpaLs4Nu8g/2n/8lqu/GC31DGw6XMzb+An4I4cvYKbPGAAAAAElFTkSuQmCC');
img.setAttribute('title', 'Settings');
img.style.cursor = 'pointer';
img.style.width = '16px';
img.style.height = '16px';
return img;
};
c4Utils.registCodec = function (func) {
var codec = new mxObjectCodec(new func());
codec.encode = function (enc, obj) {
try {
var data = enc.document.createElement(func.name);
} catch (e) {
(window.console && console.error(e));
}
return data
};
codec.decode = function (dec, node, into) {
return new func();
};
mxCodecRegistry.register(codec);
};
c4StateHandler = function (state) {
mxVertexHandler.apply(this, arguments);
};
c4StateHandler.prototype = new mxVertexHandler();
c4StateHandler.prototype.constructor = c4StateHandler;
c4StateHandler.prototype.domNode = null;
c4StateHandler.prototype.init = function () {
mxVertexHandler.prototype.init.apply(this, arguments);
this.domNode = document.createElement('div');
this.domNode.style.position = 'absolute';
this.domNode.style.whiteSpace = 'nowrap';
if (this.custom) this.custom.apply(this, arguments);
var img = c4Utils.createSettingsIcon();
mxEvent.addGestureListeners(img,
mxUtils.bind(this, function (evt) {
mxEvent.consume(evt);
})
);
mxEvent.addListener(img, 'click',
mxUtils.bind(this, function (evt) {
var isC4Person = c4Utils.isC4Person(this.state.cell);
if (isC4Person) {
var cell = this.state.cell.getChildAt(0);
if (cell !== null) {
var dlg = new EditDataDialog(ui, cell);
ui.showDialog(dlg.container, 320, 320, true, false);
dlg.init();
}
}
if (!isC4Person) {
ui.actions.get('editData').funct();
}
mxEvent.consume(evt);
})
);
this.domNode.appendChild(img);
this.graph.container.appendChild(this.domNode);
this.redrawTools();
};
c4StateHandler.prototype.redraw = function () {
mxVertexHandler.prototype.redraw.apply(this);
this.redrawTools();
};
c4StateHandler.prototype.redrawTools = function () {
if (this.state !== null && this.domNode !== null) {
var dy = (mxClient.IS_VML && document.compatMode === 'CSS1Compat') ? 20 : 4;
this.domNode.style.left = (this.state.x + this.state.width - this.domNode.children.length * 14) + 'px';
this.domNode.style.top = (this.state.y + this.state.height + dy) + 'px';
}
};
c4StateHandler.prototype.destroy = function (sender, me) {
mxVertexHandler.prototype.destroy.apply(this, arguments);
if (this.domNode !== null) {
this.domNode.parentNode.removeChild(this.domNode);
this.domNode = null;
}
};
C4Person = function () {
};
C4Person.prototype.handler = c4StateHandler;
C4Person.prototype.create = function () {
var group = new mxCell('', new mxGeometry(0, 0, 160, 180), 'group;rounded=0;labelBackgroundColor=none;fillColor=none;fontColor=#ffffff;align=center;html=1;');
group.setVertex(true);
group.setConnectable(false);
group.setAttribute('c4Type', 'person');
group.c4 = this;
var body = new mxCell('', new mxGeometry(0, 70, 160, 110), 'rounded=1;whiteSpace=wrap;html=1;labelBackgroundColor=none;fillColor=#515F62;fontColor=#ffffff;align=center;arcSize=10;strokeColor=26373B;');
body.setParent(group);
body.setVertex(true);
body.setValue(mxUtils.createXmlDocument().createElement('object'));
body.setAttribute('label', '<b>name</b><div>[Person]</div><div><br></div><div>Description</div>');
body.setAttribute('placeholders', '1');
body.setAttribute('c4Name', 'name');
body.setAttribute('c4Type', 'body');
body.setAttribute('c4Description', 'Description');
body.c4 = this;
var head = new mxCell('', new mxGeometry(40, 0, 80, 80), 'ellipse;whiteSpace=wrap;html=1;aspect=fixed;rounded=0;labelBackgroundColor=none;fillColor=#515F62;fontSize=12;fontColor=#ffffff;align=center;strokeColor=26373B;');
head.setParent(group);
head.setVertex(true);
head.setAttribute('c4Type', 'head');
head.c4 = this;
group.insert(head);
group.insert(body); // child: 0 !!
return group;
};
c4Utils.registCodec(C4Person);
C4SoftwareSystem = function () {
};
C4SoftwareSystem.prototype.handler = c4StateHandler;
C4SoftwareSystem.prototype.create = function () {
var c4SoftwareSystem = new mxCell('', new mxGeometry(0, 70, 160, 110), 'rounded=0;whiteSpace=wrap;html=1;labelBackgroundColor=none;fillColor=#1168bd;fontColor=#ffffff;align=center;arcSize=7;strokeColor=#0f5eaa;');
c4SoftwareSystem.setVertex(true);
c4SoftwareSystem.setValue(mxUtils.createXmlDocument().createElement('object'));
c4SoftwareSystem.setAttribute('label', '<b>name</b><div>[Software System]</div><div><br></div><div>Description</div>');
c4SoftwareSystem.setAttribute('placeholders', '1');
c4SoftwareSystem.setAttribute('c4Name', 'name');
c4SoftwareSystem.setAttribute('c4Type', 'SoftwareSystem');
c4SoftwareSystem.setAttribute('c4Description', 'Description');
c4SoftwareSystem.c4 = this;
return c4SoftwareSystem;
};
c4Utils.registCodec(C4SoftwareSystem);
C4SoftwareSystemDependency = function () {
};
C4SoftwareSystemDependency.prototype.handler = c4StateHandler;
C4SoftwareSystemDependency.prototype.create = function () {
var c4SoftwareSystemDependency = new mxCell('', new mxGeometry(0, 70, 160, 110), 'rounded=0;whiteSpace=wrap;html=1;labelBackgroundColor=none;fillColor=#999999;fontColor=#ffffff;align=center;arcSize=7;strokeColor=#8a8a8a;');
c4SoftwareSystemDependency.setVertex(true);
c4SoftwareSystemDependency.setValue(mxUtils.createXmlDocument().createElement('object'));
c4SoftwareSystemDependency.setAttribute('label', '<b>name</b><div>[Software System]</div><div><br></div><div>Description</div>');
c4SoftwareSystemDependency.setAttribute('placeholders', '1');
c4SoftwareSystemDependency.setAttribute('c4Name', 'name');
c4SoftwareSystemDependency.setAttribute('c4Type', 'SoftwareSystemDependency');
c4SoftwareSystemDependency.setAttribute('c4Description', 'Description');
c4SoftwareSystemDependency.c4 = this;
return c4SoftwareSystemDependency;
};
c4Utils.registCodec(C4SoftwareSystemDependency);
C4Container = function () {
};
C4Container.prototype.handler = c4StateHandler;
C4Container.prototype.create = function () {
var c4Container = new mxCell('', new mxGeometry(0, 70, 160, 110), 'rounded=0;whiteSpace=wrap;html=1;labelBackgroundColor=none;fillColor=#BEC3C4;fontColor=#ffffff;align=center;arcSize=6;strokeColor=#3c7fc0;');
c4Container.setVertex(true);
c4Container.setValue(mxUtils.createXmlDocument().createElement('object'));
c4Container.setAttribute('label', '<span><b>name</b></span><div>[Container: <span>technology</span><span>]</span></div><div><br></div><div>Description</div>');
c4Container.setAttribute('placeholders', '1');
c4Container.setAttribute('c4Name', 'name');
c4Container.setAttribute('c4Type', 'Container');
c4Container.setAttribute('c4Technology', 'technology');
c4Container.setAttribute('c4Description', 'Description');
c4Container.c4 = this;
return c4Container;
};
c4Utils.registCodec(C4Container);
C4Component = function () {
};
C4Component.prototype.handler = c4StateHandler;
C4Component.prototype.create = function () {
var c4Component = new mxCell('', new mxGeometry(0, 70, 160, 110), 'rounded=0;whiteSpace=wrap;html=1;labelBackgroundColor=none;fillColor=#85bbf0;fontColor=#000000;align=center;arcSize=7;strokeColor=#78a8d8;');
c4Component.setVertex(true);
c4Component.setValue(mxUtils.createXmlDocument().createElement('object'));
c4Component.setAttribute('label', '<span><b>name</b></span><div>[Component: <span>technology</span><span>]</span></div><div><br></div><div>Description</div>');
c4Component.setAttribute('placeholders', '1');
c4Component.setAttribute('c4Name', 'name');
c4Component.setAttribute('c4Type', 'Component');
c4Component.setAttribute('c4Technology', 'technology');
c4Component.setAttribute('c4Description', 'Description');
c4Component.c4 = this;
return c4Component;
};
c4Utils.registCodec(C4Component);
C4ExecutionEnvironment = function () {
};
C4ExecutionEnvironment.prototype.handler = c4StateHandler;
C4ExecutionEnvironment.prototype.create = function () {
var c4ExecutionEnvironment = new mxCell('', new mxGeometry(0, 70, 200, 170), 'rounded=0;whiteSpace=wrap;html=1;labelBackgroundColor=none;fillColor=#ffffff;fontColor=#000000;align=left;arcSize=3;strokeColor=#000000;verticalAlign=bottom;');
c4ExecutionEnvironment.setVertex(true);
c4ExecutionEnvironment.setValue(mxUtils.createXmlDocument().createElement('object'));
c4ExecutionEnvironment.setAttribute('label', '<div style="text-align: left">name</div><div style="text-align: left">[applicationAndVersion]</div>');
c4ExecutionEnvironment.setAttribute('placeholders', '1');
c4ExecutionEnvironment.setAttribute('c4Name', 'name');
c4ExecutionEnvironment.setAttribute('c4Type', 'ExecutionEnvironment');
c4ExecutionEnvironment.setAttribute('c4Application', 'applicationAndVersion');
c4ExecutionEnvironment.c4 = this;
return c4ExecutionEnvironment;
};
c4Utils.registCodec(C4ExecutionEnvironment);
C4DeploymentNode = function () {
};
C4DeploymentNode.prototype.handler = c4StateHandler;
C4DeploymentNode.prototype.create = function () {
var c4DeploymentNode = new mxCell('', new mxGeometry(0, 70, 240, 230), 'rounded=0;whiteSpace=wrap;html=1;labelBackgroundColor=none;fillColor=#ffffff;fontColor=#000000;align=left;arcSize=3;strokeColor=#000000;verticalAlign=bottom;');
c4DeploymentNode.setVertex(true);
c4DeploymentNode.setValue(mxUtils.createXmlDocument().createElement('object'));
c4DeploymentNode.setAttribute('label', '<div style="text-align: left">hostname</div><div style="text-align: left">[operationSystem]</div><div style="text-align: right">scalingFactor</div>');
c4DeploymentNode.setAttribute('placeholders', '1');
c4DeploymentNode.setAttribute('c4Name', 'hostname');
c4DeploymentNode.setAttribute('c4Type', 'DeploymentNode');
c4DeploymentNode.setAttribute('c4OperationSystem', 'operationSystem');
c4DeploymentNode.setAttribute('c4ScalingFactor', 'scalingFactor');
c4DeploymentNode.c4 = this;
return c4DeploymentNode;
};
c4Utils.registCodec(C4DeploymentNode);
C4Database = function () {
};
C4Database.prototype.handler = c4StateHandler;
C4Database.prototype.create = function () {
var c4Database = new mxCell('', new mxGeometry(0, 70, 160, 140), 'shape=cylinder;whiteSpace=wrap;html=1;boundedLbl=1;rounded=0;labelBackgroundColor=none;fillColor=#438dd5;fontSize=12;fontColor=#ffffff;align=center;strokeColor=#3c7fc0;');
c4Database.setVertex(true);
c4Database.setValue(mxUtils.createXmlDocument().createElement('object'));
c4Database.setAttribute('label', '<span>Database</span><div>[Container: technology]</div><div><br></div><div>Description</div>');
c4Database.setAttribute('placeholders', '1');
c4Database.setAttribute('c4Type', 'Database');
c4Database.setAttribute('c4Technology', 'technology');
c4Database.setAttribute('c4Description', 'Description');
c4Database.c4 = this;
return c4Database;
};
c4Utils.registCodec(C4Database);
C4Relationship = function () {
};
C4Relationship.prototype.handler = c4StateHandler;
C4Relationship.prototype.create = function () {
var label = '<div style="text-align: left"><div style="text-align: center"><b>Description</b></div><div style="text-align: center">[technology]</div></div>';
var cell = new mxCell('', new mxGeometry(0, 0, 160, 0), 'edgeStyle=none;rounded=0;html=1;entryX=0;entryY=0.5;jettySize=auto;orthogonalLoop=1;strokeColor=#707070;strokeWidth=2;fontColor=#707070;jumpStyle=none;dashed=1;');
cell.setValue(mxUtils.createXmlDocument().createElement('object'));
cell.geometry.setTerminalPoint(new mxPoint(0, 0), true);
cell.geometry.setTerminalPoint(new mxPoint(160, 0), false);
cell.geometry.relative = true;
cell.edge = true;
cell.value.setAttribute('label', label);
cell.value.setAttribute('c4Type', 'Relationship');
cell.value.setAttribute('c4Description', 'Description');
cell.value.setAttribute('c4Technology', 'technology');
cell.c4 = this;
return cell;
};
c4Utils.registCodec(C4Relationship);
// Adds custom sidebar entry
ui.sidebar.addPalette(sidebar_id, sidebar_title, true, function (content) {
var verticies = [C4Person, C4SoftwareSystem, C4SoftwareSystemDependency, C4Container, C4Component, C4ExecutionEnvironment, C4DeploymentNode, C4Database];
for (var i in verticies) {
var cell = verticies[i].prototype.create();
content.appendChild(ui.sidebar.createVertexTemplateFromCells([cell], cell.geometry.width, cell.geometry.height, cell.label));
}
content.appendChild(ui.sidebar.createEdgeTemplateFromCells([C4Relationship.prototype.create()], 160, 0, 'C4 Relationship'));
// , C4DynamicRelationship];
});
// Add custom handler-code for the event of data-editor instanzing to provide a custom data-editor dialog.
origGraphCreateHander = ui.editor.graph.createHandler;
ui.editor.graph.createHandler = function (state) {
if (state !== null && (this.getSelectionCells().length === 1) && c4Utils.isC4(state.cell) && state.cell.c4.handler
&& !c4Utils.isC4Relationship(state.cell)) {
return new state.cell.c4.handler(state);
}
return origGraphCreateHander.apply(this, arguments);
};
// START -> CUSTOM EDITOR MENU!
origEditDataDialog = EditDataDialog;
EditDataDialog = function (ui, cell) {
if (!c4Utils.isC4(cell)) {
return origEditDataDialog.apply(this, arguments);
}
var div = document.createElement('div');
var graph = ui.editor ? ui.editor.graph : ui.graph;
div.style.height = '100%'; //'310px';
div.style.overflow = 'auto';
var value = graph.getModel().getValue(cell);
// Converts the value to an XML node
if (!mxUtils.isNode(value)) {
var obj = mxUtils.createXmlDocument().createElement('object');
obj.setAttribute('label', value || '');
value = obj;
}
// Creates the dialog contents
var form = new mxForm('properties');
form.table.style.width = '100%';
form.table.style.paddingRight = '20px';
var colgroupName = document.createElement('colgroup');
colgroupName.width = '120';
form.table.insertBefore(colgroupName, form.body);
var colgroupValue = document.createElement('colgroup');
form.table.insertBefore(colgroupValue, form.body);
var attrs = value.attributes;
var names = [];
var texts = [];
var count = 0;
var addTextArea = function (index, name, value, tabIndex) {
names[index] = name;
texts[index] = form.addTextarea(names[count] + ':', value, 2);
texts[index].style.width = '100%';
texts[index].tabIndex = tabIndex;
return texts[index];
};
var addText = function (index, name, value, tabIndex) {
names[index] = name;
texts[index] = form.addText(names[count] + ':', value);
texts[index].style.width = '100%';
texts[index].tabIndex = tabIndex;
return texts[index];
};
var addAttribute = function (index, name, value) {
names[index] = name;
texts[index] = document.createElement('textarea');
texts[index].value = value;
return texts[index];
};
for (var i = 0; i < attrs.length; i++) {
var nodeName = attrs[i].nodeName;
var nodeValue = attrs[i].nodeValue;
// if (cell.awssf.hiddenAttributes && cell.awssf.hiddenAttributes.indexOf(nodeName) >= 0) continue;
if (nodeName === 'c4Type') {
var span = document.createElement('span');
mxUtils.write(span, nodeValue);
form.addField('c4Type:', span);
} else if (nodeName === 'label') {
addAttribute(count, nodeName, nodeValue);
count++;
var labelDiv = document.createElement('div');
labelDiv.setAttribute('style', 'border: 1px dashed #c2c2c2; margin-bottom: 4px;');
labelDiv.innerHTML = nodeValue;
div.appendChild(labelDiv);
}
else if (nodeName !== 'placeholders') {
addTextArea(count, nodeName, nodeValue, i);
count++;
}
}
div.appendChild(form.table);
this.init = function () {
function getIndexOfC4Type(c4type) {
for (var i = 0; i < names.length; i++) {
if (names[i] === c4type) { //'c4Name'
return i;
}
}
}
var firstInputField = -1;
switch (cell.getAttribute('c4Type')) {
case 'body':
case 'SoftwareSystem':
case 'Container':
case 'Component':
case 'ExecutionEnvironment':
case 'DeploymentNode':
firstInputField = getIndexOfC4Type('c4Name');
break;
case 'Relationship':
firstInputField = getIndexOfC4Type('c4Description');
break;
case 'DynamicRelationship':
firstInputField = getIndexOfC4Type('c4Step');
break;
case 'Database':
firstInputField = getIndexOfC4Type('c4Technology');
break;
}
if (texts.length > 0 && firstInputField !== -1) {
texts[firstInputField].focus();
}
};
var cancelBtn = mxUtils.button(mxResources.get('cancel'), function () {
ui.hideDialog.apply(ui, arguments);
});
cancelBtn.className = 'geBtn';
var applyBtn = mxUtils.button(mxResources.get('apply'), function () {
try {
ui.hideDialog.apply(ui, arguments);
// Clones and updates the value
value = value.cloneNode(true);
var removeLabel = false;
var c4NotationUpdate = function () {
var c4Name = '';
var c4Description = '';
var c4Technology = '';
var c4OperationSystem = '';
var c4Application = '';
var c4ScalingFactor = '';
var c4Step = 1;
var labelIndex = -1;
for (var i = 0; i < names.length; i++) {
if (names[i] === 'c4Name') {
c4Name = texts[i].value;
}
if (names[i] === 'c4Description') {
c4Description = texts[i].value;
}
if (names[i] === 'c4Technology') {
c4Technology = texts[i].value;
}
if (names[i] === 'c4OperationSystem') {
c4OperationSystem = texts[i].value;
}
if (names[i] === 'c4Application') {
c4Application = texts[i].value;
}
if (names[i] === 'c4ScalingFactor') {
c4ScalingFactor = texts[i].value;
}
if (names[i] === 'c4Step') {
c4Step = texts[i].value;
}
if (names[i] === 'label') {
labelIndex = i;
}
}
if (labelIndex >= 0) {
switch (cell.getAttribute('c4Type')) {
case 'body':
texts[labelIndex].value = '<b>' + c4Name + '</b><div>[Person]</div><div><br></div><div>' + c4Description;
break;
case 'SoftwareSystem':
texts[labelIndex].value = '<b>' + c4Name + '</b><div>[Software System]</div><div><br></div><div>' + c4Description;
break;
case 'SoftwareSystemDependency':
texts[labelIndex].value = '<b>' + c4Name + '</b><div>[Software System]</div><div><br></div><div>' + c4Description;
break;
case 'Container':
texts[labelIndex].value = '<span><b>' + c4Name + '</b></span><div>[Container: <span>' + c4Technology + '</span><span>]</span></div><div><br></div><div>' + c4Description + '</div>';
break;
case 'Component':
texts[labelIndex].value = '<span><b>' + c4Name + '</b></span><div>[Component: <span>' + c4Technology + '</span><span>]</span></div><div><br></div><div>' + c4Description + '</div>';
break;
case 'Relationship':
texts[labelIndex].value = '<div style="text-align: left"><div style="text-align: center"><b>' + c4Description + '</b></div><div style="text-align: center">[' + c4Technology + ']</div></div>';
break;
case 'ExecutionEnvironment':
texts[labelIndex].value = '<div style="text-align: left"><b>' + c4Name + '</b></div><div style="text-align: left">[' + c4Application + ']</div>';
break;
case 'DeploymentNode':
texts[labelIndex].value = '<div style="text-align: left"><b>' + c4Name + '</b></div><div style="text-align: left">[' + c4OperationSystem + ']</div><div style="text-align: right">' + c4ScalingFactor + '</div>';
break;
case 'DynamicRelationship':
texts[labelIndex].value = '<bold>' + c4Step + ': </bold><bold>' + c4Description + '</bold>' + '<div>[' + c4Technology + ']</div><div><br></div><div>';
break;
case 'Database':
texts[labelIndex].value = '<span>Database</span><div>[Container: ' + c4Technology + ']</div><div><br></div><div>' + c4Description + '</div>';
break;
}
}
}();
for (var i = 0; i < names.length; i++) {
if (cell.c4 && cell.c4.applyForm) {
removeLabel = removeLabel || cell.c4.applyForm(value, names[i], texts[i]);
} else {
if (texts[i] === null) {
value.removeAttribute(names[i]);
}
else {
value.setAttribute(names[i], texts[i].value);
removeLabel = removeLabel || (names[i] === 'placeholder' &&
value.getAttribute('placeholders') === '1');
}
}
}
// Removes label if placeholder is assigned
if (removeLabel) {
value.removeAttribute('label');
}
// Updates the value of the cell (undoable)
graph.getModel().setValue(cell, value);
}
catch (e) {
mxUtils.alert(e);
}
});
applyBtn.className = 'geBtn gePrimaryBtn';
applyBtn.tabIndex = 10;
var buttons = document.createElement('div');
buttons.style.marginTop = '18px';
buttons.style.textAlign = 'right';
if (graph.getModel().isVertex(cell) || graph.getModel().isEdge(cell)) {
var replace = document.createElement('span');
replace.style.marginRight = '10px';
var input = document.createElement('input');
input.setAttribute('type', 'checkbox');
input.style.marginRight = '6px';
if (value.getAttribute('placeholders') === '1') {
input.setAttribute('checked', 'checked');
input.defaultChecked = true;
}
mxEvent.addListener(input, 'click', function () {
if (value.getAttribute('placeholders') === '1') {
value.removeAttribute('placeholders');
}
else {
value.setAttribute('placeholders', '1');
}
});
replace.appendChild(input);
mxUtils.write(replace, mxResources.get('placeholders'));
if (EditDataDialog.placeholderHelpLink !== null) {
var createHelpIcon = function () {
var link = document.createElement('a');
link.setAttribute('href', EditDataDialog.placeholderHelpLink);
link.setAttribute('title', mxResources.get('help'));
link.setAttribute('target', '_blank');
link.style.marginLeft = '10px';
link.style.cursor = 'help';
var icon = document.createElement('img');
icon.setAttribute('border', '0');
icon.setAttribute('valign', 'middle');
icon.style.marginTop = '-4px';
icon.setAttribute('src', Editor.helpImage);
link.appendChild(icon);
replace.appendChild(link);
}();
}
buttons.appendChild(replace);
}
if (ui.editor && ui.editor.cancelFirst) {
buttons.appendChild(cancelBtn);
buttons.appendChild(applyBtn);
}
else {
buttons.appendChild(applyBtn);
buttons.appendChild(cancelBtn);
}
div.appendChild(buttons);
this.container = div;
}
///// END <- CUSTOM EDITOR FORM
});