From 1e224370e28fd2f0f0895357973bd7690e00718f Mon Sep 17 00:00:00 2001 From: jdotzki Date: Tue, 14 Oct 2014 09:12:03 +0200 Subject: [PATCH] improve(resize): restrict resizable elements related bpmn-io/bpmn-js#140 --- lib/Modeler.js | 3 +- .../resize/BpmnResizableElements.json | 6 ++++ lib/features/resize/BpmnResizeHandler.js | 28 +++++++++++++++++++ lib/features/resize/index.js | 7 +++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 lib/features/resize/BpmnResizableElements.json create mode 100644 lib/features/resize/BpmnResizeHandler.js create mode 100644 lib/features/resize/index.js diff --git a/lib/Modeler.js b/lib/Modeler.js index f90d5991..14e92f7a 100644 --- a/lib/Modeler.js +++ b/lib/Modeler.js @@ -69,7 +69,8 @@ Modeler.prototype._modelingModules = [ require('diagram-js/lib/features/resize'), require('./features/modeling'), require('./features/context-pad'), - require('./features/palette') + require('./features/palette'), + require('./features/resize') ]; diff --git a/lib/features/resize/BpmnResizableElements.json b/lib/features/resize/BpmnResizableElements.json new file mode 100644 index 00000000..cf845eb6 --- /dev/null +++ b/lib/features/resize/BpmnResizableElements.json @@ -0,0 +1,6 @@ +{ + "elements": [ + "bpmn:Task", + "bpmn:SubProcess" + ] +} diff --git a/lib/features/resize/BpmnResizeHandler.js b/lib/features/resize/BpmnResizeHandler.js new file mode 100644 index 00000000..5a88a136 --- /dev/null +++ b/lib/features/resize/BpmnResizeHandler.js @@ -0,0 +1,28 @@ +'use strict'; + +var _ = require('lodash'); + +var resizableElements = require('./BpmnResizableElements.json').elements; + + +function BpmnResizeHandler(eventBus, resize) { + + var isResizeAllowed = function(element) { + var isAllowed = _.contains(resizableElements, element.type); + + if (isAllowed) { + return true; + } else { + return false; + } + }; + + // Register Handler + eventBus.on('canvas.init', function() { + resize.registerResizableHandler(isResizeAllowed); + }); +} + +module.exports = BpmnResizeHandler; + +BpmnResizeHandler.$inject = [ 'eventBus', 'resize' ]; diff --git a/lib/features/resize/index.js b/lib/features/resize/index.js new file mode 100644 index 00000000..6ec21321 --- /dev/null +++ b/lib/features/resize/index.js @@ -0,0 +1,7 @@ +module.exports = { + __depends__: [ + require('diagram-js/lib/features/resize') + ], + __init__: [ 'bpmnResizeHandler' ], + bpmnResizeHandler: [ 'type', require('./BpmnResizeHandler') ] +};