Skip to content

Instantly share code, notes, and snippets.

@marti1125
Last active January 4, 2016 15:29
Show Gist options
  • Save marti1125/8641153 to your computer and use it in GitHub Desktop.
Save marti1125/8641153 to your computer and use it in GitHub Desktop.
backbone get hours
// Horarios
Horario = Backbone.Model.extend({});
HorarioCollection = Backbone.Collection.extend({
model: Horario,
url: 'js/horarios_domingo_y_feriados.json',
initialize: function(estacionNumero) {
this.estacion = estacionNumero;
},
parse: function(response) {
//console.log(JSON.stringify(response[this.estacion]))
return response[this.estacion];
}
});
HorarioView = Backbone.View.extend({
events: {
"click #settings-btn": "cerrarHorario"
},
cerrarHorario: function(){
$('#settings-view').removeClass('subir');
$('#settings-view').addClass('bajar');
},
initialize: function(){
this.template = _.template( $("#HorarioView").html() );
},
render: function () {
console.log(JSON.stringify(this.collection))
this.$el.html(this.template({ horarios: this.collection.toJSON() }));
return this;
}
});
events: {
"click #IdEstacion": "obtenerHorario"
},
obtenerHorario: function(ev){
$("#settings-view").removeClass("bajar");
$("#settings-view").addClass("subir");
var estacion = $(ev.currentTarget).text().replace("Estación ","").trim();
var value = $(ev.currentTarget).data("value");
var horarioCollection = new HorarioCollection(value);
var horarioView = new HorarioView({collection: horarioCollection});
horarioCollection.fetch({reset: true});
horarioCollection.bind('reset', function () {
$("#horarios-page").append(horarioView.render().$el);
});
var dia = new Date();
var n = dia.getDay();
$("#tituloNombreEstacion").html(" Estación " + estacion);
/*if(n == 0){
$("#horariosDiaSemana").html("Domingos y Feriados");
}
if(n == 1 || n == 2 || n == 3 || n == 4 || n == 5){
$("#horariosDiaSemana").html("Lunes - Viernes");
}
if(n == 6){
$("#horariosDiaSemana").html("Sabados");
}*/
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment