/*
 * hyCMS
 * Copyright(C)2008 by Friedrich Gräter
 * Published under the terms of the Lesser GNU General Public License v2
 *
 * Dialog widgets
 *
 */

/*
 * wk_createDialog(id, buttons, innerView, topAnchor, leftAnchor, topOrientation, leftOrientation, relatedDocument)
 *
 *
 * Creates a frame that shows the given view and a button list. The parameter buttonList contains
 * a list of button widgets, shown at the bottom of the dialog.
 *
 * The other parameters, methods and events are describes in wk_createFrame.
 *
 * The control will have the following additional methods:
 *
 *		enableButton	Enables a button
 *		disableButton	Disables a button
 *		getButton		Returns a button
 *
 */
function wk_createDialog(id, buttons, innerView, topAnchor, leftAnchor, topOrientation, leftOrientation, relatedDocument)
{
	if (relatedDocument == null)
		relatedDocument = document;

	var hbox = wk_createOrientedBox(id+"_hbox", "horizontal", -1, 10, relatedDocument);
	var buttonList = wk_createOrientedBox(id+"_buttonList", "vertical", -1, 10, relatedDocument);
	var buttonViews = [];

	hbox.add(innerView, -1, -1);
	hbox.add(buttonList, -1, -1);

	var view = wk_createFrame(id, hbox, topAnchor, leftAnchor, topOrientation, leftOrientation, relatedDocument);
	
	// Creating view
	view.wk_type = "dialog";
		
	view.id = id;
	view.className = "wk_frame";

	// Fill button list
	for (var idx = 0; idx < buttons.length; idx ++) {
		var button = buttons[idx];

		buttonViews.push(button);
		buttonList.add(button, -1, -1);	
	}
	
	buttonList.style.margin = "auto";
	buttonList.parentNode.style.textAlign = "center";
	
	// Methods
	view.enableButton = function(id)
	{
		buttonViews[idx].enable();
	}

	view.disableButton = function(id)
	{
		buttonViews[idx].disable();
	}
	
	view.getButton = function(id)
	{
		return buttonViews[idx];
	}

	return view;
}


