(function(){"use strict";u8.Crm.Widgets.HierarchicalSerialEntry=function(e,i){this.Widget(e,$.extend({},u8.Crm.Widgets.HierarchicalSerialEntry.defaults,i));this._isCreated=false;this.commandBindings={"HierarchyTree/ClearSelection":this._onHierarchyTreeClearSelection.bind(this)};this._create()};u8.Crm.Widgets.HierarchicalSerialEntry.makeClass({name:"HierarchicalSerialEntry",events:["Create"],deriveFrom:u8.Base.Widgets.Widget});u8.Crm.Widgets.HierarchicalSerialEntry.defaults={theme:{css:{root:"u8-hierarchicalserialentry",header:"u8-hierarchicalserialentry-header",hierarchy:"u8-hierarchicalserialentry-hierarchy",serialEntry:"u8-hierarchicalserialentry-serialentry"}}};$.extend(u8.Crm.Widgets.HierarchicalSerialEntry.prototype,{dispose:function(){if(this._isDisposed){return}this.Widget_dispose()},_create:function(){var e=this.$(this.element).addClass(this.theme.css.root).css("visibility","hidden");Function.chain(this._using,this._createViewModel.async(),this._createView,u8.tools.ready.curry(this.children),this._updateLayout.async(),u8.tools.createdWhenReady.curry(this),e.css.bind(e,"visibility","inherit").async()).call(this)},_using:function(e){u8.using({texts:["SerialEntry_text"],templates:[{name:"u8-hierarchical-serial-entry",url:"~/crm/HierarchicalSerialEntry.utml.htm"}]},e)},_createViewModel:function(){this._viewModel={id:this.id,css:this.theme.css,hierarchyTreeViewOptions:u8.tools.extend("deep,event",{},this.hierarchyTreeViewOptions,{id:this.id+"_hierarchy",onValueChange:this._onHierarchyValueChange.bind(this)}),serialEntryOptions:u8.tools.extend("deep,event",{},this.serialEntryOptions,{id:this.id+"_serialEntry",headerSelector:"#"+this.id+"_header",model:{onPropertyChange:this._onSerialEntryModelPropertyChange.bind(this)}}),clearTreeButtonOptions:{textId:"TXT_SerialEntry_text_25",command:"HierarchyTree/ClearSelection",isDefault:true}}},_createView:function(e){this.$(this.element).data("layout",{name:"dock",settingsName:"HierarchicalSerialEntry/SidebarLayout",splitters:{left:true}}).utml({name:"u8-hierarchical-serial-entry",itemOptions:{parent:this},data:this._viewModel},e)},_updateLayout:function(){u8.Base.Dom.updateLayout(this.element)},_onHierarchyValueChange:function(e,i){var t=this.children.get(this.id+"_serialEntry");var r=t&&t.model;if(!r){return}var a=e.getValue();var n=r.get("filterType");if(!a){r.set("sourceLink",null);if(n=="None"){r.execute()}}else{r.set("sourceLink",$.extend({linkId:this._hierarchyIndexToLinkId(this.hierarchyTreeViewOptions.hierarchyIndex)},a));if(n=="None"){r.execute()}else{r.set("filterType","None")}}},_onSerialEntryModelPropertyChange:function(e,i){if(i.propertyName!="filterType"){return}if(i.value!="None"){this.getWidget("hierarchy").setValue(null)}},_onHierarchyTreeClearSelection:function(){this.getWidget("hierarchy").setValue(null)},_hierarchyIndexToLinkId:function(e){return 34e3+(e||0)*1e4}})})();