Skip to content

Commit 445b1fb

Browse files
committed
Create diagrams in a modal dialog
1 parent b3c964e commit 445b1fb

File tree

6 files changed

+27
-45
lines changed

6 files changed

+27
-45
lines changed

lang/de/lang.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
$lang['missingConfig'] = 'Fehlende Konfiguration für SVG Diagramme: Bitte "svg image/svg+xml" in mime.local.conf ergänzen';
44

55
$lang['js']['createButton'] = 'Erstellen';
6+
$lang['js']['createLink'] = 'Diagramm erstellen';
67
$lang['js']['createIntro'] = 'draw.io Diagramm im aktuellen Namensraum erstellen:';
78
$lang['js']['editButton'] = 'Diagramm editieren';
89
$lang['js']['errorInvalidId'] = 'Name ist leer oder enthält ungültige Zeichen!';

lang/en/lang.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
$lang['missingConfig'] = 'Missing configuration for SVG diagrams: Remeber to add "svg image/svg+xml" to mime.local.conf';
44

55
$lang['js']['createButton'] = 'Create';
6+
$lang['js']['createLink'] = 'Create a diagram';
67
$lang['js']['createIntro'] = 'Create draw.io diagram in current namespace';
78
$lang['js']['editButton'] = 'Edit diagram';
89
$lang['js']['errorInvalidId'] = 'Name is empty or contains invalid characters!';

script.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,35 @@ jQuery( function() {
4444

4545
/**
4646
* Media manager
47+
* FIXME this should be moved to a separate file
4748
*/
49+
50+
/* are we in media manager context? */
4851
const $mm_page = jQuery('#mediamanager__page');
4952
const $mm_popup = jQuery('#media__manager');
50-
if (!$mm_page.length && !$mm_popup.length) return;
53+
const isMMPage = $mm_page.length > 0;
54+
const isMMPopup = $mm_popup.length > 0;
55+
if (!isMMPage && !isMMPopup) return;
5156

57+
/* in the namespace tree add a link to create a new diagram */
5258
const $mm_tree = jQuery("#media__tree");
53-
$mm_tree.prepend(newDiagramForm());
54-
55-
// update diagram NS when clicking in media tree
56-
$mm_tree.find('a.idx_dir').each(function (e) {
57-
const $this = jQuery( this );
58-
$this.on('click', function (e) {
59-
e.preventDefault();
60-
61-
const $nsSpan = jQuery('#drawio__current-ns');
62-
$nsSpan.text(extractNs(e.target));
59+
const $createLink = jQuery('<a href="#">' + LANG.plugins.drawio.createLink + '</a>').on('click', function (e) {
60+
e.preventDefault();
61+
newDiagramForm().dialog({
62+
title: LANG.plugins.drawio.createLink,
63+
width: 600,
64+
appendTo: '.dokuwiki',
65+
modal: true,
66+
open: () => {
67+
const ns = isMMPage ? jQuery('.panelHeader h3 strong').html() : jQuery('#media__ns').html();
68+
jQuery('#drawio__current-ns').text(ns);
69+
},
6370
});
6471
});
72+
$mm_tree.prepend($createLink);
6573

66-
// FIXME
67-
if (!$mm_page.length) return;
6874
// attach edit button to detail view of SVG files
75+
if (!isMMPage) return;
6976
$mm_page.on('click', '.panel.filelist .panelContent a', function (e) {
7077

7178
// observe div.file for mutations

script/elements.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
* @returns {jQuery|HTMLElement}
55
*/
66
function newDiagramForm() {
7-
const currentNs = extractNs(location.href);
87
const $createForm = jQuery(
9-
'<form>' +
8+
'<form style="padding: 0.5em;">' +
109
'<div>' + LANG.plugins.drawio.createIntro + ' <strong><span id="drawio__current-ns">' +
11-
currentNs +
1210
'</strong></span></div>' +
1311
'<input type="text" name="drawio-create-filename" id="drawio__create-filename" />' +
1412
'<button id="drawio__create">' + LANG.plugins.drawio.createButton + '</button>' +
@@ -28,16 +26,7 @@ function newDiagramForm() {
2826
function createDiagram(event) {
2927
event.preventDefault();
3028

31-
let href;
32-
// get namespace selected in ns tree
33-
const $selectedNSLink = jQuery('.idx_dir.selected');
34-
if ($selectedNSLink && $selectedNSLink.length > 0) {
35-
href = $selectedNSLink.attr('href');
36-
} else {
37-
// FIXME url rewriting?
38-
href = location.href;
39-
}
40-
const ns = extractNs(href);
29+
const ns = jQuery('#drawio__current-ns').html();
4130
const id = jQuery('#drawio__create-filename').val();
4231

4332
if (!validId(id)) {

script/helpers.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@ function splitFullId(fullId) {
3939
return {ns: ns, id: id};
4040
}
4141

42-
/**
43-
* extract ns param from URL
44-
*
45-
* @param url
46-
* @returns {string}
47-
*/
48-
function extractNs(url) {
49-
const urlParam = function(name) {
50-
const results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(url);
51-
return results[1] || '';
52-
};
53-
return decodeURIComponent(urlParam('ns'));
54-
}
55-
5642
/**
5743
* extract image id from media URL
5844
*

script/service.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const handleServiceMessages = function( event ) {
1515
jQuery.get(DOKU_BASE + 'lib/exe/fetch.php?media=' + fullId, function (data) {
1616
drawio.postMessage(JSON.stringify({action: 'load', xml: data}), '*');
1717
}, 'text')
18-
.fail(function () { // catch 404, file does not exist yet locally
18+
.fail(function () { // catch 404, file does not yet exist locally
1919
drawio.postMessage(JSON.stringify({action: 'load', xml: ''}), '*');
2020
});
2121
} else if ( msg.event === 'save' ) {
@@ -36,10 +36,8 @@ const handleServiceMessages = function( event ) {
3636
jQuery( window ).off( 'message', {fullId: fullId}, handleServiceMessages );
3737
jQuery( '#drawio-frame' ).remove();
3838
const url = new URL(location.href);
39-
// media manager window should reflect selection in ns tree
40-
if (jQuery('#mediamanager__page').length > 0) {
41-
url.searchParams.set('ns', ns);
42-
}
39+
// media manager window should show current namespace
40+
url.searchParams.set('ns', ns);
4341
setTimeout( function() {
4442
location.assign(url);
4543
}, 200 );

0 commit comments

Comments
 (0)