ns('Carib.Order.Widgets');

/**
 * Tourist window
 * 
 * @version $Id: tourist_win.js 547 2009-09-14 15:18:36Z  $
 */
Carib.Order.Widgets.TouristWin = function(config) {
  config = $.extend({
    auto_init: false,
    window_config: {
      autoOpen: false,
      title: 'Турист',
      modal: true,
      dialogClass: 'order_wizard',
      resizable: false,
      closeOnEscape: false,
      position: ['right', 'top'],
      buttons: {
        'Отмена': this.onCancel.createDelegate(this),
        'OK': this.onOk.createDelegate(this)
      }
    },
    form: null // required      
  }, config);
  
  var form_size = config.form.getSize();
  config.window_config.width = form_size.width + 30;
  config.window_config.height = form_size.height + 120;
  
  this.button_processing = false;
  
  this.addEvents({
    ok: true,
    cancel: true
  });
  
  Carib.Order.Widgets.TouristWin.superclass.constructor.call(this, config);
}

utils.extend(Carib.Order.Widgets.TouristWin, Carib.Order.Widgets.Window, {
  getForm: function() {
    return this.form;
  },
  
  onShow: function() {
    Carib.Order.Widgets.TouristWin.superclass.onShow.call(this);
    
    this.form.updateFields();
  },
  
  onHide: function() {
    Carib.Order.Widgets.TouristWin.superclass.onHide.call(this);
    
    if(!this.button_processing)
      this.fireEvent('cancel', [this]);
  },
  
  onOk: function() {
    if(!this.form.validate())
      return;
      
    this.button_processing = true;
    this.hide();
    this.form.updateRecord();
    this.fireEvent('ok', [this]);
    this.button_processing = false;
  },
  
  onCancel: function() {
    this.button_processing = true;
    this.hide();
    this.fireEvent('cancel', [this]);
    this.button_processing = false;    
  }
});

