Orden de js y FIX: cambio a estado avisos

This commit is contained in:
2020-05-31 13:31:23 -04:00
parent 84e6808883
commit 2d2eccb600
9 changed files with 435 additions and 363 deletions

View File

@ -153,112 +153,120 @@
@push('scripts')
<script type="text/javascript">
var months = {
long: [],
short: []
}
var date = new Date(2018, 0, 1)
for (i = 0; i < 12; i ++) {
date.setMonth(i)
months.long.push(date.toLocaleString('es-ES', {month: "long"}).replace(
/\w\S*/g,
function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}
))
months.short.push(date.toLocaleString('es-ES', {month: "short"}).replace(
/\w\S*/g,
function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}
))
}
function listImage(image) {
var icon = $('<i></i>').attr('class', 'trash alternate outline icon')
icon.css('cursor', 'pointer').click(function() {
var url = '{{$urls->admin}}/producto/{{$producto->id}}/imagen/delete'
$.post(url, {imagen: image}, (data) => {
if (data.estado) {
window.location.reload()
var producto = {
months: {
long: [],
short: []
},
date: new Date(2018, 0, 1),
listImage: (image) => {
var icon = $('<i></i>').attr('class', 'trash alternate outline icon')
icon.css('cursor', 'pointer').click(function() {
var url = '{{$urls->admin}}/producto/{{$producto->id}}/imagen/delete'
$.post(url, {imagen: image}, (data) => {
if (data.estado) {
window.location.reload()
}
})
})
$('#imagenes').append(
$('<div></div>').attr('class', 'item').append(
icon
).append(
$('<div></div>').attr('class', 'content').html(image)
)
)
},
setMonths: () => {
for (i = 0; i < 12; i ++) {
producto.date.setMonth(i)
producto.months.long.push(producto.date.toLocaleString('es-ES', {month: "long"}).replace(
/\w\S*/g,
function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}
))
producto.months.short.push(producto.date.toLocaleString('es-ES', {month: "short"}).replace(
/\w\S*/g,
function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}
))
}
},
setup: () => {
producto.setMonths()
$('.selection.dropdown').dropdown()
$('.selection.dropdown').dropdown('set selected', '{{$producto->segmento}}')
$('.calendar').calendar({
type: 'month',
text: {
months: producto.months.long,
monthsShort: producto.months.short
},
formatInput: false,
onChange: function(a, b) {
if (typeof a == 'undefined') {
a = new Date()
}
$(this).find('input').val(('0' + (a.getMonth() + 1)).slice(-2) + '/' + a.getFullYear())
}
})
})
$('#imagenes').append(
$('<div></div>').attr('class', 'item').append(
icon
).append(
$('<div></div>').attr('class', 'content').html(image)
)
)
var entrega = new Date('{{str_pad(implode('-', array_reverse(explode('/', $producto->entrega))), 7, '20', STR_PAD_LEFT)}}-01T01:00')
$('.calendar').calendar('set date', entrega)
$('.checkbox').checkbox()
@if ($producto->destacado())
$('.checkbox').checkbox('set checked')
@endif
$("input[name='imagen']").change(function() {
var data = new FormData()
data.append('imagen', $(this)[0].files[0])
var url = '{{$urls->admin}}/producto/{{$producto->id}}/imagenes/add'
$.ajax({
url: url,
method: 'post',
data: data,
contentType: false,
processData: false,
success: (data) => {
if (data.estado) {
window.location.reload()
}
}
})
})
@foreach ($producto->imagenes() as $image)
producto.listImage('{{$image}}')
@endforeach
$("input[name='video']").change(function() {
var fData = new FormData()
fData.append('video', $("input[name='video']")[0].files[0])
var url = '{{$urls->admin}}/producto/{{$producto->id}}/video/set'
$.ajax({
url: url,
method: 'post',
data: fData,
contentType: false,
processData: false,
success: (data) => {
if (data.estado) {
window.location.reload()
}
}
})
})
$('.trash.video').attr('cursor', 'pointer').click(() => {
var url = '{{$urls->admin}}/producto/{{$producto->id}}/video/delete'
$.post(url, {}, (data) => {
if (data.estado) {
window.location.reload()
}
})
})
}
}
$(document).ready(() => {
$('.selection.dropdown').dropdown()
$('.selection.dropdown').dropdown('set selected', '{{$producto->segmento}}')
$('.calendar').calendar({
type: 'month',
text: {
months: months.long,
monthsShort: months.short
},
formatInput: false,
onChange: function(a, b) {
if (typeof a == 'undefined') {
a = new Date()
}
$(this).find('input').val(('0' + (a.getMonth() + 1)).slice(-2) + '/' + a.getFullYear())
}
})
var entrega = new Date('{{str_pad(implode('-', array_reverse(explode('/', $producto->entrega))), 7, '20', STR_PAD_LEFT)}}-01T01:00')
$('.calendar').calendar('set date', entrega)
$('.checkbox').checkbox()
@if ($producto->destacado())
$('.checkbox').checkbox('set checked')
@endif
$("input[name='imagen']").change(function() {
var data = new FormData()
data.append('imagen', $(this)[0].files[0])
var url = '{{$urls->admin}}/producto/{{$producto->id}}/imagenes/add'
$.ajax({
url: url,
method: 'post',
data: data,
contentType: false,
processData: false,
success: (data) => {
if (data.estado) {
window.location.reload()
}
}
})
})
@foreach ($producto->imagenes() as $image)
listImage('{{$image}}')
@endforeach
$("input[name='video']").change(function() {
var fData = new FormData()
fData.append('video', $("input[name='video']")[0].files[0])
var url = '{{$urls->admin}}/producto/{{$producto->id}}/video/set'
$.ajax({
url: url,
method: 'post',
data: fData,
contentType: false,
processData: false,
success: (data) => {
if (data.estado) {
window.location.reload()
}
}
})
})
$('.trash.video').attr('cursor', 'pointer').click(() => {
var url = '{{$urls->admin}}/producto/{{$producto->id}}/video/delete'
$.post(url, {}, (data) => {
if (data.estado) {
window.location.reload()
}
})
})
producto.setup()
})
</script>
@endpush