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

@ -29,7 +29,7 @@ class Home {
$avisos = json_decode(trim(file_get_contents($filename))); $avisos = json_decode(trim(file_get_contents($filename)));
if (isset($post['estado'])) { if (isset($post['estado'])) {
$avisos->activo = (bool) $post['estado']; $avisos->activo = ($post['estado'] !== 'false');
} else { } else {
$aviso = (object) [ $aviso = (object) [
'titulo' => '', 'titulo' => '',

View File

@ -41,24 +41,25 @@
@push('scripts') @push('scripts')
<script type="text/javascript"> <script type="text/javascript">
var edit = false var faq = {
var faqs = [ edit: false,
faqs: [
@foreach ($faqs as $faq) @foreach ($faqs as $faq)
{ {
titulo: '{{$faq->titulo}}', titulo: '{{$faq->titulo}}',
contenido: '{{$faq->contenido}}' contenido: '{{$faq->contenido}}'
}, },
@endforeach @endforeach
] ],
$(document).ready(() => { setup: () => {
$('.titulo').css('cursor', 'pointer').click(function() { $('.titulo').css('cursor', 'pointer').click(function() {
var id = $(this).attr('data-id') var id = $(this).attr('data-id')
$("input[name='id']").val(id) $("input[name='id']").val(id)
$("input[name='titulo']").val(faqs[id].titulo) $("input[name='titulo']").val(faq.faqs[id].titulo)
$("textarea[name='contenido']").val(faqs[id].contenido) $("textarea[name='contenido']").val(faq.faqs[id].contenido)
$('.button.enviar').html('EDITAR') $('.button.enviar').html('EDITAR')
edit = true faq.edit = true
}) })
$('.trash.icon').css('cursor', 'pointer').click(function() { $('.trash.icon').css('cursor', 'pointer').click(function() {
var id = $(this).attr('data-id') var id = $(this).attr('data-id')
@ -72,7 +73,7 @@
$('.button.resetear').click(() => { $('.button.resetear').click(() => {
$("input[name='id']").val('') $("input[name='id']").val('')
$('.button.enviar').html('AGREGAR') $('.button.enviar').html('AGREGAR')
edit = false faq.edit = false
}) })
$('.form').trigger('reset') $('.form').trigger('reset')
$('.form').submit((e) => { $('.form').submit((e) => {
@ -92,6 +93,10 @@
}) })
return false return false
}) })
}
}
$(document).ready(() => {
faq.setup()
}) })
</script> </script>
@endpush @endpush

View File

@ -81,24 +81,25 @@
@push('scripts') @push('scripts')
<script type="text/javascript"> <script type="text/javascript">
var edit = false var home = {
function editAviso(id) { edit: false,
editAviso: (id) => {
var titulo = $(".link.titulo[data-id='" + id + "']").html() var titulo = $(".link.titulo[data-id='" + id + "']").html()
var contenido = $(".link.contenido[data-id='" + id + "']").html() var contenido = $(".link.contenido[data-id='" + id + "']").html()
$("input[name='id']").val(id) $("input[name='id']").val(id)
$("input[name='titulo']").val(titulo) $("input[name='titulo']").val(titulo)
$("input[name='contenido']").val(contenido) $("input[name='contenido']").val(contenido)
edit = true home.edit = true
$('.accion').html('EDITAR') $('.accion').html('EDITAR')
} },
function submitAviso(e) { submitAviso: (e) => {
e.preventDefault() e.preventDefault()
input = { input = {
titulo: $("input[name='titulo']").val(), titulo: $("input[name='titulo']").val(),
contenido: $("input[name='contenido']").val() contenido: $("input[name='contenido']").val()
} }
if (edit) { if (home.edit) {
input['id'] = $("input[name='id']").val() input['id'] = $("input[name='id']").val()
} }
if (input['titulo'] == '') { if (input['titulo'] == '') {
@ -111,32 +112,32 @@
} }
}, 'json') }, 'json')
return false return false
} },
function deleteAviso(id) { deleteAviso: (id) => {
var url = '{{$urls->admin}}/home/avisos/delete' var url = '{{$urls->admin}}/home/avisos/delete'
$.post(url, {id: id}, (data) => { $.post(url, {id: id}, (data) => {
if (data.estado) { if (data.estado) {
window.location.reload() window.location.reload()
} }
}, 'json') }, 'json')
} },
$(document).ready(() => { setup: () => {
$('.link').css('cursor', 'pointer').click(function() { $('.link').css('cursor', 'pointer').click(function() {
var id = $(this).attr('data-id') var id = $(this).attr('data-id')
editAviso(id) home.editAviso(id)
}) })
$('#avisos').trigger('reset') $('#avisos').trigger('reset')
$('#avisos').submit((e) => { $('#avisos').submit((e) => {
submitAviso(e) home.submitAviso(e)
}) })
$(".button[type='reset']").click((e) => { $(".button[type='reset']").click((e) => {
$("input[name='id']").val('') $("input[name='id']").val('')
$('.accion').html('CREAR') $('.accion').html('CREAR')
edit = false home.edit = false
}) })
$('.trash.icon').css('cursor', 'pointer').click(function() { $('.trash.icon').css('cursor', 'pointer').click(function() {
var id = $(this).attr('data-id') var id = $(this).attr('data-id')
deleteAviso(id) home.deleteAviso(id)
}) })
$('.checkbox').checkbox({ $('.checkbox').checkbox({
onChange: function() { onChange: function() {
@ -168,6 +169,10 @@
} }
}) })
}) })
}
}
$(document).ready(() => {
home.setup()
}) })
</script> </script>
@endpush @endpush

