FIX: no se podia subir los videos

This commit is contained in:
2020-06-18 02:16:32 -04:00
parent 0f26b53546
commit ef453fef56
9 changed files with 317 additions and 79 deletions

View File

@ -42,7 +42,7 @@ var imagenes = {
$('#agregar_imagen').css('cursor', 'pointer').click(() => {
imagenes.add()
})
$('.trash.icon').css('cursor', 'pointer').click(function() {
$('#imagenes .trash.icon').css('cursor', 'pointer').click(function() {
let i = $(this).attr('data-media')
imagenes.deleteImage(i)
})
@ -80,11 +80,11 @@ var imagenes = {
div = $('<div></div>').attr('class', 'ui modal').append(
$('<i></i>').attr('class', 'inside close icon')
)
if (imagenes.imagenes.length >= 12) {
if (imagenes.imagenes.length + videos.videos.length >= 12) {
div.append(
$('<div></div>').attr('class', 'header').html('Media')
$('<div></div>').attr('class', 'header').html('Foto')
).append(
$('<div></div>').attr('class', 'content').html('Se ha llegado al máximo de media.')
$('<div></div>').attr('class', 'content').html('Se ha llegado al máximo de elementos.')
)
imgs.after(div)
div.modal('show')
@ -92,7 +92,7 @@ var imagenes = {
}
div.append(
$('<div></div>').attr('class', 'header').html('Media')
$('<div></div>').attr('class', 'header').html('Foto')
).append(
$('<div></div>').attr('class', 'content').append(imagenes.buildForm())
)
@ -108,6 +108,129 @@ var imagenes = {
})
},
addImage: () => {
let form = $('#add_image')
$('#add_image #resultado').html('')
$('#add_image #resultado').append(
$('<div></div>').attr('class', 'ui active loader')
)
let data = new FormData(form[0])
let url = imagenes.url + '/evento/' + imagenes.evento + '/image/add'
let fallo = () => {
$('#add_image #resultado').html('')
$('#add_image #resultado').append(
$('<div></div>').attr('class', 'ui negative message')
.append($('<i></i>').attr('class', 'inline close icon'))
.append('<p>No se pudo agregar.</p>')
)
$('#add_image #resultado .message .close').on('click', function() {
$(this).closest('.message')
.transition('fade');
});
}
$.ajax({
url: url,
data: data,
processData: false,
contentType: false,
type: 'POST',
success: (output) => {
if (output.estado) {
window.location.reload()
return
}
fallo()
},
error: () => {
fallo()
}
})
},
deleteImage: (i) => {
let media = imagenes.imagenes[i]
let url = imagenes.url + '/evento/' + imagenes.evento + '/image/delete'
$.post(url, {media: media}, (output) => {
if (output.estado) {
window.location.reload()
}
})
}
}
var videos = {
videos: [],
url: '',
evento: '',
setup: () => {
$('#agregar_video').css('cursor', 'pointer').click(() => {
videos.add()
})
$('#videos .trash.icon').css('cursor', 'pointer').click(function() {
let i = $(this).attr('data-media')
videos.deleteVideo(i)
})
},
buildForm: () => {
let form = new Elem('form', {
class: 'ui form',
id: 'add_video',
method: 'post',
enctype: 'multipart/form-data',
action: videos.url + '/evento/' + videos.evento + '/video/add'
}).addChild(
new Elem('div', {class: 'ui grid'}).addChild(
new Elem('div', {class: 'row'}).addChild(
new Elem('div', {class: 'sixteen wide column'}).addChild(
new Elem('div', {class: 'ui fluid input'}).addChild(
new Elem('input', {type: 'file', name: 'video[]', multiple: 'multiple'}, false)
)
)
)
).addChild(
new Elem('div', {class: 'row'}).addChild(
new Elem('div', {class: 'two wide column'}).addChild(
new Elem('div', {class: 'ui fluid button', type: 'submit'}).html('Agregar')
)
)
)
)
return form.build()
},
add: () => {
var vds = $('#videos')
var div = vds.next('.modal')
if (div.length > 0) {
div.remove()
}
div = $('<div></div>').attr('class', 'ui modal').append(
$('<i></i>').attr('class', 'inside close icon')
)
if (imagenes.imagenes.length + videos.videos.length >= 12) {
div.append(
$('<div></div>').attr('class', 'header').html('Video')
).append(
$('<div></div>').attr('class', 'content').html('Se ha llegado al máximo de elementos.')
)
vds.after(div)
div.modal('show')
return
}
div.append(
$('<div></div>').attr('class', 'header').html('Video')
).append(
$('<div></div>').attr('class', 'content').append(videos.buildForm())
)
vds.after(div)
div.modal('show')
div.find('form .button').click((e) => {
div.find('form').submit()
})
/*div.find('form').submit((e) => {
e.preventDefault()
videos.addImage()
return false
})*/
},
/*addImage: () => {
let form = $('#add_image')
$('#resultado').html('')
$('#resultado').append(
@ -144,10 +267,10 @@ var imagenes = {
fallo()
}
})
},
deleteImage: (i) => {
let media = imagenes.imagenes[i]
let url = imagenes.url + '/evento/' + imagenes.evento + '/image/delete'
},*/
deleteVideo: (i) => {
let media = videos.videos[i]
let url = videos.url + '/evento/' + videos.evento + '/video/delete'
$.post(url, {media: media}, (output) => {
if (output.estado) {
window.location.reload()