Skip to content

Commit

Permalink
Ver y editar participante
Browse files Browse the repository at this point in the history
  • Loading branch information
holisticode committed Sep 7, 2012
1 parent d3be474 commit 1e2760c
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 28 deletions.
32 changes: 28 additions & 4 deletions domain/Participantes.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ function Service(app) {
});
}

function getEquipFromParticipanteId(req, res, next) {
var Equipamiento = app.db.model('Equipamiento');
Equipamiento.findById(req.participante.equipamiento_id, function(err, r) {
req.equipamiento = r;
next();
});
}



/*
* JSON
*/
Expand Down Expand Up @@ -147,13 +157,27 @@ function Service(app) {
});
});

app.get('/participantes/:id', getParticipantes, function(req, res) {
res.render('participante', {
app.get('/participantes/:id/edit', getParticipantes, getEquipFromParticipanteId, function(req, res) {
res.render('view_edit_participante', {
locals: {
participante: req.participante,
equipamiento: req.equipamiento,
params: app.params,
articulo: 'EditarParticipante',
}
});
});

app.get('/participantes/:id', getParticipantes, getEquipFromParticipanteId, function(req, res) {
res.render('view_edit_participante', {
locals: {
participante: req.participante
participante: req.participante,
equipamiento: req.equipamiento,
params: app.params,
articulo: 'VerParticipante',
}
});
});
}

module.exports = Service;
module.exports = Service;
1 change: 1 addition & 0 deletions models/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var Participante = new Schema({
, comuna : { type: String, enum: params.comunas }
, barrio : { type: String, enum: params.barrios }
, estrato : { type: String, enum: params.estratos }
, contacto : { type: String}
, fotos : { type: Array }
, videos : { type: Array }
, familiar : { type: String, enum: params.familiaridades }
Expand Down
47 changes: 37 additions & 10 deletions public/javascripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,30 @@ Paginas.EquipamientoTalleres = function() {
$('#fecha').datepicker();

$el.find('.submit').click(function(e) {
if ($('#fecha').hasClass('border_error')) {
$('#fecha').removeClass('border_error');
}
e.preventDefault();
$(this).blur();

var equip = location.pathname.split('/')[2];
var taller_id = $('select option:selected').val();
var fecha = $('#fecha').val().split('/');
if (fecha) {
fecha = new Date(parseInt(fecha[2]), parseInt(fecha[0].replace(/^0/, '')) - 1, parseInt(fecha[1].replace(/^0/, '')))
fecha = fecha.getTime();
}
var fecha_str = $('#fecha').val();
if (fecha_str) {
var fecha = fecha_str.split('/');
if (fecha) {
fecha = new Date(parseInt(fecha[2]), parseInt(fecha[0].replace(/^0/, '')) - 1, parseInt(fecha[1].replace(/^0/, '')))
fecha = fecha.getTime();
}
}

if (!equip) {
$(this).parent().before("<p class='error'>* debe seleccionar un equipamiento</p>");
}

if (!fecha) {
$(this).parent().before("<p class='error'>* debe seleccionar una fecha</p>");
$('#fecha').addClass('border_error');
}

if (fecha && taller_id) {
Expand Down Expand Up @@ -175,7 +182,7 @@ Paginas.Consultas = function() {
width: $(this).closest('li').width()
});
});
},
};

Paginas.FormEquipamiento = function() {
// Callback par atender el response
Expand All @@ -194,7 +201,7 @@ Paginas.FormEquipamiento = function() {
$.post('/equipamientos', data, res);
}
});
},
};

Paginas.FormTaller = function() {};

Expand Down Expand Up @@ -253,7 +260,27 @@ Paginas.FormCreativo = function() {
$.post('/admin/creativos', data, res);
}
});
},
};

Paginas.EditarParticipante = function() {
var $el = $('#edit_participante');
var participante_id = $('#participante_id').val();
$el.find('button.submit').click(function(e) {
e.preventDefault();
var data = EditarParticipanteForm.getValidData();
if (data) {
$.ajax({
url: '/participantes/' + participante_id,
type: 'PUT',
data: data,
success: function(data) {
console.log(data);
location.href = "/participantes/" + participante_id;
}
});
}
});
};

Paginas.FormEvalTaller = function() {
var $el = $('#taller form');
Expand All @@ -273,7 +300,7 @@ Paginas.FormEvalTaller = function() {
});
}
});
},
};