View File

@ -153,27 +153,13 @@
@push('scripts') @push('scripts')
<script type="text/javascript"> <script type="text/javascript">
var months = { var producto = {
months: {
long: [], long: [],
short: [] short: []
} },
var date = new Date(2018, 0, 1) date: new Date(2018, 0, 1),
for (i = 0; i < 12; i ++) { listImage: (image) => {
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') var icon = $('<i></i>').attr('class', 'trash alternate outline icon')
icon.css('cursor', 'pointer').click(function() { icon.css('cursor', 'pointer').click(function() {
var url = '{{$urls->admin}}/producto/{{$producto->id}}/imagen/delete' var url = '{{$urls->admin}}/producto/{{$producto->id}}/imagen/delete'
@ -190,15 +176,33 @@
$('<div></div>').attr('class', 'content').html(image) $('<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();
} }
$(document).ready(() => { ))
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()
$('.selection.dropdown').dropdown('set selected', '{{$producto->segmento}}') $('.selection.dropdown').dropdown('set selected', '{{$producto->segmento}}')
$('.calendar').calendar({ $('.calendar').calendar({
type: 'month', type: 'month',
text: { text: {
months: months.long, months: producto.months.long,
monthsShort: months.short monthsShort: producto.months.short
}, },
formatInput: false, formatInput: false,
onChange: function(a, b) { onChange: function(a, b) {
@ -232,7 +236,7 @@
}) })
}) })
@foreach ($producto->imagenes() as $image) @foreach ($producto->imagenes() as $image)
listImage('{{$image}}') producto.listImage('{{$image}}')
@endforeach @endforeach
$("input[name='video']").change(function() { $("input[name='video']").change(function() {
var fData = new FormData() var fData = new FormData()
@ -259,6 +263,10 @@
} }
}) })
}) })
}
}
$(document).ready(() => {
producto.setup()
}) })
</script> </script>
@endpush @endpush

View File

@ -127,27 +127,31 @@
@push('scripts') @push('scripts')
<script type="text/javascript"> <script type="text/javascript">
var months = { var producto = {
months: {
long: [], long: [],
short: [] short: []
} },
var date = new Date(2018, 0, 1) date: new Date(2018, 0, 1),
setMonths: () => {
for (i = 0; i < 12; i ++) { for (i = 0; i < 12; i ++) {
date.setMonth(i) producto.date.setMonth(i)
months.long.push(date.toLocaleString('es-ES', {month: "long"}).replace( producto.months.long.push(producto.date.toLocaleString('es-ES', {month: "long"}).replace(
/\w\S*/g, /\w\S*/g,
function(txt) { function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
} }
)) ))
months.short.push(date.toLocaleString('es-ES', {month: "short"}).replace( producto.months.short.push(producto.date.toLocaleString('es-ES', {month: "short"}).replace(
/\w\S*/g, /\w\S*/g,
function(txt) { function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
} }
)) ))
} }
$(document).ready(() => { },
setup: () => {
producto.setMonths()
$('.selection.dropdown').dropdown() $('.selection.dropdown').dropdown()
$('.calendar').calendar({ $('.calendar').calendar({
type: 'month', type: 'month',
@ -161,6 +165,10 @@
} }
}) })
$('.checkbox').checkbox() $('.checkbox').checkbox()
}
}
$(document).ready(() => {
producto.setup()
}) })
</script> </script>
@endpush @endpush

