"use strict";
/*
 * ooiui/static/js/views/science/AnnotationTableView.js
 * View definitions to build a table view of streams
 *
 * Dependencies
 * CSS: 
 * - ooiui/static/css/common/AnnotationTableView.css
 * Partials: 
 * - ooiui/static/js/partials/AnnotationTable.html
 * - ooiui/static/js/partials/AnnotationTableItem.html
 * Libs
 * - ooiui/static/lib/underscore/underscore.js
 * - ooiui/static/lib/backbone/backbone.js
 * - ooiui/static/js/ooi.js
 * Usage
 */

var AnnotationTableView = Backbone.View.extend({
  className: "annotationTableView",
  events:{
    "click #addAnnotation"   : "onAddClick"
  },
  columns: [
      {
        name : 'ui_id',
        label : 'Annotation ID' //not the same as the uframe id
      },
      {
        name : 'annotation',
        label : 'Annotation'
      },
      {
        name : 'referenceDesignator',
        label : 'Reference Designator'
      },      
      {
        name : 'beginDT',
        label : 'Date Time (Start)'
      },
      {
        name : 'endDT',
        label : 'Date Time (End)'
      }      
  ],
  initialize: function() {
    _.bindAll(this, "render");    
  },
  template: JST['ooiui/static/js/partials/AnnotationTable.html'],
  onAddClick: function(event) {
    event.stopPropagation();
    ooi.trigger('AnnotationTableView:onAddClick');
  },
  render: function() {    
    var self = this;
    this.$el.html(this.template({collection: this.collection, columns: this.columns}));
    this.collection.each(function(model, i) {
      console.log(model);
      model.set('ui_id',i)

      var streamTableItemView = new AnnotationTableItemView({
        columns: self.columns,
        model: model
      });
      self.$el.find('tbody').append(streamTableItemView.el);
    });
  }
});

var AnnotationTableItemView = Backbone.View.extend({
  tagName: 'tr',
  events: {
    'click' : 'onClick'
  },
  initialize: function(options) {
    if(options && options.columns) {
      this.columns = options.columns;
    }
    this.listenTo(this.model, 'change', this.render);
    this.render();
  },
  onClick: function(event) {
    event.stopPropagation();
    ooi.trigger('AnnotationTableItemView:onClick', this.model);
  },
  template: JST['ooiui/static/js/partials/AnnotationTableItem.html'],
  render: function() {
    this.$el.html(this.template({model: this.model, columns: this.columns}));
  }
});


@@ -145,18 +145,17 @@
 %0A * CSS:
- 
 %0A
+
  * - ooi
@@ -211,17 +211,16 @@
 artials:
- 
 %0A * - oo
@@ -889,22 +889,16 @@
       %7D,
-      
 %0A      %7B
@@ -1042,22 +1042,16 @@
 %0A      %7D
-      
 %0A  %5D,%0A  
@@ -1105,20 +1105,16 @@
 ender%22);
-    
 %0A  %7D,%0A  
@@ -1316,20 +1316,16 @@
 tion() %7B
-    
 %0A    var
@@ -1426,16 +1426,16 @@
 mns%7D));%0A
+
     this
@@ -1476,34 +1476,8 @@
 ) %7B%0A
-      console.log(model);%0A
     

remove console log