Revize f4a56448
Přidáno uživatelem Pavel Fidranský před více než 6 roky(ů)
sources/src/main/webapp/css/main.css | ||
---|---|---|
901 | 901 |
.loggedOut .loggedInOnly { |
902 | 902 |
display: none !important; |
903 | 903 |
} |
904 |
|
|
905 |
/** |
|
906 |
* MODAL WINDOW |
|
907 |
**/ |
|
908 |
|
|
909 |
.modal { |
|
910 |
position: absolute; |
|
911 |
top: 0; |
|
912 |
bottom: 0; |
|
913 |
left: 0; |
|
914 |
right: 0; |
|
915 |
padding: 20px 40px; |
|
916 |
background: rgba(0,0,0,0.5); |
|
917 |
} |
|
918 |
|
|
919 |
.modal-content { |
|
920 |
position: relative; |
|
921 |
max-width: 440px; |
|
922 |
min-height: 40px; |
|
923 |
max-height: 100%; |
|
924 |
margin-left: auto; |
|
925 |
margin-right: auto; |
|
926 |
padding: 10px 20px; |
|
927 |
background-color: #fff; |
|
928 |
border: 1px solid #7db9e8; |
|
929 |
} |
|
930 |
|
|
931 |
.modal-content .close-button { |
|
932 |
position: absolute; |
|
933 |
top: 10px; |
|
934 |
right: 10px; |
|
935 |
display: block; |
|
936 |
width: 20px; |
|
937 |
height: 20px; |
|
938 |
padding: 0; |
|
939 |
background: none; |
|
940 |
border: none; |
|
941 |
cursor: pointer; |
|
942 |
} |
sources/src/main/webapp/js/app.js | ||
---|---|---|
45 | 45 |
this.sidebarComponent = null; |
46 | 46 |
/** @prop {Viewport} viewportComponent */ |
47 | 47 |
this.viewportComponent = null; |
48 |
/** @prop {ModalWindow} modalWindowComponent */ |
|
49 |
this.modalWindowComponent = null; |
|
48 | 50 |
|
49 | 51 |
/** @prop {array<Edge>} edgeList */ |
50 | 52 |
this.edgeList = []; |
... | ... | |
146 | 148 |
content.appendChild(self.sidebarComponent.render()); |
147 | 149 |
self.sidebarComponent.minimapComponent.setViewportSize(self.viewportComponent.getSize()); |
148 | 150 |
|
151 |
self.modalWindowComponent = new ModalWindow; |
|
152 |
content.appendChild(self.modalWindowComponent.render()); |
|
153 |
|
|
149 | 154 |
// context menu |
150 | 155 |
document.body.addEventListener('mousedown', function() { |
151 | 156 |
self.closeFloatingComponents(); |
... | ... | |
311 | 316 |
}); |
312 | 317 |
|
313 | 318 |
// save to database button |
314 |
var saveDiagramToDatabaseButton = document.getElementById('btnSaveDiagramToDatabase'); |
|
315 |
if (saveDiagramToDatabaseButton) { |
|
316 |
saveDiagramToDatabaseButton.addEventListener('click', function(e) { |
|
317 |
var diagramId = app.utils.getQueryVariable('diagramId'); |
|
318 |
if (diagramId === false) diagramId = null; |
|
319 |
|
|
320 |
var diagramName = prompt('Enter new diagram name:', self.diagram !== null ? self.diagram.name : ''); |
|
321 |
if (diagramName === null || diagramName === '') return false; |
|
322 |
|
|
323 |
$.ajax({ |
|
324 |
'type': 'POST', |
|
325 |
'url': app.API.saveDiagram, |
|
326 |
'data': { |
|
327 |
'diagramId': diagramId, |
|
328 |
'name': diagramName, |
|
329 |
'graphJson': JSON.stringify(self.graphExporter.run()), |
|
330 |
'public': 0, |
|
331 |
}, |
|
332 |
'success': function() { |
|
333 |
alert('Saved.'); |
|
334 |
}, |
|
335 |
'error': function(xhr) { |
|
336 |
switch (xhr.status) { |
|
337 |
case 401: |
|
338 |
alert('You are either not logged in or not an owner of this diagram.'); |
|
339 |
break; |
|
340 |
default: |
|
341 |
alert('Something went wrong.'); |
|
342 |
} |
|
343 |
}, |
|
344 |
}); |
|
345 |
}); |
|
346 |
} |
|
319 |
document.getElementById('btnSaveDiagramToDatabase').addEventListener('click', function(e) { |
|
320 |
self.modalWindowComponent.open(); |
|
321 |
}); |
|
347 | 322 |
|
348 | 323 |
// window resize |
349 | 324 |
window.addEventListener('resize', function(e) { |
... | ... | |
374 | 349 |
loadGraphDataPromise = getDiagramPromise.then(function(data) { |
375 | 350 |
self.diagram = new Diagram(data); |
376 | 351 |
|
352 |
document.title = self.NAME + ' - ' + self.diagram.name; |
|
353 |
|
|
377 | 354 |
return $.getJSON(self.API.loadGraphData + '?diagramId=' + diagramId); |
378 | 355 |
}); |
379 | 356 |
} |
sources/src/main/webapp/js/components/modalWindow.js | ||
---|---|---|
1 |
/** |
|
2 |
* Class representing a modal window. |
|
3 |
* @constructor |
|
4 |
*/ |
|
5 |
function ModalWindow() { |
|
6 |
var rootElement; |
|
7 |
var diagramForm; |
|
8 |
|
|
9 |
/** |
|
10 |
* Opens this modal window. |
|
11 |
*/ |
|
12 |
this.open = function() { |
|
13 |
rootElement.classList.remove('hidden'); |
|
14 |
|
|
15 |
diagramForm.appendChild(app.dom.createHtmlElement('div', { class: 'err_msg' })); |
|
16 |
diagramForm.appendChild(app.dom.htmlStringToElement(`<table><tbody><tr><td><label for="diagramName">Diagram name:</label></td><td><input type="text" name="diagramName" value="${app.diagram !== null ? app.diagram.name : ''}" id="diagramName" required></td></tr><tr><td><label for="diagramPublic">Is public:</label></td><td><input type="checkbox" name="diagramPublic" value="1" id="diagramPublic" ${app.diagram !== null && app.diagram.public ? 'checked' : ''}></td></tr><tr><td></td><td><button type="submit" class="button">Save</button></td></tr></tbody></table>`)); |
|
17 |
|
|
18 |
diagramForm.diagramName.focus(); |
|
19 |
}; |
|
20 |
|
|
21 |
/** |
|
22 |
* Closes this modal window. |
|
23 |
*/ |
|
24 |
this.close = function() { |
|
25 |
rootElement.classList.add('hidden'); |
|
26 |
|
|
27 |
diagramForm.innerHTML = ''; |
|
28 |
}; |
|
29 |
|
|
30 |
/** |
|
31 |
* Creates a new HTML DOM element representing the modal window in memory. Binds user interactions to local handler functions. |
|
32 |
* @returns {Element} HTML DOM element. |
|
33 |
*/ |
|
34 |
this.render = function() { |
|
35 |
rootElement = app.utils.createHtmlElement('div', { |
|
36 |
'class': 'modal hidden', |
|
37 |
}); |
|
38 |
rootElement.addEventListener('click', this.close); |
|
39 |
|
|
40 |
var modalContent = app.utils.createHtmlElement('div', { |
|
41 |
'class': 'modal-content', |
|
42 |
}); |
|
43 |
modalContent.addEventListener('click', app.utils.stopPropagation); |
|
44 |
rootElement.appendChild(modalContent); |
|
45 |
|
|
46 |
var closeButton = app.utils.createHtmlElement('button', { |
|
47 |
'class': 'close-button button', |
|
48 |
}); |
|
49 |
closeButton.appendChild(app.utils.createTextElement('×')); |
|
50 |
closeButton.addEventListener('click', closeButtonClick.bind(this)); |
|
51 |
modalContent.appendChild(closeButton); |
|
52 |
|
|
53 |
diagramForm = app.dom.createHtmlElement('form', {}); |
|
54 |
diagramForm.addEventListener('submit', saveDiagram.bind(this)); |
|
55 |
modalContent.appendChild(diagramForm); |
|
56 |
|
|
57 |
return rootElement; |
|
58 |
}; |
|
59 |
|
|
60 |
/** |
|
61 |
* Close button click interaction. Closes the modal window. |
|
62 |
* @param {Event} e Click event. |
|
63 |
*/ |
|
64 |
function closeButtonClick(e) { |
|
65 |
this.close(); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Saves diagram. |
|
70 |
* @param {Event} e Submit event. |
|
71 |
*/ |
|
72 |
function saveDiagram(e) { |
|
73 |
e.preventDefault(); |
|
74 |
|
|
75 |
var self = this; |
|
76 |
|
|
77 |
$.ajax({ |
|
78 |
'type': 'POST', |
|
79 |
'url': app.API.saveDiagram, |
|
80 |
'data': { |
|
81 |
'id': app.diagram === null ? null : app.diagram.id, |
|
82 |
'name': e.target.diagramName.value, |
|
83 |
'graphJson': JSON.stringify(app.graphExporter.run()), |
|
84 |
'public': (e.target.diagramPublic.checked | 0).toString(), |
|
85 |
}, |
|
86 |
'success': function(data) { |
|
87 |
app.diagram = new Diagram(data); |
|
88 |
|
|
89 |
document.title = app.NAME + ' - ' + app.diagram.name; |
|
90 |
history.replaceState({} , document.title, app.HOME_URL + 'graph?diagramId=' + app.diagram.id); |
|
91 |
|
|
92 |
self.close(); |
|
93 |
alert('Saved.'); |
|
94 |
}, |
|
95 |
'error': function(xhr) { |
|
96 |
switch (xhr.status) { |
|
97 |
case 401: |
|
98 |
alert('You are either not logged in or not an owner of this diagram.'); |
|
99 |
break; |
|
100 |
default: |
|
101 |
alert('Something went wrong.'); |
|
102 |
} |
|
103 |
}, |
|
104 |
}); |
|
105 |
} |
|
106 |
} |
sources/src/main/webapp/showGraph.jsp | ||
---|---|---|
28 | 28 |
<script src="js/components/group.js"></script> |
29 | 29 |
<script src="js/components/groupVertexList.js"></script> |
30 | 30 |
<script src="js/components/minimap.js"></script> |
31 |
<script src="js/components/modalWindow.js"></script> |
|
31 | 32 |
<script src="js/components/sidebar.js"></script> |
32 | 33 |
<script src="js/components/sidebarExcludedNodeList.js"></script> |
33 | 34 |
<script src="js/components/sidebarUnconnectedNodeList.js"></script> |
Také k dispozici: Unified diff
Diagram can be saved as public