function hubConnected(){$("#executeSearchBtn").removeAttr("disabled")}function onUpdateSearchStatus(n){refreshTreeAsync(n.TreeData);updateGridAsync(n.GridData);refreshProgressBarAsync(n.TreeData);refreshAllArchivesFilter(n.AllCountText);n.SearchComplete&&onSearchCompleted(n.TreeData,n.AllCountText)}function onPublishAlternativePlaceNames(n){$("#alternatePlaceNameList").html(n.Places.join(", "));$("#alternatePlaceNameListWrapper").show()}function updateGridAsync(n){setTimeout(function(){var i=$("#searchResultGrid").data("kendoGrid"),t=i.dataSource.data().toJSON(),r;t.push.apply(t,n);r=new kendo.data.DataSource({data:t,pageSize:10,sort:{field:"Timestamp"}});i.setDataSource(r);currentFilterString.length>0&&applyFilter(currentFilterString);t.length>0&&($("#resultWaitingMessagePanel:visible").hide(),$("#resultGridPanel:hidden").show())},0)}function refreshAllArchivesFilter(n){setTimeout(function(){$("#archivesFilterAll").html(n)},0)}function refreshTreeAsync(n){setTimeout(function(){var t=$("#StatusResultTree").data("kendoTreeView"),i=new kendo.data.HierarchicalDataSource({data:n,schema:{model:{id:"Id",text:"Text",children:"Items",fields:{hasChildren:"HasChildren",expanded:"Expanded"}}}});t.setDataSource(i)},0)}function refreshProgressBarAsync(n){setTimeout(function(){var t=getFinishedArchiveItemCount(n),r=getTotalArchiveItemCount(n),i=$("#loadingProgressBar").data("kendoProgressBar");i?t>i.value()&&i.value(t):createProgressBar(0,r,t)},0)}function destroyProgressBarAsync(){setTimeout(function(){var n=$("#loadingProgressBar");n&&(n.data("kendoProgressBar")!=null&&n.data("kendoProgressBar").destroy(),n.html(""),n.removeClass(),n.removeAttr("data-role"))},50)}function getFinishedArchiveItemCount(n){var t=0;return n.forEach(function(n){n.Items.forEach(function(n){n.Text.indexOf("ajax-loader.gif")<0&&t++})}),t}function getTotalArchiveItemCount(n){var t=0;return n.forEach(function(n){t+=n.Items.length}),t}function filterResult(n,t){applyFilter(n);setResultCaption(t)}function applyFilter(n){var t,r,i;currentFilterString=n;t=$("#searchResultGrid").data("kendoGrid");n==="allItems"?t.dataSource.filter(null):(n.lastIndexOf(",")>0?(r=n.split(","),i=[],r.forEach(function(n){var t={field:"ArchiveId",operator:"eq",value:n};i.push(t)}),t.dataSource.filter({logic:"or",filters:i})):t.dataSource.filter({field:"ArchiveId",operator:"eq",value:n}),t.refresh())}function setResultCaption(n){$(".searchResult-caption").html(n)}function setPermanentUrl(n){var t=$("#permanentUrl");t.attr("href",n);t.text(n)}function onGridDataBound(){this.dataSource.total()<=this.dataSource.pageSize&&(this.options.pageable=!1);this.dataSource.total()===0?(this.pager.element.hide(),this.thead.hide(),this.pagerTop&&this.pagerTop.element.hide()):(this.pager.element.show(),this.thead.show(),this.pagerTop&&this.pagerTop.element.show());hideDigitizedColumnIfEmpty();clonePager()}function clonePager(){var n=$("#searchResultGrid").data("kendoGrid"),t;n.pagerTop||(t=$('<div class="k-pager-wrap k-grid-pager pagerTop hidden-xs"/>').insertBefore(n.element.children("table")),n.pagerTop=new kendo.ui.Pager(t[0],$.extend({},n.options.pageable,{dataSource:n.dataSource})),n.element.height("").find(".pagerTop").css("border-width","0 0 1px 0"))}function clearGridData(){var n=$("#searchResultGrid").data("kendoGrid"),t;n.dataSource.filter(null);t=new kendo.data.DataSource({data:[],pageSize:10});n.setDataSource(t);n.dataSource.fetch()}function createProgressBar(n,t,i){$("#loadingProgressBar").kendoProgressBar({min:n,max:t,value:i,showStatus:!1,animation:{duration:50}})}function hideDigitizedColumnIfEmpty(){for(var n=$("#searchResultGrid").data("kendoGrid"),i=n.dataSource.data(),r=!0,t=0;t<i.length;t++)if(i[t].HasDigitizedItems){r=!1;break}r?n.hideColumn("HasDigitizedItems"):n.showColumn("HasDigitizedItems")}function onSearchInvocationStarted(n){$("#resultsPanel").show();$("#resultWaitingMessagePanel").show();setResultCaption(n.DefaultCaption);setPermanentUrl(n.PermanentUrl)}function onSearchCompleted(n,t){destroyProgressBarAsync();createDropDownFilterList(n,t);$("#resultWaitingMessagePanel:visible").hide();$("#resultGridPanel:hidden").show();$("#executeSearchBtn").show();$("#searchExecuting").hide();$("#resetSearchBtn").removeClass("disabled")}function createDropDownFilterList(n,t){var i=[];i.push({text:t,value:"allItems"});n.forEach(function(n){var t=$.parseHTML(n.Text);i.push({text:t[0].text,value:$(n.Items).map(function(){return this.Id}).get().join()});n.Items.forEach(function(n){var t=$.parseHTML(n.Text);i.push({text:"..."+t[0].text,value:n.Id})})});$("#mobileFilter").kendoDropDownList({dataTextField:"text",dataValueField:"value",dataSource:i,change:function(){filterResult(this.value(),"")}});$("#mobileFilterArea").show()}function onSearchInvocationStarting(){$("#welcomePanel").hide();$("#resultGridPanel").hide();$("#mobileFilterArea").hide();$("#alternatePlaceNameListWrapper").hide();$("#executeSearchBtn").hide();$("#searchExecuting").show();$("#resetSearchBtn").addClass("disabled");currentFilterString="";clearGridData()}function setTreeSelectedState(n){for(var f,u,i,e,r=$(".k-treeview"),t=0;t<r.length;t++)for(f=$("#"+r[t].id).data("kendoTreeView"),u=$("#"+r[t].id+" .k-item"),i=0;i<u.length;i++)e=f.dataSource.getByUid($(u[i]).attr("data-uid")),e.set("checked",n);onCheck()}function initTreeState(){for(var i,r=$("#SearchModel_Archives").val(),u=r.split(","),t=$(".k-treeview"),n=0;n<t.length;n++)i=$("#"+t[n].id).data("kendoTreeView"),setCheckedNodes(i.dataSource.view(),u)}function setCheckedNodes(n,t){for(var i=0;i<n.length;i++)$.inArray(n[i].id,t)>=0&&n[i].set("checked",!0),n[i].hasChildren&&setCheckedNodes(n[i].children.view(),t)}function checkedNodeIds(n,t){for(var i=0;i<n.length;i++)n[i].checked&&t.push(n[i].id),n[i].hasChildren&&checkedNodeIds(n[i].children.view(),t)}function onCheck(){for(var u,n=[],i,r=$(".k-treeview"),t=0;t<r.length;t++)u=$("#"+r[t].id).data("kendoTreeView"),checkedNodeIds(u.dataSource.view(),n);i=n.length>0?n.join(","):"";$("#SearchModel_Archives").val(i)}function linkSelected(n,t){$.ajax({type:"POST",url:"Search/LinkClicked",data:JSON.stringify({archiveId:n,url:t}),contentType:"application/json; charset=utf-8",dataType:"json"})}$().ready(function(){var n=$.connection.searchHub,t=$.connection.hub.start();n.on("updateSearchStatus",function(n){onUpdateSearchStatus(n)});n.on("PublishAlternativePlaceNames",function(n){onPublishAlternativePlaceNames(n)});t.done(hubConnected);$.connection.hub.disconnected(function(){$.connection.hub.lastError&&console.log("Disconnected. Reason: "+$.connection.hub.lastError.message);$("#executeSearchBtn").prop("disabled","disabled");setTimeout(function(){var n=$.connection.hub.start();n.done(hubConnected)},250)})});var currentFilterString;$().ready(function(){$("input[name='SearchModel.SearchOption']").on("change",function(){var n=$(this).val();n==="SelectedArchives"?$(".archiveSelection").show():$(".archiveSelection").hide()});$("#removeSelectionLink").click(function(){return setTreeSelectedState(!1),!1});$("#selectAllLink").click(function(){return setTreeSelectedState(!0),!1});$("#resetSearchBtn").click(function(){$("#SearchModel_FulltextSearch").val("");$("#SearchModel_YearFrom").val("");$("#SearchModel_YearTo").val("");$("#SearchModel_UseTopoTerm").removeAttr("checked");setTreeSelectedState(!0);$("#SearchModel_SearchOption_AllArchives").click()});initTreeState();$("#excelExport").click(function(){var n=$("#searchResultGrid").data("kendoGrid");n.saveAsExcel()});var n=$("#Execute").val();(n==="true"||n==="True")&&setTimeout(function(){$("#executeSearchBtn").click()},500)})