Code coverage report for code/utils/js-plumb-diagram-toolkit.coffee

Statements: 0% (0 / 48)      Branches: 0% (0 / 10)      Functions: 0% (0 / 18)      Lines: 0% (0 / 44)      Ignored: none     

All files » code/utils/ » js-plumb-diagram-toolkit.coffee
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                                                                                                                                                                                                                                                                                   
# Purpose of this class: Provide an abstraction over our chosen diagramming toolkit.
 
module.exports = class DiagramToolkit
 
  constructor: (@domContext, @options = {}) ->
    @type      = "jsPlumbWrappingDiagramToolkit"
    @color     = @options.color or '#233'
    @lineWidth = @options.lineWidth or 1
    @lineWidth = 1
    @kit       = jsPlumb.getInstance {Container: @domContext}
    @kit.importDefaults
      Connector:        ["Bezier", {curviness: 60}],
      Anchor:           "Continuous",
      DragOptions :     {cursor: 'pointer', zIndex:2000},
      ConnectionsDetachable: true,
      DoNotThrowErrors: false
    @registerListeners()
 
  registerListeners: ->
    @kit.bind 'connection', @handleConnect.bind @
 
  handleConnect: (info, evnt)  ->
    @options.handleConnect? info, evnt
    true
 
  handleClick: (connection, evnt) ->
    @options.handleClick? connection, evnt
 
  handleLabelClick: (label, evnt) ->
    @options.handleClick? label.component, evnt
 
  handleDisconnect: (info, evnt) ->
    return (@options.handleDisconnect? info, evnt) or true
 
  repaint: ->
    @kit.repaintEverything()
 
  _endpointOptions: [ "Dot", { radius:15 } ]
 
  makeSource: (div) ->
    @kit.addEndpoint(div,
      isSource: true
      connector: ["Bezier"]
      dropOptions:
        activeClass: "dragActive"
      anchor: "Center"
      #paintStyle: @_paintStyle()
      endpoint: ["Rectangle",
        width: 19
        height: 19
        cssClass: 'node-link-button'
      ]
      maxConnections: -1
    )
 
  makeTarget: (div) ->
    size = 60
    @kit.addEndpoint(div,
      isTarget: true
      isSource: false
      connector: ["Bezier"]
      anchor: "Center"
      endpoint: ["Rectangle",
        height: size
        width: size
        cssClass: "node-link-target"
      ]
      maxConnections: -1
      dropOptions:
        activeClass: "dragActive"
     )
 
  clear: ->
    if @kit
      @kit.deleteEveryEndpoint()
      @kit.reset()
      @registerListeners()
    else
      log.info "No kit defined"
 
  _paintStyle: (color) ->
    strokeStyle: color or @color,
    lineWidth: @lineWidth
    outlineColor: "rgb(0,240,10)"
    outlineWidth: "10px"
 
  _overlays: (label, selected) ->
    results = [["Arrow", {
      location: 1.0
      length: 10
      width: 10
      events: { click: @handleLabelClick.bind @ }
    }]]
    if label?.length > 0
      results.push ["Label", {
        location: 0.5,
        events: { click: @handleLabelClick.bind @ },
        label: label or '',
        cssClass: "label#{if selected then ' selected' else ''}"
      }]
    results
 
  _clean_borked_endpoints: ->
    $('._jsPlumb_endpoint:not(.jsplumb-draggable)').remove()
 
  addLink: (source, target, label, color, isSelected, linkModel) ->
    paintStyle = @_paintStyle color
    paintStyle.outlineColor = "none"
    paintStyle.outlineWidth = 20
    if isSelected
      paintStyle.outlineColor = "#f6bf33"
      paintStyle.outlineWidth = 1
 
    connection = @kit.connect
      source: source
      target: target
      paintStyle: paintStyle
      overlays: @_overlays label, isSelected
      endpoint: ["Rectangle",
        width: 10
        height: 10
        cssClass: 'node-link-target'
      ]
 
    connection.bind 'click', @handleClick.bind @
    connection.linkModel = linkModel
 
  setSuspendDrawing: (shouldwestop) ->
    if not shouldwestop
      @_clean_borked_endpoints()
    @kit.setSuspendDrawing shouldwestop, not shouldwestop
 
  supspendDrawing: ->
    @setSuspendDrawing true
 
  resumeDrawing: ->
    @setSuspendDrawing false