You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SIPRP/trunk/SiprpWebFichasClinicas/WebContent/static/scripts/safemode/edit-double-list.js

679 lines
18 KiB

$.noConflict();
(function($) {
$.QueryString = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'));
})(jQuery);
var app = angular.module('ngEditDiploma', ['ui.bootstrap']);
app.controller('EditDiplomaCtrl', ['$scope', '$modal', '$q', '$location', function($scope, $modal, $q, $location) {
//$scope.bean = null;
$scope.fileData = {
fileName: 'Nenhum ficheiro seleccionado',
selectedFile: null,
alterado: false,
fileSelected: false,
fileTooltip: 'Editar ficheiro'
};
jQuery("#btn").click(function()
{
if($scope.fileData.fileSelected === false)
{
jQuery("#pdf").click();
$scope.fileData.alterado = true;
}
else
{
$scope.fileData.selectedFile = null;
$scope.fileData.alterado = true;
}
$scope.$apply();
});
$scope.$watch("fileData.selectedFile", function(value)
{
if( value !== null )
{
$scope.fileData.fileSelected = true;
$scope.fileData.fileName = value.replace(/.*(\/|\\)/, '');
}
else
{
$scope.fileData.fileSelected = false;
$scope.fileData.fileName = 'Nenhum ficheiro seleccionado';
}
});
$scope.$watch("fileData.fileSelected", function(value)
{
if(value === false)
{
$scope.fileData.fileTooltip = 'Editar ficheiro';
}
else
{
$scope.fileData.fileTooltip = 'Remover ficheiro';
}
});
$scope.location = jQuery.QueryString["id"];
$scope.loadCategorias = function() {
var wsClient = new ws_safemode_pt__LegislacaoWS_impl_ws_safemode_pt__LegislacaoWSImplPort( );
wsClient.getAllCategorias(function(x, y) {
$scope.categorias.listaCategorias = [];
jQuery.merge( $scope.categorias.listaCategorias, x.getReturn() );
$scope.$apply();
}, function(x, y) {
if( x === 340 )
{
window.location.href = window.location.href;
}
else alert( x + " " + y );
});
};
$scope.categorias = {
listaCategorias: [],
listaTemas: [],
listaSubtemas: [],
categoria: null,
tema: null,
subtema: null,
add: function() {
if( ( $scope.categorias.subtema !== null ) && ( $scope.categorias.subtema !== undefined ) && ( $scope.categorias.subtema !== "" ) )
{
$scope.bean._subtemas.push($scope.categorias.subtema);
}
else if( ( $scope.categorias.tema !== null ) && ( $scope.categorias.tema !== undefined ) && ( $scope.categorias.tema !== "" ) )
{
$scope.bean._subtemas.push($scope.categorias.tema);
}
$scope.categorias.subtema = null;
$scope.categorias.tema = null;
$scope.categorias.categoria = null;
$scope.categorias.listaTemas = [];
$scope.categorias.listaSubtemas = [];
},
remove: function(item) {
var position = jQuery.inArray(item, $scope.bean._subtemas);
if (position !== -1) {
$scope.bean._subtemas.splice(position, 1);
}
},
loadTemas: function(item) {
var wsClient = new ws_safemode_pt__LegislacaoWS_impl_ws_safemode_pt__LegislacaoWSImplPort( );
wsClient.getAllTemas(function(x, y) {
$scope.categorias.listaTemas = [];
jQuery.merge( $scope.categorias.listaTemas, x.getReturn() );
$scope.$apply();
}, function(x, y) {
if( x === 340 )
{
window.location.href = window.location.href;
}
else alert( x + " " + y );
}, item);
},
loadSubtemas: function(item) {
var wsClient = new ws_safemode_pt__LegislacaoWS_impl_ws_safemode_pt__LegislacaoWSImplPort( );
wsClient.getAllSubtemas(function(x, y) {
$scope.categorias.listaSubtemas = [];
jQuery.merge( $scope.categorias.listaSubtemas, x.getReturn() );
$scope.$apply();
}, function(x, y) {
if( x === 340 )
{
window.location.href = window.location.href;
}
else alert( x + " " + y );
}, item);
}
};
$scope.loadCategorias();
$scope.$watch("categorias.categoria", function(value) {
if ( (value !== undefined) && (value !== null) ) {
$scope.categorias.loadTemas(value);
} else {
$scope.categorias.listaTemas = [];
$scope.categorias.tema = null;
}
});
$scope.$watch("categorias.tema", function(value) {
if ( (value !== undefined) && (value !== null) ) {
$scope.categorias.loadSubtemas(value);
} else {
$scope.categorias.listaSubtemas = [];
$scope.categorias.subtema = null;
}
});
$scope.load = function()
{
if( $scope.bean === undefined )
{
var tipos = new ws_safemode_pt__LegislacaoWS_impl_ws_safemode_pt__LegislacaoWSImplPort();
tipos.getDiplomaView(function(result)
{
$scope.$apply(function()
{
$scope.bean = new ws_safemode_pt__legislacaoBean();
var returnBean = result._return;
$scope.bean._cnpdDirectivasEuropeias = returnBean._cnpdDirectivasEuropeias;
$scope.bean._data_publicacao = returnBean._data_publicacao;
$scope.bean._diplomasAlterados = returnBean._diplomasAlterados;
$scope.bean._diplomasRelacionados = returnBean._diplomasRelacionados;
$scope.bean._diplomasRepublicados = returnBean._diplomasRepublicados;
$scope.bean._diplomasRevogados = returnBean._diplomasRevogados;
$scope.bean._disposicoesTransitorias = returnBean._disposicoesTransitorias;
$scope.bean._entidadesReguladoras = returnBean._entidadesReguladoras;
$scope.bean._estado = returnBean._estado;
$scope.bean._numero = returnBean._numero;
$scope.bean._observacoes = returnBean._observacoes;
$scope.bean._palavrasChave = returnBean._palavrasChave;
$scope.bean._subtemas = returnBean._subtemas;
$scope.bean._sumario = returnBean._sumario;
$scope.bean._tipo = returnBean._tipo;
$scope.bean._id = returnBean._id;
if(returnBean._temFicheiro)
{
$scope.fileData.selectedFile = (returnBean._tipo + " " + returnBean._numero + " " + returnBean._data_publicacao.replace("\/","-").replace("\/","-") + ".pdf").split(' ').join('_');
}
else
{
$scope.fileData.selectedFile = null;
}
});
}, function(x, y)
{
if( x === 340 )
{
window.location.href = window.location.href;
}
else
{
alert( x + " " + y );
$scope.bean = new ws_safemode_pt__legislacaoBean();
}
}, jQuery.QueryString["id"]);
}
};
$scope.load( );
$scope.tipo = function()
{
if( $scope.tipos === undefined )
{
var tipos = new ws_safemode_pt__LegislacaoWS_impl_ws_safemode_pt__LegislacaoWSImplPort();
tipos.getTipos(function(result)
{
$scope.tipos = result._return;
$scope.$apply();
}, function(x, y)
{
if( x === 340 )
{
window.location.href = window.location.href;
}
else $scope.tipos = [];
});
}
};
$scope.tipo();
$scope.estado = function()
{
if( $scope.estados === undefined )
{
var estados = new ws_safemode_pt__LegislacaoWS_impl_ws_safemode_pt__LegislacaoWSImplPort();
estados.getEstados(function(result)
{
$scope.estados = result._return;
$scope.$apply();
}, function(x, y)
{
if( x === 340 )
{
window.location.href = window.location.href;
}
else $scope.estados = [];
});
}
};
$scope.estado();
$scope.entidadeReguladora = function()
{
if( $scope.entidadesReguladoras === undefined )
{
var diplomas = new ws_safemode_pt__LegislacaoWS_impl_ws_safemode_pt__LegislacaoWSImplPort();
diplomas.getEntidadesReguladoras(function(result)
{
$scope.entidadesReguladoras = result._return;
$scope.$apply();
}, function(x, y)
{
if( x === 340 )
{
window.location.href = window.location.href;
}
else deferred.resolve([]);
});
}
};
$scope.entidadeReguladora( );
$scope.getPalavrasChave = function(filter)
{
var deferred = $q.defer();
var palavrasChave = new ws_safemode_pt__LegislacaoWS_impl_ws_safemode_pt__LegislacaoWSImplPort();
palavrasChave.getPalavrasChave(filter, function(result)
{
deferred.resolve(result._return);
}, function(x, y)
{
if( x === 340 )
{
window.location.href = window.location.href;
}
else deferred.resolve([]);
});
return deferred.promise;
};
$scope.tags = {
tags: function( filter )
{
return $scope.getPalavrasChave( filter ).then(function(res)
{
return res;
});
},
selected: null,
addTag: function( )
{
if(this.selected !== null)
{
$scope.bean._palavrasChave.push( this.selected );
this.selected = null;
}
},
removeTag: function(tag)
{
var position = jQuery.inArray(tag, $scope.bean._palavrasChave);
if(position !== -1)
{
$scope.bean._palavrasChave.splice(position, 1);
}
}
};
$scope.getDiplomas = function(filter)
{
var deferred = $q.defer();
var diplomas = new ws_safemode_pt__LegislacaoWS_impl_ws_safemode_pt__LegislacaoWSImplPort();
diplomas.getDiplomas(function(result)
{
deferred.resolve(result._return);
}, function(x, y)
{
if( x === 340 )
{
window.location.href = window.location.href;
}
else deferred.resolve([]);
}, filter);
return deferred.promise;
};
$scope.related = {
tags: function( filter )
{
return $scope.getDiplomas( filter ).then(function(res)
{
return res;
});
},
selected: null,
addTag: function( )
{
if(this.selected !== null)
{
$scope.bean._diplomasRelacionados.push( this.selected );
this.selected = null;
}
},
removeTag: function(tag)
{
var position = jQuery.inArray(tag, $scope.bean._diplomasRelacionados);
if(position !== -1)
{
$scope.bean._diplomasRelacionados.splice(position, 1);
}
}
};
$scope.entidades = {
selected: null,
addTag: function( )
{
if(this.selected !== null)
{
$scope.bean._entidadesReguladoras.push( this.selected );
this.selected = null;
}
},
removeTag: function(tag)
{
var position = jQuery.inArray(tag, $scope.bean._entidadesReguladoras);
if(position !== -1)
{
$scope.bean._entidadesReguladoras.splice(position, 1);
}
}
};
$scope.revogados = {
tags: function( filter )
{
return $scope.getDiplomas( filter ).then(function(res)
{
return res;
});
},
selected: null,
addTag: function( )
{
if(this.selected !== null)
{
var modalInstance = $modal.open({
templateUrl: 'revogados.html',
controller: 'ModalRevogadosCtrl'
});
modalInstance.result.then(function (selectedItem) {
var resultado = new ws_safemode_pt__alteracaoBean();
resultado._id = $scope.revogados.selected._id;
resultado._designacao = $scope.revogados.selected._designacao;
resultado._detalhes = selectedItem;
$scope.bean._diplomasRevogados.push( resultado );
$scope.revogados.selected = null;
}, function () {
console.log('');
});
}
},
removeTag: function(tag)
{
var position = jQuery.inArray(tag, $scope.bean._diplomasRevogados);
if(position !== -1)
{
$scope.bean._diplomasRevogados.splice(position, 1);
}
}
};
$scope.republicados = {
tags: function( filter )
{
return $scope.getDiplomas( filter ).then(function(res)
{
return res;
});
},
selected: null,
addTag: function( )
{
if(this.selected !== null)
{
var modalInstance = $modal.open({
templateUrl: 'republicados.html',
controller: 'ModalRepublicadosCtrl'
});
modalInstance.result.then(function (selectedItem) {
var resultado = new ws_safemode_pt__alteracaoBean();
resultado._id = $scope.republicados.selected._id;
resultado._designacao = $scope.republicados.selected._designacao;
resultado._detalhes = selectedItem;
$scope.bean._diplomasRepublicados.push( resultado );
$scope.republicados.selected = null;
}, function () {
console.log('');
});
}
},
removeTag: function(tag)
{
var position = jQuery.inArray(tag, $scope.bean._diplomasRepublicados);
if(position !== -1)
{
$scope.bean._diplomasRepublicados.splice(position, 1);
}
}
};
$scope.alterados = {
tags: function( filter )
{
return $scope.getDiplomas( filter ).then(function(res)
{
return res;
});
},
selected: null,
addTag: function( )
{
if(this.selected !== null)
{
var modalInstance = $modal.open({
templateUrl: 'alterados.html',
controller: 'ModalAlteradosCtrl'
});
modalInstance.result.then(function (selectedItem) {
var resultado = new ws_safemode_pt__alteracaoBean();
resultado._id = $scope.alterados.selected._id;
resultado._designacao = $scope.alterados.selected._designacao;
resultado._detalhes = selectedItem;
$scope.bean._diplomasAlterados.push( resultado );
$scope.alterados.selected = null;
}, function () {
console.log('');
});
}
},
removeTag: function(tag)
{
var position = jQuery.inArray(tag, $scope.bean._diplomasAlterados);
if(position !== -1)
{
$scope.bean._diplomasAlterados.splice(position, 1);
}
}
};
$scope.data = {
numero: null,
publicacao: null,
publicacao_string: null,
file: null,
estado: null,
tipo: null,
observacoes: null,
disposicoesTransitorias: null,
palavrasChave: null
};
$scope.submit = function( )
{
jQuery("body").css("cursor", "wait");
var diplomas = new ws_safemode_pt__LegislacaoWS_impl_ws_safemode_pt__LegislacaoWSImplPort();
diplomas.changeDiploma(function(result)
{
if( $scope.fileData.alterado )
{
if( $scope.fileData.fileSelected )
{
jQuery("body").css("cursor", "auto");
alert("Diploma alterado com successo.\nA enviar ficheiro pdf...");
//Send the pdf file...
jQuery( "#createLeg" ).submit();
}
else
{
diplomas.removePdf( function(result)
{
jQuery("body").css("cursor", "auto");
alert("Diploma alterado com successo.");
window.location = "/safemode/pages/legislacao/listagemDiploma.do?id=" + $scope.bean._id;
}, function(x, y)
{
if( x === 340 )
{
window.location.href = window.location.href;
}
jQuery("body").css("cursor", "auto");
}, $scope.bean._id);
}
}
else
{
jQuery("body").css("cursor", "auto");
alert("Diploma alterado com successo.");
window.location = "/safemode/pages/legislacao/listagemDiploma.do?id=" + $scope.bean._id;
}
}, function(x, y)
{
if( x === 340 )
{
window.location.href = window.location.href;
}
else alert("Erro ao editar o diploma, por favor verifique se os dados estão bem preenchidos");
jQuery("body").css("cursor", "auto");
}, $scope.bean);
};
$scope.cancel = function( )
{
window.location = "/safemode/pages/legislacao/listagemDiploma.do?id=" + $scope.bean._id;
};
$scope.tipo = null;
$scope.add = function()
{
$scope.tag.tags.append($scope.tag.selected);
};
jQuery('#dataPublicacaoControl').datepicker({
weekStart: 1,
viewMode: 0
}).on('changeDate', function(ev)
{
$scope.$apply(function()
{
console.log($scope.bean);
$scope.data.publicacao = ev.date;
var day = ev.date.getDate().toString();
if (day.length == 1)
{
day = "0" + day;
}
var month = ev.date.getMonth() + 1 + "";
if (month.length == 1)
{
month = "0" + month;
}
var year = ev.date.getFullYear().toString();
$scope.bean._data_publicacao = day + "/" + month + "/" + year;
});
});
}]);
app.controller('ModalRevogadosCtrl', ['$scope', '$modalInstance', function ($scope, $modalInstance)
{
$scope.selected = {
item: ''
};
$scope.ok = function () {
$modalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}]);
app.controller('ModalRepublicadosCtrl', ['$scope', '$modalInstance', function ($scope, $modalInstance)
{
$scope.selected = {
item: ''
};
$scope.ok = function () {
$modalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}]);
app.controller('ModalAlteradosCtrl', ['$scope', '$modalInstance', function ($scope, $modalInstance)
{
$scope.selected = {
item: ''
};
$scope.ok = function () {
$modalInstance.close($scope.selected.item);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}]);