From 9c8843104de1540f51f669f9c9e6e74eeed9a79f Mon Sep 17 00:00:00 2001 From: Philip Schatz Date: Thu, 31 Oct 2013 15:32:25 -0400 Subject: [PATCH] make dfs/bfs and getChildren optional Folders to not use TocPointerNode so they do not have a tree structure --- scripts/mixins/tree.coffee | 4 ++-- scripts/views/layouts/workspace/sidebar.coffee | 2 +- scripts/views/workspace/sidebar/toc-branch.coffee | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/mixins/tree.coffee b/scripts/mixins/tree.coffee index 3498796e..9e93a0da 100644 --- a/scripts/mixins/tree.coffee +++ b/scripts/mixins/tree.coffee @@ -65,7 +65,7 @@ define ['backbone'], (Backbone) -> # Perform a Breadth First Search, returning the first element that matches findDescendantBFS: (compare) -> #Check children first and then descendants - return @getChildren().find(compare) or @getChildren().find (node) -> node.findDescendantBFS(compare) + return @getChildren().find(compare) or @getChildren().find (node) -> node.findDescendantBFS?(compare) # Perform a Depth First Search, returning the first element that matches findDescendantDFS: (compare) -> @@ -78,7 +78,7 @@ define ['backbone'], (Backbone) -> # because `.find` returns the element, not what was returned to find @getChildren().each (node) -> return if ret # if something is found, stop searching - found = node.findDescendantDFS(compare) + found = node.findDescendantDFS?(compare) ret = found return ret diff --git a/scripts/views/layouts/workspace/sidebar.coffee b/scripts/views/layouts/workspace/sidebar.coffee index 8c370c40..579afcfc 100644 --- a/scripts/views/layouts/workspace/sidebar.coffee +++ b/scripts/views/layouts/workspace/sidebar.coffee @@ -28,7 +28,7 @@ define [ onShow: () -> model = @model - collection = @collection or model.getChildren() + collection = @collection or model.getChildren?() if model # This is a tree sidebar diff --git a/scripts/views/workspace/sidebar/toc-branch.coffee b/scripts/views/workspace/sidebar/toc-branch.coffee index 5acf985a..2d203b87 100644 --- a/scripts/views/workspace/sidebar/toc-branch.coffee +++ b/scripts/views/workspace/sidebar/toc-branch.coffee @@ -145,7 +145,7 @@ define [ # if the user hasn't set the state yet make sure the active file is visible if @model.expanded == undefined - hasDescendant = @model.findDescendantBFS (child) -> + hasDescendant = @model.findDescendantBFS? (child) -> # Dereference if the child is a pointer-node child = child.dereferencePointer?() or child return child.get('_selected') @@ -177,7 +177,7 @@ define [ return { isPicker: @options.isPicker - childIsSelected: @model.findDescendantBFS (child) -> (child.dereferencePointer?() or child).get('_selected') + childIsSelected: @model.findDescendantBFS? (child) -> (child.dereferencePointer?() or child).get('_selected') selected: model.get('_selected') ancestorSelected: @options.ancestorSelected mediaType: model.mediaType @@ -219,9 +219,9 @@ define [ model = @model if not model.getRoot?() # Find the 1st leaf node (editable model) - model = model.findDescendantDFS (model) -> return model.getChildren().isEmpty() + model = model.findDescendantDFS? (model) -> return model.getChildren().isEmpty() - controller.goEdit(model, model.getRoot()) + controller.goEdit(model, model.getRoot?()) editSettings: ->