/**
 * 功能：Form组件,用于生成HTML表单
 */
package("com.henry.ui");

com.henry.ui.Form = function(id, action) {
	var self = new com.henry.ui.HTML("FORM", id);
	var formInstance = this.constructor.extendInstance(self);
	var $super = formInstance.$super;

	var _fields = {};
	var _keyedTable = null;
		
	{
		formInstance.getAction = function() {
			return self.getAttribute("action");
		}
		formInstance.setAction = function(theAction) {
			self.setAttribute("action", theAction);
		}
		
		formInstance.getMode = function() {
			return self.getAttribute("mode");
		}
		formInstance.setMode = function(theMode) {
			self.setAttribute("mode", theMode);
		}
		
		formInstance.getTarget = function() {
			self.getAttribute("target");
		}
		formInstance.setTarget = function(theTarget) {
			self.setAttribute("target", theTarget);
		}

		formInstance.addFields = function(fields) {
			_keyedTable.addFields(fields);
			return this;
		}
		
		formInstance.addField = function(theField, colspan, rowspan, endDesc) {
			var layoutConstraint = {colspan:1, rowspan:1};
			if (colspan) {
				layoutConstraint.colspan = colspan;
			}
			
			if (rowspan) {
				layoutConstraint.rowspan = rowspan;
			}
			
			if (endDesc) {
				layoutConstraint.endDesc = endDesc;
			}
			
			_keyedTable.addField(theField, layoutConstraint);
			return this;		
		} 
		
		formInstance.addComponent = function(name, theComp, layoutConstraint) {
			_keyedTable.addComponent(name, theComp, layoutConstraint);
			
			return this;
		}
		
		formInstance.endLine = function() {
			_keyedTable.endLine();
		}

		formInstance.endCell = function() {
			_keyedTable.endCell();
		}
		formInstance.openCell = function() {
			_keyedTable.openCell();
		}
		formInstance.noCell = function() {
			_keyedTable.noCell();
		}
	}

	(function() {
		self.setAction(action);
			
		self.setAttribute("method", "post");
		self.setAttribute("mode", "1");
		self.setStyle("margin", "0 0 0 0");
			
		_keyedTable = new com.henry.ui.KeyedTable()

		_keyedTable.setAttribute("cellPadding", "1");
		_keyedTable.setAttribute("cellSpacing", "2");
		_keyedTable.setAttribute("class", "Input");
			
		self.addChild("keyedTable", _keyedTable);
	})();
		

	return formInstance;
}


