(function(){"use strict";u8.Base.Widgets.GroupPanel=function(e,t){this.Panel(e,$.extend({},u8.Base.Widgets.GroupPanel.defaults,t));this._isCreated=false;u8.services.texts.loadText(this.title,function(){this._create(function(){if(this.collapsed&&this.allowCollapse){this.withoutEvents(this.setCollapsed,this.collapsed)}delete this.collapsed;this.commandBindings={"ValidationManager/StatusChange":this._onValidationManagerStatusChange.bind(this)}}.bind(this))}.bind(this))};u8.Base.Widgets.GroupPanel.makeClass({name:"GroupPanel",deriveFrom:u8.Base.Widgets.Panel,events:["CollapsedChange","Create"]});u8.Base.Widgets.GroupPanel.defaults={title:"GroupPanel",borderStyle:"all",allowCollapse:true,allowFocus:true,enableErrorIndicator:false,theme:{css:{fieldset:"u8-grouppanel u8-focus-container",bordersPrefix:"u8-grouppanel-borders",content:"u8-grouppanel-content",collapsed:"collapsed",focus:"focus"}}};$.extend(u8.Base.Widgets.GroupPanel.prototype,{setContent:function(e){this._$fieldset.children(":not(legend)").remove();this.$(e).addClass(this.theme.css.content);this._$fieldset.append(e);this.$(this.element).on("focus",":input, [tabIndex]",this._onSubElementFocus.ifAlive(this)).on("blur",":input, [tabIndex]",this._onSubElementBlur.ifAlive(this))},getContent:function(){return this._$fieldset.children(":not(legend)")[0]},setCollapsed:function(e){var t,s,i;this._$fieldset.toggleClass(this.theme.css.collapsed,e);if(e){i=this._$fieldset.find(":input");for(t=0;t<i.length;t++){s=this.$(i[t]);s.data("u8GroupPanel_disabled",s.is(":disabled"));s.attr("disabled","disabled")}i=this._$fieldset.find(":not(.legend)[tabIndex]");for(t=0;t<i.length;t++){s=this.$(i[t]);s.attr("u8GroupPanel_tabIndex",s.attr("tabIndex"));s.removeAttr("tabIndex")}}else{i=this._$fieldset.find(":input");for(t=0;t<i.length;t++){s=this.$(i[t]);if(!s.data("u8GroupPanel_disabled")){s.removeAttr("disabled")}s.removeData("u8GroupPanel_disabled")}i=this._$fieldset.find("[u8GroupPanel_tabIndex]");for(t=0;t<i.length;t++){s=this.$(i[t]);s.attr("tabIndex",s.attr("u8GroupPanel_tabIndex"));s.removeAttr("u8GroupPanel_tabIndex")}}u8.services.commands.execute(this,"Widget/size",{el:this.element});this.raise("CollapsedChange",{collapsed:e})},getCollapsed:function(){return this._$fieldset.hasClass(this.theme.css.collapsed)},update:function(e){var t=this.$(this.element);var s=this._$fieldset.children(":not(legend)");t.empty();this._create(function(){if(!this.items){this.setContent(s)}}.bind(this))},_create:function(e){var t=this;var s;var i=this.$(this.element).children();if(i.length>0){s=this.$("<div/>").append(i);this.$(this.element).empty()}this._$fieldset=this.$("<fieldset/>").addClass(this.theme.css.fieldset).appendTo(this.element);if(this.style){this._$fieldset.attr("data-style",this.style)}var n=this.$("<legend/>").appendTo(this._$fieldset),a=this.$("<div class='legend' />").appendTo(n);this._$fieldset.addClass(this.theme.css.bordersPrefix+"-"+this.borderStyle);if(this.allowFocus&&!this.designer){a.attr("tabindex",this.tabIndex||0).on("focus",this._onSubElementFocus.bind(this)).on("blur",this._onSubElementBlur.bind(this))}if(this.allowCollapse){var l=this._toggleCollapse.bind(this);this.$("<span/>").addClass("u8-grouppanel-collapse").appendTo(a).on("click",l);n.on("dblclick",l).on("keydown",function(e){if(e.keyCode==32){t._toggleCollapse()}})}if(this.enableErrorIndicator){this._errorIndicator=this.$("<img/>").addClass("error-indicator").image("u8-img-validator-error-s").appendTo(a).hide()}var o=this.$("<span class='text' />").appendTo(a);if(this.allowDraggable){o.attr("draggable","true")}if(u8.services.texts.isTextId(this.title)){o.text($t(this.title))}else{o.text(this.title)}if(s){this.setContent(s)}var d=this.items&&this.items[0];if(d){var r=this._createItemElement(d);this.setContent(r);this._createItemContent(r,d)}u8.tools.createdWhenReady(this,e)},_toggleCollapse:function(e){if(this.designer){return}this.setCollapsed(!this.getCollapsed())},_onSubElementFocus:function(){this._$fieldset.addClass(this.theme.css.focus)},_onSubElementBlur:function(){this._$fieldset.removeClass(this.theme.css.focus)},_onValidationManagerStatusChange:function(e,t,s){if(!this.enableErrorIndicator){return}if(s.status=="error"){this._errorIndicator.show()}else{this._errorIndicator.hide()}},"Designer.removeItem":function(e){if(e.arrayName=="items"&&e.arrayIndex==0){return this._$fieldset.children(":not(legend)")}},"Designer.insertItem":function(e){if(e.arrayName=="items"&&(typeof e.arrayIndex=="undefined"||e.arrayIndex==0)){this.setContent(e.element)}}});$.extend(u8.Base.Widgets.GroupPanel,{"Designer.prepareModelForDesignMode":function(e){var t=e.model.options;var s=t&&t.items;if(s&&!s.length){s.push({})}}})})();