function cast(n,t){return n.__proto__=t.prototype,n}var __extends=this&&this.__extends||function(){var n=function(t,i){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,t){n.__proto__=t}||function(n,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i])},n(t,i)};return function(t,i){function r(){this.constructor=t}if(typeof i!="function"&&i!==null)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");n(t,i);t.prototype=i===null?Object.create(i):(r.prototype=i.prototype,new r)}}(),Dmp;(function(n){var t;(function(n){var t;(function(n){var t=function(){function n(){}return n.NOT_SORTED=0,n.ASC=1,n.DESC=2,n}(),i,b,k,h,c,u,r,f,l,a,v,y,p,w,e,o,d,s;n.SortDirection=t;i=function(){function n(){}return n.STRING=1,n.NUMBER=2,n.RANGE=3,n.CHOICE=4,n.BOOL=5,n.DATERANGE=6,n}();n.FilterType=i;b=function(){function n(){}return n.SINGLECHOICE=1,n.MULTIPLECHOICE=2,n}();n.ChoiceFilterMode=b;k=function(){function n(n){var i=this,t;this.IsUpdating=!1;t=this;this.OnPagerUpdated=function(){i.TriggerUpdate()};this.OnPagerAppended=function(){i.TriggerAppend()};this.OnFilterChanged=function(){i.UsePager&&i.Pager.Page(1);i.TriggerUpdate()};this.OnSorted=function(n){i.Pager.Page(1);_.each(i.Sortables,function(t){t!=n&&t.Reset()},i);i.TriggerUpdate()};this.OnLoad=function(n,t,i){if(i?($("#product-list .productListData").remove(),$("#product-list .pagination-wrapper").remove(),$("#product-list").append(n)):$("#product-list").html(n),t.UsePager){var r=$("#product-list .productListData").data("totalitems"),u=cast(r,Number);t.Pager.TotalItems(u);t.Pager.Page(n.page);t.Pager.Update();t.UseAutoPaging&&$("#product-list-scroll").removeClass("hide")}};this.IsInEndOfPage=function(){var n=$("#product-list-scroll");if(n.length==1){var t=$(window).scrollTop(),r=t+$(window).height(),i=$(n).offset().top-150,u=i+$(n).height();return u<=r&&i>=t}return!1};this.CanUseAutoPaging=function(){return!0};this.UseAutoPaging=n.UseAutoPaging;this.SetUpPager=function(){t.Pager.TotalItems(n.TotalItems);$("#product-list").on("click",".pagination a",function(n){t.ShowLoading();var i=$(this).data("pageid");return t.Pager.GoToPage(i),t.HideLoading(),n.preventDefault(),!1});if(t.UseAutoPaging){$("#product-list-scroll").removeClass("hide");$(window).on("scroll",function(){function r(){t.IsInEndOfPage()&&t.CanUseAutoPaging()&&t.Pager.AppendNextPage()}var n=150,i=(new Date).getTime();t.Pager.ScrollTimer||(i-t.Pager.LastScrollFireTime>3*n&&(r(),t.Pager.LastScrollFireTime=i),t.Pager.ScrollTimer=setTimeout(function(){t.Pager.ScrollTimer=null;t.Pager.LastScrollFireTime=(new Date).getTime();r()},n))})}};this.UrlHandler=new d;this.UrlHandler.InstructionsChanged=function(n){i.ApplyGridInstructions(n)};this.Sortables=_.map(n.Sortables,function(n){var t=new c(n);return t.Sorted=i.OnSorted,t},this);this.Filters=_.map(n.Filters,function(n){var t=u.Create(n);return t.FilterChanged=i.OnFilterChanged,t},this);this.UsePager=n.UsePaging;this.UsePager&&(this.DefaultPageSize=n.DefaultPageSize,this.Pager=new h(this.DefaultPageSize),this.Pager.Page(n.CurrentPage),this.Pager.Updated=this.OnPagerUpdated,this.Pager.Appended=this.OnPagerAppended,this.SetUpPager());this.DataUrl=n.DataUrl;this.Data=ko.observableArray();location.hash&&this.ApplyGridInstructions(this.UrlHandler.Parse(location.hash));this.Sortables.sort()}return n.prototype.GetCurrentGridInstructions=function(){var n=new s;return n.FilterInstructions=this.GetCurrentFilterInstructions(),n.SortingInstructions=this.GetCurrentSortingInstructions(),n.PagingInstructions=this.UsePager?this.Pager.GetCurrentPagingInstructions():undefined,n},n.prototype.GetCurrentFilterInstructions=function(){var n=_.map(this.Filters,function(n){return n.GetFilterInstruction()},this);return _.reject(n,function(n){return n==undefined},this)},n.prototype.GetCurrentSortingInstructions=function(){var i=_.find(this.Sortables,function(n){return n.Direction()!=t.NOT_SORTED},this),n;if(i)return n=new f,n.By=i.Name,n.Direction=i.Direction(),n},n.prototype.ApplyGridInstructions=function(n){var t=this;this.IsUpdating||(this.IsUpdating=!0,_.each(this.Filters,function(i){var r=_.find(n.FilterInstructions,function(n){return i.Name.toLowerCase()==n.Name.toLowerCase()},t);r?i.ApplyInstruction(r):i.Reset()},this),_.each(this.Sortables,function(t){n.SortingInstructions.By&&n.SortingInstructions.By.toLowerCase()==t.Name.toLowerCase()?t.ApplyInstructions(n.SortingInstructions):t.Reset()},this),this.UsePager&&this.Pager.ApplyInstructions(n.PagingInstructions),this.Update(),this.IsUpdating=!1)},n.prototype.Load=function(n,t,i){var r=this;r.ShowLoading();$.ajax({url:n,type:"POST",data:JSON.stringify(t.GetCurrentGridInstructions()),contentType:"application/json; charset=utf-8",success:function(n){r.OnLoad&&r.OnLoad(n,t,i);r.HideLoading();r.UrlHandler.SupressInstructionsChanged=!1},error:function(){r.UrlHandler.SupressInstructionsChanged=!1}})},n.prototype.TriggerUpdate=function(){var n=this;this.IsUpdating||(this.UpdateTimer&&window.clearTimeout(this.UpdateTimer),this.UpdateTimer=window.setTimeout(function(){n.Update();n.UpdateTimer=undefined},1e3))},n.prototype.TriggerAppend=function(){var n=this;this.IsUpdating||(this.UpdateTimer&&window.clearTimeout(this.UpdateTimer),this.UpdateTimer=window.setTimeout(function(){n.Append();n.UpdateTimer=undefined},250))},n.prototype.Update=function(n){n||(n=this.GetCurrentGridInstructions());this.UrlHandler.SupressInstructionsChanged||(this.UrlHandler.SupressInstructionsChanged=!0,this.UrlHandler.Update(n),this.Load(this.DataUrl,this,!1))},n.prototype.Append=function(n){n||(n=this.GetCurrentGridInstructions());this.UrlHandler.SupressInstructionsChanged||(this.UrlHandler.SupressInstructionsChanged=!0,this.UrlHandler.Update(n),this.Load(this.DataUrl,this,!0))},n.prototype.ShowLoading=function(){$("#product-loading-spinner").removeClass("hide")},n.prototype.HideLoading=function(){$("#product-loading-spinner").addClass("hide")},n}();n.ProductGrid=k;h=function(){function n(n){var t=this;this.SupressUpdatedEvent=!1;this.DefaultPageSize=n;this.Page=ko.observable(1);this.PageSize=ko.observable(this.DefaultPageSize);this.TotalItems=ko.observable(0);this.PagesList=ko.observableArray([]);this.ScrollTimer=this.LastScrollFireTime=0;this.TotalPages=ko.computed(function(){return Math.ceil(t.TotalItems()/t.PageSize())});this.HasPreviousPage=ko.computed(function(){return t.Page()>1});this.HasNextPage=ko.computed(function(){return t.Page()<t.TotalPages()});this.GoToPage=function(n){var i=n;n<1?i=1:t.TotalPages()>0&&n>t.TotalPages()&&(i=t.TotalPages());t.Page()!=i&&(t.Page(i),t.RaiseUpdated())};this.AppendNextPage=function(){$("#product-list-scroll").addClass("hide");t.HasNextPage()&&(t.Page(t.Page()+1),t.RaiseAppended())}}return n.prototype.ApplyInstructions=function(n){this.SupressUpdatedEvent=!0;n.PageSize?this.PageSize(n.PageSize):this.PageSize(this.DefaultPageSize);n.Page?this.GoToPage(n.Page):this.GoToPage(1);this.SupressUpdatedEvent=!1},n.prototype.GoToFirst=function(){this.GoToPage(1)},n.prototype.GoToLast=function(){this.GoToPage(this.TotalPages())},n.prototype.GetCurrentPagingInstructions=function(){return{Page:this.Page(),PageSize:this.PageSize()}},n.prototype.Update=function(){this.GoToPage(this.Page())},n.prototype.RaiseUpdated=function(){!this.SupressUpdatedEvent&&this.Updated&&this.Updated()},n.prototype.RaiseAppended=function(){!this.SupressUpdatedEvent&&this.Updated&&this.Appended()},n}();n.Pager=h;c=function(){function n(n){var i=this;this.SupressSortedEvent=!1;this.Name=n.Name;this.Label=n.Label;this.Direction=ko.observable(t.NOT_SORTED);this.Direction.subscribe(function(){i.RaiseSorted()})}return n.prototype.Sort=function(){switch(this.Direction()){case t.NOT_SORTED:this.Direction(t.ASC);break;case t.ASC:this.Direction(t.DESC);break;case t.DESC:this.Direction(t.NOT_SORTED)}},n.prototype.Reset=function(){this.Direction()!=t.NOT_SORTED&&(this.SupressSortedEvent=!0,this.Direction(t.NOT_SORTED),this.SupressSortedEvent=!1)},n.prototype.ApplyInstructions=function(n){this.Direction()!=n.Direction&&(this.SupressSortedEvent=!0,this.Direction(n.Direction),this.SupressSortedEvent=!1)},n.prototype.RaiseSorted=function(){!this.SupressSortedEvent&&this.Sorted&&this.Sorted(this)},n}();n.Sortable=c;u=function(){function n(n){this.Name=n.Name;this.Label=n.Label;this.Format=n.Format}return n.Create=function(n){switch(n.FilterType){case i.RANGE:return new v(n);case i.CHOICE:return new p(n);case i.STRING:return new a(n);case i.DATERANGE:return new y(n)}},n.prototype.GetFilterInstruction=function(){var n=new r(this.Name,[this.Value]);return n.FilterType=this.FilterType,n},n.prototype.ApplyInstruction=function(n){this.Value!=n.Value[0]&&(this.Value=n.Value[0])},n.prototype.Reset=function(){},n.prototype.RaiseFilterChanged=function(){this.FilterChanged&&this.FilterChanged(this)},n}();n.Filter=u;r=function(){function n(n,t){this.Name=n;this.Value=t}return n}();n.FilterInstruction=r;f=function(){function n(){}return n}();n.SortingInstructions=f;l=function(){function n(){}return n}();n.PagingInstructions=l;a=function(n){function t(t){var r=n.call(this,t)||this;return r.FilterType=i.STRING,r.Value=ko.observable(""),r.Value.subscribe(function(){r.RaiseFilterChanged()}),r}return __extends(t,n),t.prototype.GetFilterInstruction=function(){var n=new r(this.Name,[this.Value()]);return n.FilterType=this.FilterType,n},t.prototype.ApplyInstruction=function(n){this.Value()!=n.Value[0]&&this.Value(n.Value[0])},t.prototype.Reset=function(){this.Value("")},t}(u);n.StringFilter=a;v=function(n){function t(t){var r=n.call(this,t)||this;return r.FilterType=i.RANGE,r.Limits=new o(t.Limits),r.Value=new o(t.Limits),r.Value.Minimum.subscribe(function(){r.RaiseFilterChanged()}),r.Value.Maximum.subscribe(function(){r.RaiseFilterChanged()}),r}return __extends(t,n),t.prototype.GetFilterInstruction=function(){if(this.Value.Minimum()!=this.Limits.Minimum()||this.Value.Maximum()!=this.Limits.Maximum()){var n=new r(this.Name,[this.Value.Minimum(),this.Value.Maximum()]);return n.FilterType=this.FilterType,n}},t.prototype.ApplyInstruction=function(n){this.Value.Minimum()!=n.Value[0]&&this.Value.Minimum(n.Value[0]);this.Value.Maximum()!=n.Value[1]&&this.Value.Maximum(n.Value[1])},t.prototype.Reset=function(){this.Value.Minimum(this.Limits.Minimum());this.Value.Maximum(this.Limits.Maximum())},t}(u);n.RangeFilter=v;y=function(n){function t(t){var r=n.call(this,t)||this;return r.FilterType=i.DATERANGE,r.Limits=new e(t.Limits),r.Value=new e(t.Limits),r.Value.Minimum.subscribe(function(){r.RaiseFilterChanged()}),r.Value.Maximum.subscribe(function(){r.RaiseFilterChanged()}),r}return __extends(t,n),t.prototype.GetFilterInstruction=function(){if(this.Value.Minimum()!=this.Limits.Minimum()||this.Value.Maximum()!=this.Limits.Maximum()){var n=new r(this.Name,[this.Value.Minimum(),this.Value.Maximum()]);return n.FilterType=this.FilterType,n}},t.prototype.ApplyInstruction=function(n){this.Value.Minimum()!=n.Value[0]&&this.Value.Minimum(n.Value[0]);this.Value.Maximum()!=n.Value[1]&&this.Value.Maximum(n.Value[1])},t.prototype.Reset=function(){this.Value.Minimum(this.Limits.Minimum());this.Value.Maximum(this.Limits.Maximum())},t}(u);n.DateRangeFilter=y;p=function(n){function t(t){var r=n.call(this,t)||this;return r.FilterType=i.CHOICE,r.Options=[],_.each(t.Options,function(n){var t=new w(n);t.IsSelected.subscribe(function(){r.RaiseFilterChanged()});r.Options.push(t)},r),r}return __extends(t,n),t.prototype.GetFilterInstruction=function(){var t=_.reject(this.Options,function(n){return n.IsSelected()==!1}),n;if(t.length>0)return n=new r(this.Name,_.pluck(t,"Value")),n.FilterType=this.FilterType,n},t.prototype.ApplyInstruction=function(n){_.each(this.Options,function(t){var i=_.find(n.Value,function(n){return t.Value==n});i?t.IsSelected(!0):t.IsSelected(!1)})},t.prototype.Reset=function(){_.each(this.Options,function(n){n.IsSelected(!1)})},t}(u);n.ChoiceFilter=p;w=function(){function n(n){this.Name=n.Name;this.Label=n.Label;this.Count=n.Count;this.Value=n.Value;this.IsSelected=ko.observable(!1)}return n}();n.Option=w;e=function(){function n(n){this.Minimum=ko.observable(n.Minimum);this.Maximum=ko.observable(n.Maximum)}return n}();n.DateRange=e;o=function(){function n(n){this.Minimum=ko.observable(n.Minimum);this.Maximum=ko.observable(n.Maximum)}return n}();n.Range=o;d=function(){function n(){var n=this;this.SupressInstructionsChanged=!1;window.onhashchange=function(){var t=n.Parse(window.location.hash);!n.SupressInstructionsChanged&&n.InstructionsChanged&&n.InstructionsChanged(t);n.SupressInstructionsChanged=!1}}return n.prototype.Parse=function(n){var t=new s,i;return n=="./"?t:(i=n.toLowerCase().substr(1).split("&"),_.each(i,function(n){var f=n.toLowerCase().split("="),i,u;if(f.length==2)if(i=f[0],u=f[1].split(","),i.substr(0,2)=="f.")t.FilterInstructions.push(new r(i.substr(2),u));else if(i.substr(0,5)=="sort.")switch(i.substr(5)){case"by":t.SortingInstructions.By=u[0];break;case"direction":t.SortingInstructions.Direction=+u[0]}else if(i.substr(0,2)=="p.")switch(i.substr(2)){case"page":t.PagingInstructions.Page=+u[0];break;case"pagesize":t.PagingInstructions.PageSize=+u[0]}},this),t)},n.prototype.Update=function(n){var i=this,t=[];n.SortingInstructions&&(t.push(this.FormatInstruction("sort","by",[n.SortingInstructions.By])),t.push(this.FormatInstruction("sort","direction",[n.SortingInstructions.Direction])));_.each(n.FilterInstructions,function(n){t.push(i.FormatInstruction("f",n.Name,n.Value))},this);n.PagingInstructions&&(t.push(this.FormatInstruction("p","page",[n.PagingInstructions.Page])),t.push(this.FormatInstruction("p","pageSize",[n.PagingInstructions.PageSize])));window.location.hash=t.join("&")},n.prototype.FormatInstruction=function(n,t,i){return n+"."+t+"="+i.join()+""},n}();s=function(){function n(){this.FilterInstructions=[];this.SortingInstructions=new f;this.PagingInstructions=new l}return n}();n.GridInstructions=s})(t=n.Eshop||(n.Eshop={}))})(t=n.Platform||(n.Platform={}))})(Dmp||(Dmp={}))