function get_driver_lines( my_obj ) {
  var result = [];
  if ('driver_lines' in my_obj) {
    result = my_obj.driver_lines.map( function (_id) { return DriverLines.findOne(_id) } );
   }
  return result;
}

function get_neuron_types( my_obj ) {
  var result = [];
  if ('neuron_types' in my_obj) {
    result = my_obj.neuron_types.map( function (_id) { return NeuronTypes.findOne(_id) } );
   }
  return result;
}

function get_neuropiles( my_obj ) {
  var result = [];
  if ('neuropiles' in my_obj) {
    result = my_obj.neuropiles.map( function (_id) { return Neuropiles.findOne(_id) } );
   }
  return result;
}

// -------------

Template.show_dialog.modal_title = function () {
  var tmp = Session.get("modal_info");
  if (tmp) return tmp.modal_title;
}

Template.show_dialog.modal_body = function () {
  return "modal body";
}

open_insert_edit_dialog = function (modal_title) {
  // A general purpose dialog for inserting a new entry or editing an
  // existing entry.
  Session.set("modal_info", {modal_title: modal_title});
  $("#show_dialog_id").modal("show");
}

var jump_table = {
  'DriverLines': {'remove': function (x) { remove_driver_line(x); },
		  'edit':   function (x) { edit_driver_line(x); }
		 },
  'NeuronTypes': {'remove': function (x) { remove_neuron_type(x); },
		  'edit':   function (x) { edit_neuron_type(x); }
		 },
  'Neuropiles':  {'remove': function (x) { remove_neuropile(x);   },
		  'edit':   function (x) { edit_neuropile(x); }
		 }
}

Template.edit_delete_buttons.events({
  'click button.edit': function(e) {
    e.preventDefault();
    jump_table[this.collection].edit(this.my_id);
  },
  'click button.delete': function(e) {
    e.preventDefault();
    //open_confirm_dialog("Do you want to delete item?"); // TODO XXX FIXME add this
    jump_table[this.collection].remove(this.my_id);
  }
});


// -------------

Template.driver_line_from_id_block.driver_line_from_id = function () {
  var my_id = this;
  if (this.valueOf) { // If we have "valueOf" function, "this" is boxed.
    my_id = this.valueOf(); // unbox it
  }
  return DriverLines.findOne(my_id);
}

Template.driver_lines.driver_line_cursor = function () {
  return DriverLines.find({});
}

Template.driver_lines.events({
  'click a.add': function(e) {
    e.preventDefault();
    open_insert_edit_dialog("Add new driver line");
  }
});

Template.driver_line_show.neuron_types = function () {
  return get_neuron_types(this);
}

Template.driver_line_show.neuropiles = function () {
  return get_neuropiles(this);
}



// -------------

Template.neuron_types.events({
  'click a.add': function(e) {
    e.preventDefault();
    open_insert_edit_dialog("Add new neuron type");
  }
});

Template.neuron_types.neuron_type_cursor = function () {
  return NeuronTypes.find({});
}

Template.neuron_type_show.driver_lines = function () {
  return get_driver_lines(this);
}

Template.neuron_type_show.neuropiles = function () {
  return get_neuropiles(this);
}

// -------------

Template.neuropiles.events({
  'click a.add': function(e) {
    e.preventDefault();
    open_insert_edit_dialog("Add new neuropile");
  }
});

Template.neuropiles.neuropile_cursor = function () {
  return Neuropiles.find({});
}

Template.neuropile_show.driver_lines = function () {
  return get_driver_lines(this);
}

Template.neuropile_show.neuron_types = function () {
  return get_neuron_types(this);
}

// ------- tab layout stuff ----

Template.MyLayout.tab_attrs_home = function () {
  var current = Router.current();
  if (current && current.route.name=='home') {
    return {'class':"active"};
  }
}

Template.MyLayout.tab_attrs_driver_lines = function () {
  var cur = Router.current();
  if (cur && cur.route.name=='driver_lines' || cur.route.name=='driver_line_show' ) {
    return {'class':"active"};
  }
}

Template.MyLayout.tab_attrs_neuron_types = function () {
  var cur = Router.current();
  if (cur && cur.route.name=='neuron_types' || cur.route.name=='neuron_type_show') {
    return {'class':"active"};
  }
}

Template.MyLayout.tab_attrs_neuropiles = function () {
  var cur = Router.current();
  if (cur && cur.route.name=='neuropiles' || cur.route.name=='neuropile_show') {
    return {'class':"active"};
  }
}

// -------------

UI.body.getData = function () {
  return 'data';
};

@@ -17,16 +17,20 @@
 ver_line
+_doc
 s( my_ob
@@ -27,32 +27,32 @@
 ocs( my_obj ) %7B%0A
-
   var result = %5B
@@ -229,16 +229,20 @@
 ron_type
+_doc
 s( my_ob
@@ -409,32 +409,32 @@
 turn result;%0A%7D%0A%0A
-
 function get_neu
@@ -439,16 +439,20 @@
 europile
+_doc
 s( my_ob
@@ -2419,32 +2419,36 @@
  get_neuron_type
+_doc
 s(this);%0A%7D%0A%0ATemp
@@ -2432,32 +2432,32 @@
 ype_docs(this);%0A
-
 %7D%0A%0ATemplate.driv
@@ -2510,32 +2510,36 @@
 rn get_neuropile
+_doc
 s(this);%0A%7D%0A%0A%0A%0A//
@@ -2863,32 +2863,36 @@
  get_driver_line
+_doc
 s(this);%0A%7D%0A%0ATemp
@@ -2962,16 +2962,20 @@
 europile
+_doc
 s(this);
@@ -3302,16 +3302,20 @@
 ver_line
+_doc
 s(this);
@@ -3363,32 +3363,32 @@
 = function () %7B%0A
-
   return get_neu
@@ -3395,16 +3395,20 @@
 ron_type
+_doc
 s(this);

improve JS names