diff --git a/src/main/resources/Diagram/DiagramMacro.xml b/src/main/resources/Diagram/DiagramMacro.xml index c1b84fd..0b86844 100644 --- a/src/main/resources/Diagram/DiagramMacro.xml +++ b/src/main/resources/Diagram/DiagramMacro.xml @@ -163,45 +163,50 @@ {{velocity output="false"}} #macro (displayDiagram $reference) #set ($discard = $xwiki.ssx.use('Diagram.DiagramSheet')) - (% class="diagram-container" %)((( - (% class="thumbnail" %)((( - #if ($services.security.authorization.hasAccess('view', $reference)) - #set ($diagram = $xwiki.getDocument($reference)) - #set ($diagramTitle = $diagram.plainTitle) - #if ($diagram.getObject('Diagram.DiagramClass')) - #if ($xcontext.action == 'edit' || ($xcontext.macro.params.cached == 'true' && $xcontext.action != 'export')) - {{html clean="false"}} - $!diagram.getValue('svg') - {{/html}} - #else - {{display reference="$services.rendering.escape($reference, $xcontext.macro.doc.syntax)" /}} - #end - #else - {{warning}}$services.localization.render('diagram.macro.invalidReference'){{/warning}} - #end + #set ($showCaption = true) + #if ($services.security.authorization.hasAccess('view', $reference)) + #set ($diagram = $xwiki.getDocument($reference)) + #set ($diagramTitle = $diagram.plainTitle) + #if ($diagram.getObject('Diagram.DiagramClass')) + #if ($xcontext.action == 'edit' || ($xcontext.macro.params.cached == 'true' && $xcontext.action != 'export')) + #set ($output = "{{html clean='false'}}$!diagram.getValue('svg'){{/html}}") #else - {{warning}}$services.localization.render('diagram.macro.viewNotAllowed'){{/warning}} - #if ($reference.name == $services.model.getEntityReference('DOCUMENT', 'default')) - #set ($diagramTitle = $reference.parent.name) - #else - #set ($diagramTitle = $reference.name) - #end + #set ($output = "{{display reference='$services.rendering.escape($reference, $xcontext.macro.doc.syntax)' /}}") + #set ($showCaption = false) #end + #else + #set ($output = "{{warning}}$services.localization.render('diagram.macro.invalidReference'){{/warning}}") + #end + #else + #set ($output = "{{warning}}$services.localization.render('diagram.macro.viewNotAllowed'){{/warning}}") + #if ($reference.name == $services.model.getEntityReference('DOCUMENT', 'default')) + #set ($diagramTitle = $reference.parent.name) + #else + #set ($diagramTitle = $reference.name) + #end + #end + #if ($showCaption) + (% class="diagram-container" %)((( + (% class="thumbnail" %)((( + #end + $output + #if ($showCaption) - {{html clean="true"}} - <div class="caption"> - <a class="diagram-title" href="$xwiki.getURL($reference)" - title="$escapetool.xml($services.localization.render('diagram.macro.view'))" - >$escapetool.xml($diagramTitle)</a> - #if ($services.security.authorization.hasAccess('edit', $reference)) - <a class="diagram-edit" href="$xwiki.getURL($reference, 'edit', $NULL)" - title="$escapetool.xml($services.localization.render('diagram.macro.edit'))" - target="_blank">$services.icon.renderHTML('pencil')</a> - #end - </div> - {{/html}} + {{html clean="true"}} + <div class="caption"> + <a class="diagram-title" href="$xwiki.getURL($reference)" + title="$escapetool.xml($services.localization.render('diagram.macro.view'))" + >$escapetool.xml($diagramTitle)</a> + #if ($services.security.authorization.hasAccess('edit', $reference)) + <a class="diagram-edit" href="$xwiki.getURL($reference, 'edit', $NULL)" + title="$escapetool.xml($services.localization.render('diagram.macro.edit'))" + target="_blank">$services.icon.renderHTML('pencil')</a> + #end + </div> + {{/html}} + ))) ))) - ))) + #end #end #macro (createDiagram $reference) diff --git a/src/main/resources/Diagram/DiagramViewSheet.xml b/src/main/resources/Diagram/DiagramViewSheet.xml index 3aef71f..5017ba7 100644 --- a/src/main/resources/Diagram/DiagramViewSheet.xml +++ b/src/main/resources/Diagram/DiagramViewSheet.xml @@ -68,7 +68,9 @@ #set ($discard = $xwiki.jsx.use('Diagram.DiagramViewSheet')) {{html clean="false"}} ## Check if the query contains the parameter for getting the diagram from URL. - <div class="diagram loading" #if ("$!request.source" == '') data-model="$escapetool.xml($tdoc.content)" #end></div> + <div class="diagram loading"#if ("$!request.source" == '') data-model="$escapetool.xml($tdoc.content)" + data-reference="$escapetool.xml($services.model.serialize($tdoc.documentReference, 'default'))" + data-title="$escapetool.xml($tdoc.plainTitle)"#end></div> {{/html}} #end #end @@ -320,9 +322,6 @@ define('spin-global', ['spin'], function(spin) { // This is required for the clipart images. GraphViewer.prototype.imageBaseUrl = getOrigin(); - // We don't support loading multiple pages (tabbed UI). - EditorUi.prototype.initPages = function() {}; - // Fix the diagram printing from the lightbox. mxPrintPreview#addGraphFragment optimizes the diagram rendering when // previewing the print by rendering only the shapes that intersect the clip associated with the print page. The // computations are wrong in view mode (either when computing the bounding rect of the shapes or the clip of the print @@ -333,15 +332,48 @@ define('spin-global', ['spin'], function(spin) { // See https://github.com/jgraph/mxgraph/commit/d5c1345ec946b9d55a9c2a8c1c5df0f154561edf mxPrintPreview.prototype.clipping = false; - $.fn.viewDiagram = function(options) { - options = $.extend({ + var getDiagramViewerConfig = function(diagramContainer) { + var config = { + title: diagramContainer.data('title'), lightbox: false, - toolbar: 'zoom layers lightbox' - }, options); + toolbar: 'zoom layers pages lightbox', + 'toolbar-buttons': { + edit: { + title: mxResources.get('edit'), + image: Editor.editImage + } + } + }; + if (diagramContainer.data('reference')) { + config.toolbar = 'edit ' + config.toolbar; + var diagramReference = XWiki.Model.resolve(diagramContainer.data('reference'), XWiki.EntityType.DOCUMENT); + config.reference = diagramReference; + var diagramEditURL = new XWiki.Document(diagramReference).getURL('edit'); + config['toolbar-buttons'].edit.handler = function() { + window.location.href = diagramEditURL; + }; + } + var toolbar = diagramContainer.data('toolbar'); + if (toolbar === 'false') { + delete config.toolbar; + } else if (typeof toolbar === 'string') { + config.toolbar = toolbar; + } + return config; + }; + + $.fn.viewDiagram = function(configOverride) { return this.each(function() { var diagramXML = diagramUtils.getDiagramXMLFromURL(window.location.href) || $(this).data('model'); var diagramRootNode = mxUtils.parseXml(diagramXML).documentElement; - var graphViewer = new GraphViewer(this, diagramRootNode, options); + var config = $.extend(getDiagramViewerConfig($(this)), configOverride); + var graphViewer = new GraphViewer(this, diagramRootNode, config); + // Make the diagram title from the tool bar a link to the diagram page. + if (config.title && config.reference) { + var diagramViewURL = new XWiki.Document(config.reference).getURL(); + var diagramLink = $('<a/>').attr('href', diagramViewURL).text(config.title); + $(graphViewer.toolbar).children().last().empty().append(diagramLink); + } }).removeClass('loading'); };