define([
    'views/list',
    'views/graph/graph-manager/graph-base',
    'models/graph',
    'knockout'
], function(ListView, GraphBase, GraphModel , ko) {
    var BranchList = ListView.extend({
        /**
        * A backbone view to manage a list of branch graphs
        * @augments ListView
        * @constructor
        * @name BranchList
        */

        /**
        * initializes the view with optional parameters
        * @memberof BranchList.prototype
        * @param {object} options
        * @param {boolean} options.graphModel - a reference to the selected {@link GraphModel}
        * @param {boolean} options.branches - an observableArray of branches
        */
        initialize: function(options) {
            var self = this;
            ListView.prototype.initialize.apply(this, arguments);

            this.loading = options.loading || ko.observable(false);
            this.failed = options.failed || ko.observable(false);
            this.disableAppendButton = options.disableAppendButton || ko.observable(false);
            this.graphModel = options.graphModel;
            this.selectedNode = this.graphModel.get('selectedNode');
            options.branches.forEach(function (branch) {
                branch.selected = ko.observable(false);
                branch.filtered = ko.observable(false);
                branch.graphModel = new GraphModel({
                    data: branch
                })
                this.items.push(branch);
            }, this);
            this.selectedBranch = ko.observable(null);
            this.viewMetadata = ko.observable(false);

            var valueListener = ko.computed(function() {
                var node = self.selectedNode;
                if(!!node()){
                    var oc = node().ontologyclass();
                    var datatype = node().datatype();
                    var collector = node().isCollector();
                    return oc + datatype + collector;
                }
                return false;
            });

            var updateList = function(){
                if(this.selectedNode()){
                    _.each(this.items(), function(branch){
                        branch.filtered(true);
                        if(this.graphModel.canAppend(branch.graphModel)){
                            branch.filtered(false);
                        }
                    }, this);
                }
            }
            valueListener.subscribe(updateList, this);
            updateList.call(this);
        },

        /**
        * Sets the selected branch from the users selection
        * @memberof BranchList.prototype
        * @param {object} item - the branch object the user selected
        * @param {object} evt - click event object
        */
        selectItem: function(item, evt){
            ListView.prototype.selectItem.apply(this, arguments);

            if(item.selected()){
                this.selectedBranch(item);
                this.graph = new GraphBase({
                    el: $('#branch-preview'),
                    graphModel: item.graphModel
                });
                this.viewMetadata(true);
            }else{
                this.selectedBranch(null);
                this.viewMetadata(false);
            }
        },

        /**
        * Appends the currently selected branch onto the currently selected node in the graph
        * @memberof BranchList.prototype
        * @param {object} item - the branch object the user selected
        * @param {object} evt - click event object
        */
        appendBranch: function(item, evt){
            var self = this;
            if(this.selectedNode()){
                this.loading(true);
                this.failed(false);
                this.graphModel.appendBranch(this.selectedNode().nodeid, null, item.graphModel, function(response, status){
                    this.loading(false);
                    _.delay(_.bind(function(){
                        this.failed(status !== 'success');
                        if(!(this.failed())){
                            this.closeForm();
                        }
                    }, this), 300, true);
                }, this)
            }
        },

        /**
        * Closes the form and deselects the currently selected branch
        * @memberof BranchList.prototype
        */
        closeForm: function(){
            this.clearSelection();
            this.selectedBranch(null);
            this.viewMetadata(false);

            this.trigger('close');
        },


    });
    return BranchList;
});

@@ -2020,24 +2020,25 @@
        %7D);%0A%0A
+%0A
             
@@ -2043,23 +2043,30 @@
   va
-r updateList = 
+lueListener.subscribe(
 func
@@ -2083,33 +2083,36 @@
               if
-(
+ (!!
 this.selectedNod
@@ -2141,29 +2141,20 @@
     
-_.each(this.items(), 
+this.filter_
 func
@@ -2162,16 +2162,10 @@
 ion(
-branch)%7B
+);
 %0A   
@@ -2164,32 +2164,39 @@
 n();%0A           
+     %7D%0A
              bra
@@ -2195,29 +2195,160 @@
     
- branch.filtered(true
+%7D, this);%0A%0A            // need to call this on init so that branches that can't be appended get filtered out initially%0A            this.filter_function(
 );%0A 
@@ -2350,32 +2350,36 @@
 ();%0A        
+%7D,%0A%0A
         
         if(t
@@ -2362,32 +2362,36 @@
 %7D,%0A%0A        
+/**%0A
         
 if(this.grap
@@ -2382,57 +2382,123 @@
     
-if(this.graphModel.canAppend(branch.graphModel))%7B
+* Callback function called every time a user types into the filter input box%0A        * @memberof ListView.prototype
 %0A   
@@ -2498,32 +2498,35 @@
 ype%0A        
+*/%0A
         
             
@@ -2517,41 +2517,88 @@
     
-            branch.filtered(fal
+filter_function: function()%7B%0A            var filter = this.filter().toLowerCa
 se
+(
 );%0A 
@@ -2612,49 +2612,217 @@
     
-            %7D%0A                    %7D, this
+this.items().forEach(function(item)%7B%0A                var name = typeof item.name === 'string' ? item.name : item.name();%0A                if (!item.filtered) %7B%0A                    item.filtered = ko.observable(
 );%0A 
@@ -2854,93 +2854,217 @@
     
+  
-%7D%0A            valueListener.subscribe(updateList, this);%0A            updateList.call(
+  item.filtered(true);%0A                if(name.toLowerCase().indexOf(filter) !== -1 && this.graphModel.canAppend(item.graphModel))%7B%0A                    item.filtered(false);%0A                %7D%0A            %7D, 
 this

fix bug where filtering the branch list could expose branches that couldn't be appended causing an error, re #2306