3
Hello.
I have 2 lists being mounted in javascript, based on the rule:
- Do you have flag queries Then stay in the Array: clientesDownloadTrue
- Do you have flag queries Then it stays in the Array: clientesDownloadFalse
The screen is this:
When sending, I want to be able to know exactly which record went to one side or the other?
Follow my javascript:
app.controller("ConfiguraDownloadAutomatico",
function($scope, $http,$filter,dialogMessage) {
$scope.clientes = [];
$scope.clientesDownloadFalse= [];
$scope.clientesDownloadTrue =[];
// picklist
$scope.selectedA = [];
$scope.selectedB = [];
$scope.items = [];
$scope.checkedA = false;
$scope.checkedB = false;
/**
* Obter sessão
*/
$scope.loadSession = function() {
$http({
method : 'GET',
url : 'session'
}).then(function successCallback(response) {
$scope.idUsuario = response.data.result.id_usuario;
$scope.iniciar();
}, function errorCallback(response) {
console.log(response.data);
});
};
$scope.loadSession();
$scope.iniciar = function() {
$http.post('obterEmpresasDownload', $scope.idUsuario).success(function(response) {
$scope.clientes = response;
$scope.items = response;
angular.forEach($scope.clientes, function(value, key){
if(value.consultaNotasDestinadasAutomaticamente == true){
$scope.clientesDownloadTrue.push(value);
}else{
$scope.clientesDownloadFalse.push(value);
}
});
});
};
$scope.preparaInsercao = function(clientesDownloadFalse, clientesDownloadTrue) {
var dados = {
clientesDownloadFalse : $scope.clientesDownloadFalse,
clientesDownloadTrue : $scope.clientesDownloadTrue
};
$http.post(
'configuradownload/salvarEmpresasDownloadAutomatico',
dados).then(
function(response) {
if (response.data.codReturn == 0) {
dialogMessage("Configura Download Automático",
response.data.descReturn, "success");
} else {
dialogMessage("Configura Download Automático",
response.data.descReturn, "erro");
}
}, function(response) {
});
};
function arrayObjectIndexOf(myArray, searchTerm, property) {
for(var i = 0, len = myArray.length; i < len; i++) {
if (myArray[i][property] === searchTerm) return i;
}
return -1;
}
$scope.aToB = function() {
for (i in $scope.selectedA) {
var moveId = arrayObjectIndexOf($scope.items, $scope.selectedA[i], "idCliente");
$scope.clientesDownloadTrue.push($scope.items[moveId]);
var delId = arrayObjectIndexOf($scope.clientesDownloadFalse, $scope.selectedA[i], "idCliente");
$scope.clientesDownloadFalse.splice(delId,1);
}
reset();
};
$scope.bToA = function() {
for (i in $scope.selectedB) {
var moveId = arrayObjectIndexOf($scope.items, $scope.selectedB[i], "idCliente");
$scope.clientesDownloadFalse.push($scope.items[moveId]);
var delId = arrayObjectIndexOf($scope.clientesDownloadTrue, $scope.selectedB[i], "idCliente");
$scope.clientesDownloadTrue.splice(delId,1);
}
reset();
};
function reset(){
$scope.selectedA=[];
$scope.selectedB=[];
$scope.toggle=0;
}
$scope.toggleA = function() {
if ($scope.selectedA.length>0) {
$scope.selectedA=[];
}
else {
for (i in $scope.clientesDownloadFalse) {
$scope.selectedA.push($scope.clientesDownloadFalse[i].idCliente);
}
}
}
$scope.toggleB = function() {
if ($scope.selectedB.length>0) {
$scope.selectedB=[];
}
else {
for (i in $scope.clientesDownloadTrue) {
$scope.selectedB.push($scope.clientesDownloadTrue[i].idCliente);
}
}
}
$scope.selectA = function(i) {
$scope.selectedA.push(i);
};
$scope.selectB = function(i) {
$scope.selectedB.push(i);
};
});
When saving, call the function prepareInsercao that picks up the lists, sends it to my java controller and saves the object there.
In case you need more information, post on time. Thank you.