ns('Carib.Order.Widgets');

/**
 * Tourists table
 * 
 * @version $Id: tourists_table.js 547 2009-09-14 15:18:36Z  $
 */
Carib.Order.Widgets.TouristsTable = function(config) {
  config = $.extend({
    column_model: [ 'surname', 'name', 'birthday', 'sex', 'passport', 'child', 'visa', 'insurance', 'control' ],
    hide_empty: true,
    remove_msg: 'Вы уверены, что хотите удалить туриста?'
  }, config || {});
  
  Carib.Order.Widgets.TouristsTable.superclass.constructor.call(this, config);
}

utils.extend(Carib.Order.Widgets.TouristsTable, Carib.Order.Widgets.EditableTable, {
  _getRowClass: function(record, num) {
    return num % 2 == 0 ? 'two' : false; 
  },
  
  _removeRow: function(record, num) {
    Carib.Order.Widgets.TouristsTable.superclass._removeRow.call(this, record, num);
    
    this._updateParity();
  },  
  
  _updateParity: function() {
    this.recordset.each(function(num, record) {
      var $row = this.getTableRow(record);
      if(num % 2 == 0)
        $row.addClass('two');
      else
        $row.removeClass('two');
    }, this);
  },
  
  _birthdayRenderer: function(record) {
    return { content: record.get('birthday') ? $.strftime('%d.%m.%Y', record.get('birthday')) : '' }
  },
  
  _passportRenderer: function(record) {
    var content = '';
    content += '<div><strong>Серия и номер:</strong><br/>' + record.data.passport_number + '</div>';
    content += '<div><strong>Дата выдачи:</strong><br/>' + (record.data.passport_date ? $.strftime('%d.%m.%Y', record.data.passport_date) : '') + '</div>';
    content += '<div><strong>Кем выдан:</strong><br/>' + record.data.passport_hand + '</div>';
    return { content: content };
  },
  
  _childRenderer: function(record) {
    var content = '';
    if(record.data.has_child)
      content = '<div>' + record.data.child_age + '</div>';
      
    return { content: content };
  }
});
