mainAppModule.controller('gestionarePetitiiCtrl',function($scope,ajaxService,browserInfoService){ $scope.xhr_in_progress = false; $scope.info = { table : { isEmpty : true, items : null, totalItemsCount : null, filteredItemsCount : null, totalPageNum : null, crtPageNum : null, crtPageGroup : null, groupSelectOptions : null, pageSelectOptions : null, additInfo : null }, search : { id : "", cnp : "", nume : "", prenume : "", //stare : {cod : "TRANSMISA_FARA_RASPUNS" , nume: "Transmisa fara raspuns"}, stare : {cod : "TOATE" , nume: "TOATE"}, successMemento : null, optiuniStare : null, ctp : { id : -1, nume : "TOATE" } }, params : { type : null, info : { queryEntity : null, pageNum : null, pageGroup : null, addit : null } }, jsonRequestUrl : "" }; $scope.onSearch = function(event){ if(event == undefined || event.which == 13){ if($scope.info.search.id == "" && $scope.info.search.cnp == "" && $scope.info.search.nume == "" && $scope.info.search.prenume == "" && $scope.info.search.ctp.nume == "TOATE" && $scope.info.search.stare.cod == "TOATE") $scope.info.search.successMemento = null; else{ $scope.info.search.successMemento = { column : "id", value : $scope.info.search.id, opInLink : null, opType : 1, lads : [{ column : "cnp", value : $scope.info.search.cnp, opInLink : "and", opType : 1, lads : []} ,{ column : "nume", value : $scope.info.search.nume, opInLink : "and", opType : 1, lads : []} ,{ column : "prenume", value : $scope.info.search.prenume, opInLink : "and", opType : 1, lads : []} ,{ column : "stare", value : $scope.info.search.stare.cod == "TOATE" ? "" : $scope.info.search.stare.cod, opInLink : "and", opType : 2, lads : []}] }; if($scope.info.table.additInfo['isCTPCentru'] == true && $scope.info.search.ctp.nume != "TOATE"){ $scope.info.search.successMemento.lads.push({ column : "ctp.id", value : $scope.info.search.ctp.id, opInLink : "and", opType : 2, lads : [] }); } } $scope.retrieveItems($scope.formParams("onSearch")); } }; $scope.template = { table : angular.copy($scope.info.table), search : angular.copy($scope.info.search), params : angular.copy($scope.info.params) }; $scope.retrieveItems = function(params){ $scope.xhr_in_progress = true; ajaxService.sendXTR($scope.info.jsonRequestUrl,$.param(params)) .then(function(result){ $scope.xhr_in_progress = false; //$scope.info.search.optiuniStare = $scope.info.table.additInfo["optiuniStare"]; if (result != null && result.items != null) { if(!result.isEmpty && result.items.length == 1 && result.crtPageNum == 1){ $("#cautaPetitieId").val(result.items[0].id); $("#cautaFormId").submit(); } else $scope.info.table = result; } }, function(status){ console.log("Eroare la request XHR trimis in functia 'retrieveItems' :"); console.log(status); $scope.xhr_in_progress = false; }); }; $scope.formParams = function(type,item){ $params = angular.copy($scope.template.params); $params.type = type; $params.info.queryEntity = $scope.info.search.successMemento; $params.info.pageNum = $scope.info.table.crtPageNum == null ? 1 : $scope.info.table.crtPageNum; $params.info.pageGroup = $scope.info.table.crtPageGroup == null ? 5 : $scope.info.table.crtPageGroup; if(item != undefined){ $params.info.addit = { id : item.id }; } $params.info = angular.toJson($params.info); return $params; }; $scope.onArchive = function(item){ var rezultat = window.confirm("Sunteti sigur ca doriti sa arhivati aceasta petitie?\nDaca DA apasati butonul OK."); if(rezultat == true){ $scope.retrieveItems($scope.formParams("onArchive",item)); } }; $scope.onChangePage = function(){ $scope.retrieveItems($scope.formParams("onChangePage")); }; $scope.onChangeGroup = function(){ $scope.retrieveItems($scope.formParams("onChangeGroup")); }; $scope.onCancelFilter = function(){ $scope.info.search = angular.copy($scope.template.search); $scope.onInitPage(); }; $scope.onInitPage = function(){ $scope.retrieveItems($scope.formParams("onInitPage")); }; });