(function(){var e=['<div class="u8-padding u8-vstack spaced" style="width: 600px;">','{{RadioButton({ bindings:"@handlerType<==>@groupValue", value:"Action", groupName:"handlerType", label: "Execute an action" })}}','{{RadioButton({ bindings:"@handlerType<==>@groupValue", value:"Function", groupName:"handlerType", label: "Execute a javascript function" })}}','<div data-handlertype="Action" class="u8-margin-top">{{TextInput({ bindings:"@action" })}}</div>','<div data-handlertype="Function" class="u8-margin-top">{{CodeEditor({ bindings:"@function", maxHeight: 500, editor: { mode: "javascript", lineNumbers: true, identAuto: true }, validator:"js-functionbody" })}}</div>','<div class="u8-margin-top-l" style="text-align:right;">','{{Button({ text: "Ok", command: "Apply" })}} {{Button({ text: "Cancel", command: "Cancel" })}}',"</div>","</div>"].join("");u8.Base.Widgets.FormDesignerEventEditor=function(e,t){this.Widget(e,$.extend({},u8.Base.Widgets.FormDesignerEventEditor.defaults,t));this.commandBindings={Apply:this._onCommand.bind(this),Cancel:this._onCommand.bind(this)};this._handlersByType={};if(this.value){this.withoutEvents(function(){this.setValue(this.value)})}this._create()};u8.Base.Widgets.FormDesignerEventEditor.makeClass({name:"FormDesignerEventEditor",deriveFrom:u8.Base.Widgets.Widget,events:["ValueChange","Apply","Cancel","FunctionChange","ActionChange","HandlerTypeChange"]});u8.Base.Widgets.FormDesignerEventEditor.defaults={};$.extend(u8.Base.Widgets.FormDesignerEventEditor.prototype,{setValue:function(e){this.value=e;var t=e&&e.handlerType||"Action";this._handlersByType[t]=e&&e.handler||"";this._updateHandlerType();this.raise("ValueChange",{value:e});this.raise("FunctionChange");this.raise("ActionChange");this.raise("HandlerTypeChange")},getValue:function(){return this.value},setFunction:function(e){this.setValue({handler:e,handlerType:"Function"})},getFunction:function(){return this._handlersByType["Function"]},setAction:function(e){this.setValue({handler:e,handlerType:"Action"})},getAction:function(){return this._handlersByType["Action"]},getHandlerType:function(){return this.value&&this.value.handlerType||"Action"},setHandlerType:function(e){var t=this.getValue();if(t&&t.handlerType==e){return}var n=this._handlersByType[e]||"";this.setValue({handler:n,handlerType:e})},_create:function(){this.context=this;var t=this;this.$(this.element).utml({template:e,data:this,itemOptions:{parent:this}},function(){u8.tools.ready(t.children,t._updateHandlerType.bind(t))})},_updateHandlerType:function(){var e=this.getHandlerType();this.$(this.element).find("[data-handlertype]").each(function(){this.style.display=this.getAttribute("data-handlertype")==e?"":"none"})},_onCommand:function(e,t,n){this.raise(t)}});$.extend(u8.Base.Widgets.FormDesignerEventEditor,{showAsPopup:function(e){var t;var n=u8.create("Popup","<div></div>",$.extend({sizing:"fit",title:"Event Editor",autoShow:false,position:"center-top",showArrow:true,onCreate:function(n){t=n.getContent().widget("FormDesignerEventEditor",$.extend(e,{parent:n,popup:null}))[0];t.bind("Apply",function(){n.close()}).bind("Cancel",function(){n.close({cancel:true})});n.autoSizeAndPosition();n.show()}},e.popup));n.open();return n}})})();