angular.module("knimbusLib").controller("savedSearchesCtrl",function($scope,$http,$location,PromiseAjax,$routeParams,$cookieStore,$window,$rootScope,$filter){$scope.loadSavedSearches=function(){$rootScope.showloader();PromiseAjax.getData("/ws/getDocsFromLc?type\x3dSAVED_SEARCH","GET").then(function(result){$scope.result=result;$scope.savedSearchData=result.doclist;$rootScope.hideloader()}).catch(function(error){console.error("error")})};$scope.loadSavedSearches();$scope.doneForReload=function(){location.reload()};
$scope.searchBtn=function(searchTerm){$rootScope.showloader();var searctermFilter=searchTerm;sessionStorage.result_type=JSON.stringify("ECATALOGUE_BASED");sessionStorage.searchKeyword=JSON.stringify(searctermFilter);var param={"searchTermFilter":searctermFilter,"searchedFrom":"searchBar","category":"none"};sessionStorage.searchQuery=JSON.stringify(param);PromiseAjax.getData("/ws/search/getDataFromSearchOrAdvSearch","POST",param).then(function(searchResponse){$scope.resultData=searchResponse;console.log(searchResponse);
if(searchResponse=="Search error"){$scope.strMessage="Search error";$("#alertBoxModal").modal("show")}else{sessionStorage.searchResults=JSON.stringify(searchResponse);$location.path("/searchresult").search({searchId:searctermFilter})}$rootScope.hideloader()}).catch(function(error){console.error("error: "+error)})};$scope.deleteSavedSearch=function(id,savedKeyword){var param={"unique_id":id};$rootScope.showloader();PromiseAjax.getData("/ws/deleteDataFromLc","POST",param).then(function(response){var param1=
{"action":"Delete Saved Search","actionValue":savedKeyword};PromiseAjax.getData("/ws/addLogging","POST",param1).then(function(searchResponse){console.log("Logging done",param1)});$rootScope.hideloader();$scope.strMessage="Saved Search deleted successfully. Please be aware that it may take a brief period to reflect in this list. If the link has not removed from the list yet, kindly click the Refresh Button to ensure the most up-to-date information.";$("#alertReloadBoxModal").modal({backdrop:"static"})}).catch(function(error){console.error("error: "+
error)})};$scope.deleteSavedSearch=function(id){$scope.ssId=id;$scope.strMessage="Are you sure you want to delete?";$("#confirmationBoxModal").modal("show")};$scope.deleteSavedSearchConfirm=function(){var param={"unique_id":$scope.ssId};$rootScope.showloader();PromiseAjax.getData("/ws/deleteDataFromLc","POST",param).then(function(response){var param1={"action":"Delete Saved Search","actionValue":$scope.id};PromiseAjax.getData("/ws/addLogging","POST",param1).then(function(searchResponse){console.log("Logging done",
param1)});$rootScope.hideloader();$("#confirmationBoxModal").modal("hide");$scope.strMessage="Search has been deleted sucessfully. Please be aware that it may take a brief period to reflect in this list. If the link has not removed from the list yet, kindly click the Refresh Button to ensure the most up-to-date information.";$("#alertReloadBoxModal").modal("show")}).catch(function(error){console.error("error: "+error)})};$scope.curPage=0;$scope.pageSize=10;$scope.numberOfPages=function(){return $scope.result!=
undefined&&$scope.result!=null&&$scope.result!=""&&$scope.result.totalHits>0?Math.ceil($scope.result.totalHits/$scope.pageSize):0};$scope.pagination=function(curPageStatus){if(curPageStatus!=undefined||curPageStatus!=""||curPageStatus!=null)$scope.curPage=curPageStatus;$scope.offset=$scope.curPage*10;$rootScope.showloader();PromiseAjax.getData("/ws/getDocsFromLc?type\x3dSAVED_SEARCH\x26offset\x3d"+$scope.offset,"GET").then(function(result){$scope.result=result;$scope.savedSearchData=result.doclist;
$location.path("/myLibrary/savedSearches");$rootScope.hideloader()}).catch(function(error){console.error("error")})}});