View File

@ -28,17 +28,22 @@
@push('scripts') @push('scripts')
<script type="text/javascript"> <script type="text/javascript">
var max_width = 0 var resumen = {
$(document).ready(function() { max_width: 0,
setup: () => {
$('#resumen .circular.segment').each(function(i, el) { $('#resumen .circular.segment').each(function(i, el) {
var width = $(this).css('width') var width = $(this).css('width')
var w = parseInt(width) var w = parseInt(width)
if (w > max_width) { if (w > resumen.max_width) {
max_width = w resumen.max_width = w
} }
$(this).css('width', max_width + 'px') $(this).css('width', resumen.max_width + 'px')
$(this).css('height', max_width + 'px') $(this).css('height', resumen.max_width + 'px')
}) })
}
}
$(document).ready(function() {
resumen.setup()
}) })
</script> </script>
@endpush @endpush

View File

@ -34,14 +34,17 @@
@push('scripts') @push('scripts')
<script type="text/javascript"> <script type="text/javascript">
var loaded = { var productos = {
id: '#productos',
current_hash: '',
loaded: {
todo: false, todo: false,
@foreach ($segmentos as $segmento) @foreach ($segmentos as $segmento)
'{{mb_strtolower($segmento->titulo)}}': false, '{{mb_strtolower($segmento->titulo)}}': false,
@endforeach @endforeach
} },
function loadSegmento(segmento) { loadSegmento: (segmento) => {
if (loaded[segmento]) { if (productos.loaded[segmento]) {
return return
} }
var name = segmento var name = segmento
@ -50,7 +53,7 @@
} }
var url = '{{$urls->base}}/productos/segmento/' + name var url = '{{$urls->base}}/productos/segmento/' + name
$(".tab[data-tab='" + segmento + "']").find('.grid').html('') $(".tab[data-tab='" + segmento + "']").find('.grid').html('')
loaded[segmento] = true productos.loaded[segmento] = true
$.getJSON(url, (data) => { $.getJSON(url, (data) => {
$(".tab[data-tab='" + segmento + "']").find('.grid').append( $(".tab[data-tab='" + segmento + "']").find('.grid').append(
$('<div></div>').attr('class', 'ui active centered inline loader') $('<div></div>').attr('class', 'ui active centered inline loader')
@ -60,11 +63,11 @@
return return
} }
$.each(data.productos, (i, el) => { $.each(data.productos, (i, el) => {
getProducto(segmento, el) productos.getProducto(segmento, el)
}) })
}) })
} },
function getProducto(segmento, id_producto) { getProducto: (segmento, id_producto) => {
var url = '{{$urls->base}}/producto/' + id_producto + '/ficha' var url = '{{$urls->base}}/producto/' + id_producto + '/ficha'
$.ajax({ $.ajax({
url: url, url: url,
@ -77,21 +80,38 @@
) )
} }
}) })
} },
$(document).ready(() => { setup: () => {
loadSegmento('todo') productos.loadSegmento('todo')
$('#productos').find('.tabular.menu .item').tab({ $(productos.id).find('.tabular.menu .item').tab({
onFirstLoad: (tabPath, parameterArray, historyEvent) => { onFirstLoad: (tabPath, parameterArray, historyEvent) => {
if (tabPath == 'todo') { if (tabPath == 'todo') {
return return
} }
loadSegmento(tabPath) productos.loadSegmento(tabPath)
} }
}) })
$('#productos_menu').find('.menu .item').click(function() {
productos.getHash($(this).attr('href').split('#')[1])
})
if (window.location.hash) { if (window.location.hash) {
var start = (window.location.hash).replace('#', '').replace('%20', ' ') productos.getHash(window.location.hash)
$('#productos').find('.tabular.menu .item').tab('change tab', start)
} }
},
getHash: (hash) => {
if (typeof hash == 'undefined') {
hash = window.location.hash
}
var start = (hash).replace('#', '').replace('%20', ' ')
if (productos.current_hash == start) {
return
}
productos.current_hash = start
$(productos.id).find('.tabular.menu .item').tab('change tab', start)
}
}
$(document).ready(() => {
productos.setup()
}) })
</script> </script>
@endpush @endpush

