. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
| Server IP : 52.223.31.75 / Your IP : 172.31.32.98 [ Web Server : Apache/2.4.66 () OpenSSL/1.0.2k-fips PHP/7.4.33 System : Linux ip-172-31-14-81.eu-central-1.compute.internal 4.14.281-212.502.amzn2.x86_64 #1 SMP Thu May 26 09:52:17 UTC 2022 x86_64 User : apache ( 48) PHP Version : 7.4.33 Disable Function : NONE Domains : 4 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /var/www/ripara.co/admin/js/controllers/ |
Upload File : |
materialAdmin
//=================================================
// Controller Lista Utenti e Inserimento Utente
//=================================================
.controller('categoriaCtrl', function($filter, $sce, $scope, ngTableParams, tableService, APIService, animationService) {
this.animationService = animationService;
$scope.elencoCampi=['Nome Categoria','Foto Categoria'];
$scope.elencoChiavi = ['nomecategoria','fotocategoria'];
//questa funzione fixa il problema delle chiavi con spazi o caratteri speciali nell'ordinamento delle tabelle
//utile per le alias colonne es. Numero Chiamante
$scope.rawProperty = function(key) {
return function(item) {
if ((key == "EndTime" || key == "StartTime" || key == "AnswerTime" || key == "AlertingTime")) {
return item[key]['sec'];
}
return item[key];
};
};
this.categoriaInsert = {
'idcategoria': '',
'nomecategoria': ''
};
//Caricament dati da API REST
this.getData = function (){
APIService.async({method: "getcategor"}).then(function(adata) {
if(adata.status && adata.message.length){
//assegno i dati ricevuti a data
var data = adata.message;
//aggiorno la variabile per ng-repeat della tabella
$scope.catctrl.data = data;
//instanzio la ng-table
$scope.catctrl.tableCategoria = new ngTableParams({
page: 1, // show first page
count: 10
},
{
total: data.length,// $scope.data.length, // length of data
getData: function($defer, params) {
//controllo se esisteno paramentri che si chiamamo orderby, all'onclick ordino per quel campo
if (params.sorting()['orderBy'] != undefined) {
//aggiungo la substr perchè il primo carattere viene messo random, altrimenti ordinerebbe sempre DESC visto che se è ordinata per una qualsiasi colonna non fa più ordinare per la stessa
var orderedData = $filter('orderBy')(data, $scope.rawProperty(params.sorting()['orderBy'].substr(1)),
$scope.catctrl.isSortBy);
$scope.catctrl.isSortBy = !$scope.catctrl.isSortBy;
//ok ma non funziona con le key con spazi o punti
//var orderedData = $filter('orderBy')(data, params.sorting()['orderBy']);
} else {
var orderedData = data;
}
//verifico se sono definiti filtri
//orderedData = $filter('filterFailed')(orderedData, $scope.showOnlyFailed);
if (params.sorting()['filter'] != undefined) {
var chiave = params.sorting()['filter'].key;
var value = params.sorting()['filter'].value;
var tmpSrc = {};
tmpSrc[chiave] = value;
orderedData = $filter('filter')(orderedData, tmpSrc);
}
params.total(orderedData.length); // set total for recalc pagination
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
}else{
animationService.setAnimationJam("bounceInDown", "alert-red", false, "Errore in fase di carimento dei dati, si prega di aggiornare la pagina!");
}
});
};
this.getData();
//Insert , @Peodacontrollare
this.newCategoria = 0;
this.submitCategoria = function() {
this.categoriaInsert.method = "insertcategor";
APIService.async(this.categoriaInsert).then(function(adata) {
if(adata.status){
$scope.catctrl.getData();
//svuoto i valori precedenti
for(x in $scope.catctrl.categoriaInsert){
$scope.catctrl.categoriaInsert[x] = "";
}
//nascondo il menu inserimento
$scope.catctrl.newCategoria = 0;
swal(adata.message, "success");
}else{
$scope.catctrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, "Errore in fase di aggiornamento dei dati, si prega di aggiornare la pagina!");
}
});
}
this.modificaCategoria = function () {
this.categoriaEdit.method = "editcategor";
APIService.async(this.categoriaEdit).then(function(adati) {
if(adati.status){
$scope.catctrl.getData();
//svuoto i valori precedenti
for(x in $scope.catctrl.categoriaEdit){
$scope.catctrl.categoriaEdit[x] = "";
}
//nascondo il menu inserimento
$scope.catctrl.editCategoria = 0;
swal(adati.message, "success");
}else{
$scope.catctrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, adati.message);
}
});
}
this.cancellaCategoria = function (dati) {
swal({
title: "Sei sicuro di voler cancellare la categoria '"+dati.nomecategoria+"' ?",
text: "L'azione eseguita sarà irreversibile!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Si, cancellala!",
closeOnConfirm: false
}, function(){
dati.$edit = false;
dati.method = "deletecategor";
APIService.async(dati).then(function(adati) {
if(adati.status){
swal(adati.message, "Categoria eliminata con successo!", "success");
$scope.catctrl.getData();
}else{
$scope.catctrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, "Non puoi cancellare questa categoria perchè ci sono altri elementi legati ad essa!");
}
});
});
}
//per insert
this.aggiornaImgInsert= function(){
//setto l'immagine in real time
var fileInput = $('#foto-input');
var file = fileInput[0].files[0];
this.categoriaInsert.upload = file;
var imageType = /image.*/;
if (file.type.match(imageType)) {
var reader = new FileReader();
reader.addEventListener("load", function () {
$scope.catctrl.categoriaInsert.previewImage = this.result;
$('#mock').click();
}, false);
reader.readAsDataURL(file);
} else {
alert("File non supportato!");
}
}
//per insert
this.aggiornaImgUpdate= function(){
//setto l'immagine in real time
var fileInput = $('#foto-input');
var file = fileInput[0].files[0];
this.categoriaEdit.upload = file;
this.categoriaEdit.newfoto = 1;
var imageType = /image.*/;
if (file.type.match(imageType)) {
var reader = new FileReader();
reader.addEventListener("load", function () {
$scope.catctrl.categoriaEdit.previewImage = this.result;
$('#mock').click();
}, false);
reader.readAsDataURL(file);
} else {
alert("File non supportato!");
}
}
this.categoriaEdit = {};
$scope.editCategoria = function(w){
$scope.catctrl.categoriaEdit.nomecategoria = w.nomecategoria;
$scope.catctrl.categoriaEdit.previewImage = w.fotocategoria;
$scope.catctrl.categoriaEdit.idcategoria = w.idcategoria;
$scope.catctrl.editCategoria = 1;
}
})