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)));
if (isset($post['estado'])) {
$avisos->activo = (bool) $post['estado'];
$avisos->activo = ($post['estado'] !== 'false');
} else {
$aviso = (object) [
'titulo' => '',

View File

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

View File

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

View File

@ -153,27 +153,13 @@
@push('scripts')
<script type="text/javascript">
var months = {
var producto = {
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) {
},
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'
@ -190,15 +176,33 @@
$('<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('set selected', '{{$producto->segmento}}')
$('.calendar').calendar({
type: 'month',
text: {
months: months.long,
monthsShort: months.short
months: producto.months.long,
monthsShort: producto.months.short
},
formatInput: false,
onChange: function(a, b) {
@ -232,7 +236,7 @@
})
})
@foreach ($producto->imagenes() as $image)
listImage('{{$image}}')
producto.listImage('{{$image}}')
@endforeach
$("input[name='video']").change(function() {
var fData = new FormData()
@ -259,6 +263,10 @@
}
})
})
}
}
$(document).ready(() => {
producto.setup()
})
</script>
@endpush

View File

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

View File

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

View File

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

View File

@ -30,15 +30,38 @@
@push('scripts')
<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)
formatter = new Intl.NumberFormat('de-DE')
$('.price_label').html(formatter.format(min) + ' - ' + formatter.format(max) + ' UF')
}
var gMin = 1000
var gMax = 30000
var gMax = 30000*/
$(document).ready(() => {
changePrice(gMin, gMax)
buscar.setup()
/*changePrice(gMin, gMax)
$('#precio').slider({
min: gMin,
max: gMax,
@ -48,7 +71,7 @@
onChange: (range, min, max) => {
changePrice(min, max)
}
})
})*/
})
</script>
@endpush

View File

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