/**
 * Generated by Apache Royale Compiler from org\apache\royale\jewel\beads\views\AlertView.as
 * org.apache.royale.jewel.beads.views.AlertView
 *
 * @fileoverview
 *
 * @suppress {checkTypes|accessControls}
 */

goog.provide('org.apache.royale.jewel.beads.views.AlertView');

goog.require('org.apache.royale.core.IAlertModel');
goog.require('org.apache.royale.core.IBeadLayout');
goog.require('org.apache.royale.core.IParent');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.events.CloseEvent');
goog.require('org.apache.royale.events.IEventDispatcher');
goog.require('org.apache.royale.events.MouseEvent');
goog.require('org.apache.royale.html.beads.GroupView');
goog.require('org.apache.royale.jewel.Alert');
goog.require('org.apache.royale.jewel.Button');
goog.require('org.apache.royale.jewel.ControlBar');
goog.require('org.apache.royale.jewel.Group');
goog.require('org.apache.royale.jewel.Label');
goog.require('org.apache.royale.jewel.TitleBar');
goog.require('org.apache.royale.jewel.VGroup');
goog.require('org.apache.royale.jewel.beads.layouts.HorizontalLayout');
goog.require('org.apache.royale.jewel.beads.views.AlertTitleBarView');
goog.require('org.apache.royale.utils.Language');



/**
 *  constructor.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @constructor
 * @extends {org.apache.royale.html.beads.GroupView}
 */
org.apache.royale.jewel.beads.views.AlertView = function() {
  org.apache.royale.jewel.beads.views.AlertView.base(this, 'constructor');
};
goog.inherits(org.apache.royale.jewel.beads.views.AlertView, org.apache.royale.html.beads.GroupView);


/**
 * Prevent renaming of class. Needed for reflection.
 */
goog.exportSymbol('org.apache.royale.jewel.beads.views.AlertView', org.apache.royale.jewel.beads.views.AlertView);


/**
 * @protected
 * @type {org.apache.royale.core.IAlertModel}
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.alertModel;


/**
 * @export
 * @type {org.apache.royale.jewel.TitleBar}
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.titleBar;


/**
 * @export
 * @type {org.apache.royale.jewel.Group}
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.content;


/**
 * @export
 * @type {org.apache.royale.jewel.Label}
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.label;


/**
 * @export
 * @type {org.apache.royale.core.UIBase}
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.controlBar;


/**
 * @export
 * @type {org.apache.royale.jewel.Button}
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.okButton;


/**
 * @export
 * @type {org.apache.royale.jewel.Button}
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.cancelButton;


/**
 * @export
 * @type {org.apache.royale.jewel.Button}
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.yesButton;


/**
 * @export
 * @type {org.apache.royale.jewel.Button}
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.noButton;


/**
 * @private
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.org_apache_royale_jewel_beads_views_AlertView_prepareForPopUp = function() {
  org.apache.royale.utils.Language.as(this._strand, org.apache.royale.core.UIBase, true).element.classList.add("open");
};


/**
 * @private
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.org_apache_royale_jewel_beads_views_AlertView_createButtons = function() {
  
  this.controlBar = new org.apache.royale.jewel.ControlBar();
  var /** @type {number} */ flags = this.alertModel.flags;
  if (flags & org.apache.royale.jewel.Alert.OK) {
    this.okButton = new org.apache.royale.jewel.Button();
    this.okButton.width = 100;
    this.okButton.emphasis = org.apache.royale.jewel.Button.PRIMARY;
    this.okButton.text = this.alertModel.okLabel;
    this.okButton.addEventListener(org.apache.royale.events.MouseEvent.CLICK, org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_AlertView_handleOK, this, 'handleOK'));
    this.controlBar.addElement(this.okButton);
  }
  if (flags & org.apache.royale.jewel.Alert.CANCEL) {
    this.cancelButton = new org.apache.royale.jewel.Button();
    this.cancelButton.width = 100;
    this.cancelButton.text = this.alertModel.cancelLabel;
    this.cancelButton.addEventListener(org.apache.royale.events.MouseEvent.CLICK, org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_AlertView_handleCancel, this, 'handleCancel'));
    this.controlBar.addElement(this.cancelButton);
  }
  if (flags & org.apache.royale.jewel.Alert.YES) {
    this.yesButton = new org.apache.royale.jewel.Button();
    this.yesButton.width = 100;
    this.yesButton.emphasis = org.apache.royale.jewel.Button.PRIMARY;
    this.yesButton.text = this.alertModel.yesLabel;
    this.yesButton.addEventListener(org.apache.royale.events.MouseEvent.CLICK, org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_AlertView_handleYes, this, 'handleYes'));
    this.controlBar.addElement(this.yesButton);
  }
  if (flags & org.apache.royale.jewel.Alert.NO) {
    this.noButton = new org.apache.royale.jewel.Button();
    this.noButton.width = 100;
    this.noButton.text = this.alertModel.noLabel;
    this.noButton.addEventListener(org.apache.royale.events.MouseEvent.CLICK, org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_AlertView_handleNo, this, 'handleNo'));
    this.controlBar.addElement(this.noButton);
  }
};


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.org_apache_royale_jewel_beads_views_AlertView_handleOK = function(event) {
  this.dispatchCloseEvent(org.apache.royale.jewel.Alert.OK);
};


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.org_apache_royale_jewel_beads_views_AlertView_handleCancel = function(event) {
  this.dispatchCloseEvent(org.apache.royale.jewel.Alert.CANCEL);
};


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.org_apache_royale_jewel_beads_views_AlertView_handleYes = function(event) {
  this.dispatchCloseEvent(org.apache.royale.jewel.Alert.YES);
};


