Skip to content

Commit 2da377c

Browse files
committed
suzdalenko
1 parent 0387189 commit 2da377c

8 files changed

Lines changed: 90 additions & 44 deletions

assets/css/style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ b{
340340
cursor: pointer;
341341
}
342342
.doc-preview{
343-
height: 257px;
344-
width: 197px;
343+
height: 190px;
344+
width: 147px;
345345
}
346346

347347
.doc-actions {

assets/views/crear-nueva-etiqueta.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function crearNuevaEtiquetaInit(){
22
document.title = "Crear nueva etiqueta";
3-
document.getElementById('slugTitle').innerHTML = '<h2 class="text-xl font-semibold mb-4">Crear Nueva Etiqueta<h/2>';
3+
document.getElementById('slugTitle').innerHTML = '<h2 class="text-xl font-semibold mb-4">Crear nueva etiqueta<h/2>';
44

55
getUserTagsCNE();
66
}

assets/views/crear-nuevo-documento.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ let dataSetedCDN = new Set();
33

44
function crearNuevoDocumentoInit(){
55
document.title = "Crear nuevo documento";
6-
document.getElementById('slugTitle').innerHTML = '<h2 class="text-xl font-semibold mb-4">Crear Nuevo Documento</h2>';
6+
document.getElementById('slugTitle').innerHTML = '<h2 class="text-xl font-semibold mb-4">Crear nuevo documento</h2>';
77

88
getDepartmentTagsCND();
99
getUserEmalCND();
@@ -37,7 +37,7 @@ function saveDocCND(){
3737
body: formData,
3838
headers: {'Authorization': 'Bearer ' + (window.localStorage.getItem('token') || 'xxx')}
3939
}).then(res => res.json()).then(res => {
40-
if (res && res.data && res.data.error == 'no' && res.data.id > 0) { console.log(res.data)
40+
if (res && res.data && res.data.error == 'no' && res.data.id > 0) {
4141
showM('Documento guardado correctamente ✅', 'success');
4242
setTimeout(() => { window.location.href = '/dashboard/#ver-detalle-documento?doc_id='+res.data.id; }, 1000);
4343
} else {

assets/views/documentos-listado-general.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let oldTagsIdsDLG = '';
1010

1111
function documentosListadoGeneralInit(){
1212
document.title = "Filtrar documentos";
13-
document.getElementById('slugTitle').innerHTML = '<h2 class="text-xl font-semibold mb-4"><span class="searchDLG" onclick="closeOpenFilterDLG()">🔎</span> Listado Documentos</h2>';
13+
document.getElementById('slugTitle').innerHTML = '<h2 class="text-xl font-semibold mb-4"><span class="searchDLG" onclick="closeOpenFilterDLG()">🔎</span> Listado documentos</h2>';
1414

1515
getDocDLG();
1616
getSetFromDLG();

assets/views/editar-borrar-documento.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<iframe src="" width="322px" height="350px" style="border:none; display: none;" id="iframeEBD"></iframe>
2-
<br>
1+
<div id="iframeContainerEBD" class="flex flex-wrap gap-4 justify-start mb-6"></div>
2+
33
<div class="p-4 bg-white shadow-md rounded-md">
44
<div class="space-y-4">
55
<div>
6-
<label class="block text-sm font-medium mb-1">Nombre archivo</label>
7-
<a id="file_name_edb" class="w-full rounded px-2 py-1 link_id_dlg" onclick="showPrevieEBD()"></a>
6+
<label class="block text-sm font-medium mb-1">Archivos</label>
7+
<div id="link_files_ebd"></div>
88
</div>
99

1010
<div>
@@ -40,7 +40,7 @@ <h3 class="block text-sm font-medium mb-1">Etiquetas seleccionadas:</h3>
4040
</div>
4141

4242
<div class="flex justify-end gap-3 pt-4">
43-
<button onclick="saveDocEBD()" type="button" class="bluecol">Guardar</button>
43+
<button onclick="updateEBD()" type="button" class="bluecol">Actualizar</button>
4444
</div>
4545
</div>
4646
</div>
@@ -52,3 +52,5 @@ <h3 class="text-sm font-semibold mb-1">Etiquetas disponibles:</h3>
5252
</div>
5353
</div>
5454

55+
56+
<br><br><br><br><br><br><br>

assets/views/editar-borrar-documento.js

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
let docIdEBD = 0;
22
let idsSetedEBD = new Set();
33
let dataSetedEBD = new Set();
4-
let fileCodeEBD = '';
54

65
function editarBorrarDocumentoInit(){
7-
document.title = "Editar/Borrar Documento";
8-
document.getElementById('slugTitle').innerHTML = '<h2 class="text-xl font-semibold mb-4">Editar/Borrar Documento</h2>';
9-
10-
initPageEBD();
11-
}
12-
13-
function initPageEBD(){
146
let pageRoute = parseHashRoute();
157
docIdEBD = pageRoute.params.doc_id;
168

17-
getDepartmentTagsCND();
18-
getDocumentById();
9+
document.title = "Editar/borrar documento";
10+
document.getElementById('slugTitle').innerHTML = '<h2 class="text-xl font-semibold mb-4">Editar/borrar documento</h2>';
11+
12+
getDepartmentTagsEBD();
13+
getDocumentByIdEBD();
1914
}
2015

2116
function paintDocEBD(doc){
22-
document.getElementById('file_name_edb').innerHTML = doc.file_name;
2317
document.getElementById('doc_title_edb').value = doc.title;
18+
document.getElementById('slugTitle').innerHTML = `<h2 class="text-xl font-semibold mb-4">Editar/borrar ${doc.title}</h2>`;
2419
document.getElementById('doc_description_edb').value = doc.descrption;
2520
document.getElementById('doc_date_edb').value = doc.expiration_date;
2621
document.getElementById('email_aviso_edb').value = doc.notification_emails;
2722
}
2823

29-
function paintTagsEBD(tags){
30-
if(tags && tags.length > 0){ // console.log(tags)
24+
function paintDocTagsEBD(tags){
25+
if(tags && tags.length > 0){
3126
for(let i = 0; i < tags.length; i++){
3227
if (idsSetedEBD.has(tags[i].tag_id)){ continue; }
3328
idsSetedEBD.add(tags[i].tag_id);
@@ -37,20 +32,25 @@ function paintTagsEBD(tags){
3732
}
3833
}
3934

40-
function getDocumentById(){
41-
onlyGet('public/doc/get/doc_by_id/?doc_id='+docIdEBD, (r) => {
35+
function getDocumentByIdEBD(){
36+
onlyGet('public/doc/get/doc_by_id/?doc_id='+docIdEBD+'&user_id='+window.localStorage.getItem('user_id'), (r) => {
37+
console.log(r.data)
38+
/*
39+
I only allow the user who created the document to edit it
40+
Solo permito que el usuario que creó el documento lo edite,
41+
quizas habria que hacer desde el usuario que tiene action_pass
42+
*/
4243
if(r && r.data && r.data.doc && r.data.doc && r.data.doc.user_id == window.localStorage.getItem('user_id')){
43-
fileCodeEBD = r.data.doc.code;
4444
paintDocEBD(r.data.doc);
45-
paintTagsEBD(r.data.tags);
46-
showInframeEBD(r.data.doc.file_name, r.data.doc.code);
45+
paintDocTagsEBD(r.data.doc_tags);
46+
showInframeEBD(r.data.doc_lines);
4747
} else {
4848
showM('No hay suficientes permisos..', 'warning')
4949
}
5050
});
5151
}
5252

53-
function getDepartmentTagsCND(){
53+
function getDepartmentTagsEBD(){
5454
suzdalenkoGet('documentor/tag/get/get_department_tags/', function(response){
5555
if(response && response.data && response.data){
5656
document.getElementById('tagsListEBD').innerHTML = '';
@@ -89,13 +89,58 @@ function showTagsInDocEBD(){
8989
document.getElementById('selectedTagsEDB').innerHTML = htmlTagsEDB;
9090
}
9191

92-
function showPrevieEBD(){
93-
window.open(HTTP_HOST+'public/doc/get/serve_document/?code='+fileCodeEBD, '_blank');
92+
function showInframeEBD(doc_tags){
93+
let fileNames = '';
94+
let framesHtml = '';
95+
doc_tags.map(l => {
96+
let url = HTTP_HOST + 'public/doc/get/serve_document/?code='+l.code;
97+
let url2 = HTTP_HOST + 'public/doc/get/serve_document/?code='+l.code;
98+
if(!l.file_name.includes('.pdf')){ url = 'https://suzdalenko-dev.github.io/html-documentor/assets/img/template.png'; }
99+
framesHtml += `<div>
100+
<iframe src="${url}" class="doc-preview"></iframe>
101+
<div class="doc-actions"><button class="btn-view" onclick="window.open('${url2}', '_blank')">👁️ Ver </button></div>
102+
</div>`;
103+
fileNames += `<a href="${url2}" target="_blank" class="link_id_dlg ml-3"> ${l.file_name} </a>`;
104+
});
105+
document.getElementById('link_files_ebd').innerHTML = fileNames;
106+
document.getElementById('iframeContainerEBD').innerHTML = framesHtml;
94107
}
95108

96-
function showInframeEBD(fileName, code){
97-
if (fileName.includes(".pdf")) {
98-
document.getElementById('iframeEBD').style.display = 'block';
99-
document.getElementById('iframeEBD').src = HTTP_HOST+'public/doc/get/serve_document/?code='+fileCodeEBD;
109+
/* UPDATE BUTTON */
110+
function updateEBD(){
111+
let title = document.getElementById('doc_title_edb').value.trim();
112+
let description = document.getElementById('doc_description_edb').value.trim();
113+
let expiration_date = document.getElementById('doc_date_edb').value;
114+
let email_aviso = document.getElementById('email_aviso_edb').value.trim();
115+
let fileInput = document.getElementById('doc_file_edb');
116+
let files = fileInput.files;
117+
let tags = Array.from(dataSetedEBD).map(tag => tag.id).join(',');
118+
119+
if(!title || !expiration_date || !email_aviso){
120+
showM('Por favor, completa todos los campos del formulario.', 'warning');
121+
return;
100122
}
123+
let formData = new FormData();
124+
formData.append('doc_id', docIdEBD)
125+
formData.append('title', title);
126+
formData.append('description', description);
127+
formData.append('expiration_date', expiration_date);
128+
formData.append('email_aviso', email_aviso);
129+
formData.append('tags', tags);
130+
131+
// 🔹 Añadir cada archivo al FormData
132+
for (let i = 0; i < files.length; i++) { formData.append('files', files[i]); }
133+
134+
fetch(HTTP_HOST + 'documentor/doc/post/update_old_doc/', {
135+
method: 'POST',
136+
body: formData,
137+
headers: {'Authorization': 'Bearer ' + (window.localStorage.getItem('token') || 'xxx')}
138+
}).then(res => res.json()).then(res => {
139+
if (res && res.data && res.data.error == 'no' && res.data.id > 0) {
140+
showM('Documento guardado correctamente ✅', 'success');
141+
setTimeout(() => { window.location.href = '/dashboard/#ver-detalle-documento?doc_id='+res.data.id; }, 1000);
142+
} else {
143+
showM('Error al guardar: ' + (res.message || 'Error desconocido'), 'error');
144+
}
145+
}).catch(err => showM('Error de conexión: ' + err, 'error'));
101146
}

assets/views/ver-detalle-documento.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="p-4 bg-white shadow-md rounded-md">
44
<div class="space-y-4">
55
<div>
6-
<label class="block text-sm font-medium mb-1">Nombres archivos</label>
6+
<label class="block text-sm font-medium mb-1">Archivos</label>
77
<div id="file_links_vdd"></div>
88
</div>
99

assets/views/ver-detalle-documento.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ function verDetalleDocumentoInit(){
99

1010
function getFilesVDD(docId){
1111
onlyGet('public/doc/get/doc_by_id/?doc_id='+docId+'&user_id='+window.localStorage.getItem('user_id'), (r) => {
12-
if(r && r.data && r.data.error == 'no'){ console.log(r.data)
13-
// https://suzdalenko-dev.github.io/html-documentor/assets/img/template.png
12+
if(r && r.data && r.data.error == 'no'){
1413
let fileNames = '';
1514
if(r.data.doc_lines && r.data.doc_lines.length > 0){
1615
let framesHtml = '';
17-
r.data.doc_lines.map(l => { console.log(l.file_name)
18-
let url = HTTP_HOST + 'public/doc/get/serve_document/?code='+l.code;
16+
r.data.doc_lines.map(l => {
17+
let url = HTTP_HOST + 'public/doc/get/serve_document/?code='+l.code;
18+
let url2 = HTTP_HOST + 'public/doc/get/serve_document/?code='+l.code;
1919
if(!l.file_name.includes('.pdf')){ url = 'https://suzdalenko-dev.github.io/html-documentor/assets/img/template.png'; }
2020
framesHtml += `<div>
2121
<iframe src="${url}" class="doc-preview"></iframe>
22-
<div class="doc-actions"><button class="btn-view" onclick="window.open('${url}', '_blank')">👁️ Ver </button></div>
22+
<div class="doc-actions"><button class="btn-view" onclick="window.open('${url2}', '_blank')">👁️ Ver </button></div>
2323
</div>`;
24-
fileNames += `<a href="${url}" target="_blank" class="link_id_dlg ml-3"> ${l.file_name} </a>`;
24+
fileNames += `<a href="${url2}" target="_blank" class="link_id_dlg ml-3"> ${l.file_name} </a>`;
2525
});
2626
document.getElementById('iframeContainerVDD').innerHTML = framesHtml;
2727
}
@@ -42,6 +42,5 @@ function getFilesVDD(docId){
4242
showM('Error desconocido', 'error');
4343
}
4444
}
45-
4645
});
4746
}

0 commit comments

Comments
 (0)