var showView = Backbone.View.extend({
initialize: function(options){
var that = this;
that.metaCollection = options["metaCollection"];
that.snapView = options["snapView"];
this.model = options["model"];
this.depth = options["depth"];
(that.model.attributes["views"] = this.model.attributes["views"] || []).push(that);
that.$el.attr("data-id", that.model.get("_id")); //booya!
this.childViews = [];
},
tagName: 'li',
className: "herez node",
events: {"click .markdown" : "showMarkDownEditor"},
findModel: function(id){
if(this.snapView){
return this.metaCollection.findWhere({cur_id: id});
}
else{
return this.metaCollection.findWhere({_id: id});
}
},
//todo = refactor this function.
render: function(){
var that = this;
that.$el.html("");
var id = that.model.get("_id");
var text = that.model.get("text");
var html = that.createUIBullet(id, text, that.depth);
that.$el.children("ul").addClass("collapsed");
that.$el.attr("data-depth", that.depth);
that.$el.attr("data-id", id);
that.$el.html(html);
if(that.snapView){
that.$el.children().children("textarea").prop("disabled", true);
that.$el.addClass("snapLI");
}
console.log("about to render textarea")
that.renderChildren();
return that;
},
renderChildren: function(){
var that = this;
var childrenIds = that.model.get("children");
_.each(childrenIds, function(childId, index){
var childModel = that.findModel(childId);
var tempView = new showView({
depth: that.depth + 1,
model: childModel,
metaCollection: that.metaCollection,
snapView: that.snapView
});
that.childViews.push(tempView)
that.$el.children("ul").append(tempView.render().$el);
});
},
unhide: function(){
alert("bleh");
},
//Moved to app.js to handle bubbling issues.
// collapse: function(){
// var that = this;
// that.$el.children("ul").slideToggle(110);
// that.$el.children(".zoomButton").toggleClass("collapsed");
// },
createUIBullet: function( id , text, depth) {
var that = this;
var textArea = "";
var expandCollapse = "+"
// var aButton = "" + "";
// var handle = "
"
var zoomButton = ""
// var buttonHoist = ""
var subList = "
" + textarea.val() + "