mainAppModule.controller('genericSqlReportCtrl', function($scope,ajaxService){ $scope.filterColumns = null; $scope.jsonRequestUrl = null; $scope.checkedColumns = null; $scope.onInit = function(){ $scope.filterColumns = angular.fromJson($("#filterColumnsId").html()); $("#filterColumnsId").remove(); $scope.checkedColumns = {}; angular.forEach($scope.filterColumns,function(item,key){ $scope.checkedColumns["" + key + ""] = false; $("#text_" + key).hide(); },null); }; $scope.reconstrMap = function(){ $map = angular.fromJson($("#mapCont").html()); $("#map").val($("#mapCont").html()); $("#mapCont").remove(); $filterCBActivatorData = []; angular.forEach($scope.filterColumns,function(value,index){ if($map[value] != undefined){ $scope.checkedColumns["" + index + ""] = true; $("#text_" + index).val($map[value]); $("#text_" + index).show(); this.push(index); } },$filterCBActivatorData); $("#filterCBActivatorData").val(angular.toJson($filterCBActivatorData)); $("#filterCBActivator").trigger("onclick"); }; $scope.onChangeCB = function(cbJQElem){ $index = cbJQElem.id.split("_")[1]; $scope.checkedColumns["" + $index + ""] = $("#" + cbJQElem.id).prop("checked"); if($("#" + cbJQElem.id).prop("checked") == true) $("#text_" + $index).show(); else $("#text_" + $index).hide(); $scope.setMap(); }; $scope.onKeyPress = function(event){ if(event.which == 13){ $("#filter").submit(); } else $scope.setMap(); }; $scope.setMap = function(){ $map = {}; angular.forEach($scope.checkedColumns,function(value,key){ if(value == true && $("#text_" + key).val() != ""){ $map[$scope.filterColumns[parseInt(key)]] = $("#text_" + key).val(); } },null); $("#map").val(angular.toJson($map)); }; });