View File

@ -30,15 +30,38 @@
@push('scripts') @push('scripts')
<script type="text/javascript"> <script type="text/javascript">
function changePrice(min, max) { var buscar = {
min: 1000,
max: 30000,
changePrice: (min, max) => {
$("input[name='precio']").val(min + '-' + max)
formatter = new Intl.NumberFormat('de-DE')
$('.price_label').html(formatter.format(min) + ' - ' + formatter.format(max) + ' UF')
},
setup: () => {
buscar.changePrice(buscar.min, buscar.max)
$('#precio').slider({
min: buscar.min,
max: buscar.max,
start: buscar.min,
end: buscar.max,
step: 500,
onChange: (range, min, max) => {
buscar.changePrice(min, max)
}
})
}
}
/*function changePrice(min, max) {
$("input[name='precio']").val(min + '-' + max) $("input[name='precio']").val(min + '-' + max)
formatter = new Intl.NumberFormat('de-DE') formatter = new Intl.NumberFormat('de-DE')
$('.price_label').html(formatter.format(min) + ' - ' + formatter.format(max) + ' UF') $('.price_label').html(formatter.format(min) + ' - ' + formatter.format(max) + ' UF')
} }
var gMin = 1000 var gMin = 1000
var gMax = 30000 var gMax = 30000*/
$(document).ready(() => { $(document).ready(() => {
changePrice(gMin, gMax) buscar.setup()
/*changePrice(gMin, gMax)
$('#precio').slider({ $('#precio').slider({
min: gMin, min: gMin,
max: gMax, max: gMax,
@ -48,7 +71,7 @@
onChange: (range, min, max) => { onChange: (range, min, max) => {
changePrice(min, max) changePrice(min, max)
} }
}) })*/
}) })
</script> </script>
@endpush @endpush

View File

@ -20,15 +20,16 @@
@push('scripts') @push('scripts')
<script type="text/javascript"> <script type="text/javascript">
var images = [ var galeria = {
images: [
@foreach ($producto->imagenes() as $image) @foreach ($producto->imagenes() as $image)
'{{$urls->images}}/{{mb_strtolower($producto->nombre)}}/{{$image}}', '{{$urls->images}}/{{mb_strtolower($producto->nombre)}}/{{$image}}',
@endforeach @endforeach
] ],
function populateThumbs(current) { populateThumbs: (current) => {
var thumbs = $('#thumbnails') var thumbs = $('#thumbnails')
thumbs.html('') thumbs.html('')
$.each(images, (i, el) => { $.each(galeria.images, (i, el) => {
if (i == current) { if (i == current) {
return return
} }
@ -42,27 +43,24 @@
}) })
$('#galeria').find('.grid .image').click(function(e) { $('#galeria').find('.grid .image').click(function(e) {
var id = $(this).attr('data-id') var id = $(this).attr('data-id')
changeImage(id) galeria.changeImage(id)
}) })
} },
function changeImage(id) { changeImage: (id) => {
var big = $('#galeria>.image') var big = $('#galeria>.image')
big.find('img').attr('src', images[id]) big.find('img').attr('src', images[id])
big.attr('data-id', id) big.attr('data-id', id)
populateThumbs(id) galeria.populateThumbs(id)
} },
$(document).ready(() => { setup: () => {
$('#galeria').find('.grid .image').click(function(e) { $('#galeria').find('.grid .image').click(function(e) {
var id = $(this).attr('data-id') var id = $(this).attr('data-id')
changeImage(id) galeria.changeImage(id)
/*var big = $('#galeria>.image')
var big_id = big.attr('data-id')
big.find('img').attr('src', images[id])
big.attr('data-id', id)
$(this).find('img').attr('src', images[big_id])
$(this).attr('data-id', big_id)
populateThumbs(id)*/
}) })
}
}
$(document).ready(() => {
galeria.setup()
}) })
</script> </script>
@endpush @endpush