Paginas.FormParticipante = function() {
var $el = $('#participante form');
Expand Down Expand Up @@ -351,4 +378,4 @@ try {
catch (err) {}


}) // endonready
}) // endonready
15 changes: 6 additions & 9 deletions public/javascripts/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,9 @@ var ParticipanteForm = new FormValidator(
'find': 'input[name=nombre]',
'validate': ['presence']
},
/*
En la presentacion de la app se dijo que fecha de
nacimiento no sea obligatoria
'edad': {
'find': 'input[name=fecha]',
'validate': ['presence','fecha']
},
*/
'fecha': {
'find': 'input[name=fecha]'
},
'comuna': {
'find': 'select[name=comuna] option:selected',
'validate': ['presence']
Expand All @@ -236,7 +231,7 @@ nacimiento no sea obligatoria
'validate': ['presence']
},

'situacion': {
'familiar': {
'find': 'select[name=situacion] option:selected',
'validate': ['presence']
},
Expand All @@ -262,6 +257,8 @@ nacimiento no sea obligatoria
}
);

var EditarParticipanteForm= ParticipanteForm;

var EquipamientoForm = new FormValidator(
$("#equipamiento form"),
{
Expand Down
5 changes: 4 additions & 1 deletion public/javascripts/talleres.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ jQuery(document).ready(function($) {
});

$('#equipamiento .participante_item').click(function(e) {
return false;
window.location = '/participantes/'+this.id;
});
$('#participantes .participante_item').click(function(e) {
window.location = '/participantes/'+this.id;
});

$('#taller .participante_item').click(function(e) {
Expand Down
29 changes: 29 additions & 0 deletions public/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,18 @@ article#taller .list_header a#tab-participantes span.mask,
article#evaluacion .list_header a#tab-participantes span.mask {
width: 124px;
}
article#equipamiento .list_header a#tab-participante,
article#participante .list_header a#tab-participante,
article#taller .list_header a#tab-participante,
article#evaluacion .list_header a#tab-participante {
float: left;
}
article#equipamiento .list_header a#tab-participante span.mask,
article#participante .list_header a#tab-participante span.mask,
article#taller .list_header a#tab-participante span.mask,
article#evaluacion .list_header a#tab-participante span.mask {
width: 100%;
}
article#equipamiento .list_header a#tab-editar,
article#participante .list_header a#tab-editar,
article#taller .list_header a#tab-editar,
Expand Down Expand Up @@ -1081,6 +1093,20 @@ ul#errors {
.error p {
text-align: center;
}
p.error {
color: #f00;
font-size: 0.8em;
padding: 5px;
border-radius: 3px;
background-color: #ffcd97;
display: inline-block;
border: 1px solid;
margin-left: 5px;
}
.border_error {
box-shadow: 0px 0px 5px #f00;
border: 1px solid #f00 !important;
}
p.no_results {
font-size: 0.8em;
padding: 20px;
Expand Down Expand Up @@ -1151,3 +1177,6 @@ article#creativos .creativo_item {
width: 100%;
padding: 10px;
}
.first {
float: left !important;
}
2 changes: 1 addition & 1 deletion views/partials/lista_taller_equip.jade
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ ul
select(name='taller')
each taller in talleres
option(value='#{taller._id}') #{taller.nombre}
input#fecha(type='text')
input#fecha(type='text',placeholder='Seleccionar Fecha')
button.submit Agregar Taller
3 changes: 0 additions & 3 deletions views/participantes.jade
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ article#participantes
a#listar(href="/participantes", class='#{articulo == 'Participantes' ? "activo" : null }')
| Participantes
span.mask
a#crear(href="/participantes/new", class='#{articulo == 'FormParticipante' ? "activo" : null }')
| Crear Participante
span.mask

.list_body
ul.listado
Expand Down
21 changes: 21 additions & 0 deletions views/styles.styl
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ article#evaluacion
span.mask
width: 124px

&#tab-participante
float: left
span.mask
width: 100%

&#tab-editar
float: right
span.mask
Expand Down Expand Up @@ -771,6 +776,20 @@ ul#errors
.error p
text-align: center

p.error
color: red
font-size: 0.8em
padding: 5px
border-radius: 3px
background-color: #FFCD97
display: inline-block
border: 1px solid
margin-left: 5px

.border_error
box-shadow: 0px 0px 5px rgb(255,0,0);
border: 1px solid red !important;

p.no_results
font-size: 0.8em
padding: 20px
Expand Down Expand Up @@ -840,3 +859,5 @@ article#creativos
width: 100%
padding: 10px

.first
float: left !important

0 comments on commit 1e2760c

Please sign in to comment.