/**
 * @asprivate
 * @private
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.org_apache_royale_jewel_beads_views_AlertView_handleNo = function(event) {
  this.dispatchCloseEvent(org.apache.royale.jewel.Alert.NO);
};


/**
 * @asprivate
 * @export
 * @param {number} buttonFlag
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.dispatchCloseEvent = function(buttonFlag) {
  var /** @type {org.apache.royale.events.CloseEvent} */ closeEvent = new org.apache.royale.events.CloseEvent("close", false, false, buttonFlag);
  org.apache.royale.utils.Language.as(this._strand, org.apache.royale.events.IEventDispatcher, true).dispatchEvent(closeEvent);
};


org.apache.royale.jewel.beads.views.AlertView.prototype.set__strand = function(value) {
  org.apache.royale.jewel.beads.views.AlertView.superClass_.set__strand.apply(this, [ value] );
  
  this.alertModel = org.apache.royale.utils.Language.as(org.apache.royale.utils.Language.as(this._strand, org.apache.royale.core.UIBase).model, org.apache.royale.core.IAlertModel);
  this.titleBar = new org.apache.royale.jewel.TitleBar();
  this.titleBar.addBead(new org.apache.royale.jewel.beads.views.AlertTitleBarView());
  this.titleBar.title = this.alertModel.title;
  org.apache.royale.utils.Language.as(this._strand, org.apache.royale.core.IParent, true).addElement(this.titleBar);
  this.label = new org.apache.royale.jewel.Label();
  this.label.multiline = true;
  this.label.text = this.alertModel.message;
  this.content = new org.apache.royale.jewel.VGroup();
  this.content.addClass("content");
  this.content.addElement(this.label);
  org.apache.royale.utils.Language.as(this._strand, org.apache.royale.core.IParent, true).addElement(this.content);
  this.org_apache_royale_jewel_beads_views_AlertView_createButtons();
  org.apache.royale.utils.Language.as(this._strand, org.apache.royale.core.IParent, true).addElement(this.controlBar);
  var /** @type {org.apache.royale.jewel.beads.layouts.HorizontalLayout} */ layout = org.apache.royale.utils.Language.as(this.controlBar.getBeadByType(org.apache.royale.core.IBeadLayout), org.apache.royale.jewel.beads.layouts.HorizontalLayout);
  layout.itemsHorizontalAlign = "itemsRight";
  layout.gap = 2;
  
  setTimeout(org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_views_AlertView_prepareForPopUp, this, 'prepareForPopUp'), 300);
};


Object.defineProperties(org.apache.royale.jewel.beads.views.AlertView.prototype, /** @lends {org.apache.royale.jewel.beads.views.AlertView.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.jewel.beads.views.AlertView.prototype.set__strand}}
);


/**
 * Metadata
 *
 * @type {Object.<string, Array.<Object>>}
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.ROYALE_CLASS_INFO = { names: [{ name: 'AlertView', qName: 'org.apache.royale.jewel.beads.views.AlertView', kind: 'class' }] };



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.views.AlertView.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {
      return {
        'titleBar': { type: 'org.apache.royale.jewel.TitleBar'},
        'content': { type: 'org.apache.royale.jewel.Group'},
        'label': { type: 'org.apache.royale.jewel.Label'},
        'controlBar': { type: 'org.apache.royale.core.UIBase'},
        'okButton': { type: 'org.apache.royale.jewel.Button'},
        'cancelButton': { type: 'org.apache.royale.jewel.Button'},
        'yesButton': { type: 'org.apache.royale.jewel.Button'},
        'noButton': { type: 'org.apache.royale.jewel.Button'}
      };
    },
    accessors: function () {
      return {
        'strand': { type: 'org.apache.royale.core.IStrand', access: 'writeonly', declaredBy: 'org.apache.royale.jewel.beads.views.AlertView'}
      };
    },
    methods: function () {
      return {
        'AlertView': { type: '', declaredBy: 'org.apache.royale.jewel.beads.views.AlertView'},
        'dispatchCloseEvent': { type: 'void', declaredBy: 'org.apache.royale.jewel.beads.views.AlertView', parameters: function () { return [  { index: 1, type: 'uint', optional: false } ]; }}
      };
    }
  };
};