           flow.tasks = _.reject flow.tasks, (task) ->
             task.taskId == taskId
           @setState flows: newFlows
+
+    insertPhase: (newPhase) ->
+      newPhase.paper = @state.paper
+      newFlows = @state.flows.slice(0) #don't mutate old state
+      [head, tail] =  _.partition newFlows, (flow) ->
+        flow.position < newPhase.position
+      _.map tail, (flow) ->
+        flow.position += 1
+      updatedFlows = head.concat newPhase, tail
+      @setState flows: updatedFlows
 
     addColumn: (position) ->
       newPosition = position + 1

        data:
          phase:
            task_manager_id: @state.paper.task_manager_id
            position: column.position
            name: column.name
        success: (data) =>
          newPhase = data.phase
          newPhase.paper = @state.paper
          newFlows = @state.flows.slice(0) #don't mutate old state
          newFlows.splice(newPosition, 0, newPhase)
          @setState flows: newFlows


  Column: React.createClass

      Tahi.utils.bindColumnResize()

      $.getJSON @props.route, (data,status) =>
        @setState flows: _.sortBy(data.flows, (f) -> f.position), paper: data.paper

    componentDidUpdate: ->
      Tahi.utils.resizeColumnHeaders()
