             user_slug: selectedChannel.get('user').slug
           }
         ]
-        link.set 
+        link.set
+          block_id: block.id
           selected: false
           connections: connections
         link.collection.trigger 'model:selected'
         dfd.resolve()
+    dfd.promise
+
+  createOrConnectBlock: (link, selectedChannel)->
+    dfd = Q.defer()
+    if link.has('connections')
+      $.ajax
+        type: "POST"
+        url: "#{sd.API_URL}/channels/#{id}/connections"
+        data:
+          connectable_type: 'Block'
+          connectable_id: link.get('block_id')
+          channel_id: selectedChannel.id
+        success: dfd.resolve
+        error: dfd.error
+    else
+      blocks.create block.toJSON(),
+        url: "#{sd.API_URL}/channels/#{selectedChannel.get('slug')}/blocks"
+        success: dfd.resolve
+        error: dfd.reject
     dfd.promise
       
   showSuccess: =>

    selectedChannel = @selectedChannel
    block = new Block source: link.get('href')
    existingConnections = link.get('connections') or []
    blocks.create block.toJSON(),
      url: "#{sd.API_URL}/channels/#{selectedChannel.get('slug')}/blocks"
      success: (block) ->
        connections = existingConnections.concat [
          {
            title: selectedChannel.get('title')


module.exports = class ImportStatusView extends Backbone.View
  events:
    'click .import__status__inner__connect' : 'connectLinks'

  initialize: ->    
    @selectedChannel = new Channel()
