Skip to content

Instantly share code, notes, and snippets.

@marti1125
Created June 24, 2013 19:33
Show Gist options
  • Save marti1125/5852824 to your computer and use it in GitHub Desktop.
Save marti1125/5852824 to your computer and use it in GitHub Desktop.
backbone form collection
var tipoeventualidad = Backbone.Model.extend({
toString: function(){ return this.get("descripcion"); }
});
var tipoeventualidadesCollection = Backbone.Collection.extend({
model: tipoeventualidad,
url: 'tipoeventualidades/listaporasignarconceptoplanilla'
});
var collectionEvent = new tipoeventualidadesCollection();
var Evento = Backbone.Model.extend({
schema: {
Eventualidades: { type: 'Select', options: collectionEvent , editorClass: 'listevent' }
}
});
var evento = new Evento();
var FormView = Backbone.View.extend({
events: {
"click a#saveButton": "saveForm"
},
initialize: function() {
this.model = evento;
this.collection = new tipoeventualidadesCollection();
this.collection.bind('reset', this.render);
},
render: function() {
var $button = $('<a href="#" class="btn btn-primary right" id="saveButton">Agregar</a>');
this.form = new Backbone.Form({
model: this.model
});
this.$el.append($button);
this.$el.append(this.form.render().el);
return this;
},
renderNew: function(newModel) {
new FormView({ model:newModel }).render();
return this;
},
saveForm: function() {
$.get('TipoEventualidades/AgregarEventualidad' , { idConceptoDePlanilla: id, idTipoEventualidad: parseInt($('#c15_Eventualidades :selected').val()) }, function(data) {
collection.fetch({reset: true});
collectionEvent.fetch({reset: true});
collectionEvent.fetch();
//collection.bind('reset', this.renderNew, this);
});
}
});
var formView = (new FormView).render();
$('.listevent').append(formView.el);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment