. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
| Server IP : 52.223.31.75 / Your IP : 172.31.6.220 [ 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('sediCtrl', function($filter, $sce, $scope, ngTableParams, tableService, APIService, animationService, growlService) {
this.animationService = animationService;
$scope.elencoCampi=['Nome', 'Indirizzo', 'Telefono', 'Link Map'];
$scope.elencoChiavi = ['nomestato', 'descrizione', 'telefono', 'linkmap'];
//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.statiInsert = {
'nomesede': '',
'descrizione': '',
'telefono': '',
'linkmap': ''
};
this.statiEdit = {
'idsede': '',
'nomesede': '',
'descrizione': '',
'telefono': '',
'linkmap': ''
};
$scope.tmpSrc = {};
//Caricament dati da API REST
this.getData = function (){
APIService.async({method: "getsedi"}).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.stctrl.data = data;
//instanzio la ng-table
$scope.stctrl.tablestati = 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.stctrl.isSortBy);
$scope.stctrl.isSortBy = !$scope.stctrl.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;
$scope.tmpSrc[chiave] = value;
console.log(chiave + "|||||" +value);
debugger;
orderedData = $filter('filter')(orderedData, $scope.tmpSrc);
}else {
var orderedData = data;
}
params.total(orderedData.length); // set total for recalc pagination
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
}else{
if(adata.message.length == 0 ){
animationService.setAnimationJam("bounceInDown", "alert-orange", false, "Nessuna sede presente nel sistema!");
}else{
animationService.setAnimationJam("bounceInDown", "alert-red", false, "Errore in fase di carimento dei dati, si prega di aggiornare la pagina!");
}
}
});
};
//Insert , @Peodacontrollare
this.newstati = 0;
this.submitstati = function(valido) {
try{
this.statiInsert.linkmap = sistemaLinkMap(this.statiInsert.linkmap);
}catch(e){}
this.statiInsert.method = "insertsede";
APIService.async(this.statiInsert).then(function(adata) {
if(adata.status){
swal(adata.message, "Sede inserita con successo!", "success")
//aggiorno la lista degli utenti
$scope.stctrl.getData();
//svuoto i valori precedenti
for(x in $scope.stctrl.statiInsert){
$scope.stctrl.statiInsert[x] = ""; }
//nascondo il menu inserimento
$scope.stctrl.newstati = 0;
}else{
$scope.stctrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, adati.message );
}
});
}
$scope.sistemaLinkMap = function (linkmap) {
linkmap = linkmap.split('width="');
linkmap[1] = linkmap[1].substring(linkmap[1].indexOf('"')+1);
linkmap = linkmap[0] + "100%" + linkmap[1];
linkmap = linkmap.split('height="');
linkmap[1] = linkmap[1].substring(linkmap[1].indexOf('"')+1);
linkmap = linkmap[0] + "650" + linkmap[1];
return linkmap;
}
this.modificastati = function (dati) { //width="100%" height="650"
try{
dati.linkmap = sistemaLinkMap(dati.linkmap);
}catch(e){}
dati.$edit = false;
dati.method = "editsede";
APIService.async(dati).then(function(adati) {
if(adati.status){
swal(adati.message, "Sede modificata con successo!", "success");
}else{
$scope.stctrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, adati.message + " - Assicurarsi di aver modificato i dati!");
}
});
}
this.cancellastati = function (dati) {
swal({
title: "Sei sicuro di voler cancellare la sede '"+dati.nomesede+"' ?",
text: "L'azione eseguita sarà irreversibile!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Si, cancellalo!",
closeOnConfirm: false
}, function(){
dati.$edit = false;
dati.method = "deletesede";
APIService.async(dati).then(function(adati) {
if(adati.status){
swal(adati.message, "Sede eliminata con successo!", "success");
$scope.stctrl.getData();
}else{
$scope.stctrl.animationService.setAnimationJam("bounceInDown", "alert-red", false, "Non puoi cancellare questo stati perchè ci sono altri elementi legati ad esso!");
}
});
});
}
this.getData();
})