YUI.add("aui-form-builder-field-multiple-choice",function(e,t){var n=e.Lang,r=n.isArray,i=e.Array,s=e.Escape,o="acceptChildren",u="editor",a="field",f="form-builder",l="form-builder-multiple-choice-field",c="form-builder-options-editor",h="hidden",p="label",t="name",d="optionTemplate",v="options",m="predefinedValue",g="render",y="selected",b="showLabel",w="templateNode",E=",",S="",x=" ",T=e.getClassName,N=function(e){var t={};return i.each(e,function(e,n,r){t[e.value]=e.label}),t},C=T(f,a),k=T(f,v,u,h),L=e.Component.create({NAME:c,ATTRS:{editable:{setter:function(){return!1}}},EXTENDS:e.RadioCellEditor,prototype:{ELEMENT_TEMPLATE:'<div class="'+k+'"></div>',initializer:function(){var e=this;e.set("hideEditContainerOnSave",!1),e.after(g,function(){e._onEditEvent()})},_handleSaveEvent:function(e){var t=this;t.saveOptions(),L.superclass._handleSaveEvent.apply(this,arguments)}}}),A=e.Component.create({NAME:l,ATTRS:{acceptChildren:{value:!1,readOnly:!0},options:{value:[{label:"option 1",value:"value 1"},{label:"option 2",value:"value 2"},{label:"option 3",value:"value 3"}]},optionTemplate:{value:'<option value="{value}">{label}</option>'},predefinedValue:{setter:function(e){return r(e)?e:[e]}}},UI_ATTRS:[o,p,t,v,m,b],CSS_PREFIX:C,EXTENDS:e.FormBuilderField,prototype:{initializer:function(){var t=this,n=t.get(v);t.predefinedValueEditor=new e.DropDownCellEditor({options:t._getPredefinedValuesOptions(n)})},getPropertyModel:function(){var t=this,n=t.get(v),s=t.getStrings(),o=e.FormBuilderMultipleChoiceField.superclass.getPropertyModel.apply(t,arguments);return i.each(o,function(n,i,s){n.attributeName===m&&(s[i]=e.merge(n,{editor:t.predefinedValueEditor,formatter:function(n){var i=t.predefinedValueEditor.get(v),s=n.data.value;r(s)||(s=[s]);var o=e.Array.map(s,function(e){return i[e]});return o.join(E+x)}}))}),o.push({attributeName:v,editor:new L({editable:!0,on:{optionsChange:function(e){var n=t._normalizeValues(e.newVal);n=t._getPredefinedValuesOptions(n),t.predefinedValueEditor.set(v,n)}},options:N(n),inputFormatter:function(){var t=[];return e.each(this.get(v),function(r,s,o){var u={label:r,value:s};i.each(n,function(t){t.value===s&&(u=e.merge(t,u))}),t.push(u)}),t}}),formatter:function(t){var n=[];return e.each(t.data.value,function(e,t,r){n.push(e.label)}),n.join(E+x)},name:s[v]}),o},_getPredefinedValuesOptions:function(e){var t={label:S,value:S};return N([t].concat(e))},_normalizeValues:function(t){return e.map(t,function(e,t){return{label:e,value:t}})},_uiSetOptions:function(t){var r=this,i=[];e.each(t,function(e,t,o){i.push(n.sub(r.get(d),{label:s.html(e.label),value:s.html(e.value)}))}),r.optionNodes=e.NodeList.create(i.join(S)),r.get(w).setContent(r.optionNodes),r._uiSetPredefinedValue(r.get(m))},_uiSetPredefinedValue:function(e){var t=this,n=t.optionNodes;if(!n)return;n.set(y,!1),i.each(e,function(e){n.filter('[value="'+s.html(e)+'"]').set(y,!0)})}}});e.FormBuilderMultipleChoiceField=A,e.FormBuilder.types["multiple-choice"]=e.FormBuilderMultipleChoiceField},"2.0.0",{requires:["aui-form-builder-field-base"]});
