package com.dd.bootstrap.dynamicelements;

import com.dd.bootstrap.components.BSDynamicElement;
import com.webobjects.appserver.WOAssociation;
import com.webobjects.appserver.WOContext;
import com.webobjects.appserver.WOElement;
import com.webobjects.appserver.WOResponse;
import com.webobjects.appserver._private.WOPopUpButton;
import com.webobjects.foundation.NSDictionary;

public class BSEditorRowPopUpButton extends WOPopUpButton {

	private WOAssociation _label;
	private WOAssociation _required;
	
	public BSEditorRowPopUpButton(String aName, NSDictionary<String, WOAssociation> someAssociations, WOElement template) {
		super(aName, someAssociations, template);
		
		BSDynamicElementsHelper.AppendCSS(_associations, this);
		
		_label = _associations.removeObjectForKey("label");
		_required = _associations.removeObjectForKey("required");
	}

	@Override
	public void appendToResponse(WOResponse response, WOContext context) {
		BSDynamicElement.InjectCSSAndJS(response, context);
		
		response.appendContentString("<div class=\"form-group\"><label class=\"col-sm-2 control-label\">");
		if (_label != null && _label.valueInComponent(context.component()) != null) {
			response.appendContentHTMLString((String) _label.valueInComponent(context.component()));
			if (_required != null && (Boolean) _required.valueInComponent(context.component())) {
				response.appendContentString("*");
			}
		}
		response.appendContentString("</label><div class=\"col-sm-10\">");
		super.appendToResponse(response, context);
		response.appendContentString("</div></div>");
	}
	
	
}

@@ -982,19 +982,113 @@
 ntext);%0A
+%09%09boolean hasChildElements = (childrenElements() != null && childrenElements().count() != 0);%0A
 %09%09%0A
-
 %09%09respon
@@ -1490,16 +1490,19 @@
 %09%09%7D%0A%09%09%7D%0A
+%09%09%0A
 %09%09respon
@@ -1568,50 +1568,646 @@
 ;%0A%09%09
-super.appendToResponse(response, context);
+%0A%09%09if (hasChildElements) %7B%0A%09%09%09response.appendContentString(%22%3Cdiv class=%5C%22input-group%5C%22%3E%22);%0A%09%09%7D%0A%09%09%0A%09%09super.appendToResponse(response, context);%0A%09%09%0A%09%09// component content, i guess%0A%09%09if (hasChildElements) %7B%0A%09%09%09response.appendContentString(%22%3Cspan class=%5C%22input-group-addon%5C%22%3E%22);%0A%09%09%09context.appendZeroElementIDComponent();%0A%09%09%09for (WOElement element : childrenElements()) %7B%0A%09%09%09%09element.appendToResponse(response, context);%0A%09%09%09%09context.incrementLastElementIDComponent();%0A%09%09%09%7D%0A%09%09%09context.deleteLastElementIDComponent();%0A%09%09%09response.appendContentString(%22%3C/span%3E%22);%0A%09%09%7D%0A%09%09%0A%09%09if (hasChildElements) %7B%0A%09%09%09response.appendContentString(%22%3C/div%3E%22);%0A%09%09%7D%0A%09%09
 %0A%09%09r

Support for additional component content in PopUpButton