Created
February 9, 2013 00:00
-
-
Save adatta02/4743002 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Language = Backbone.Model.extend({ | |
defaults: function() { | |
return { | |
languageName: "", | |
}; | |
}, | |
initialize: function() { | |
}, | |
save: function() { | |
LanguagesCollection.at(0).save(); | |
}, | |
destroy: function(options) { | |
options = options ? _.clone(options) : {}; | |
var model = this; | |
var success = options.success; | |
model.trigger('destroy', model, model.collection, options); | |
LanguagesCollection.at(0).save(); | |
} | |
}); | |
var LanguageList = Backbone.Collection.extend({ | |
model: Language, | |
}); | |
var LanguageCollection = Backbone.Model.extend({ | |
defaults: function() { | |
return { | |
languages: new LanguageList() | |
}; | |
}, | |
parse: function(response) { } | |
}); | |
var LanguageCollectionList = Backbone.Collection.extend({ | |
model: LanguageCollection, | |
}); | |
var LanguageView = Backbone.View.extend({ | |
tagName: "div", | |
template: _.template($('#language-item-template').html()), | |
initialize: function() { | |
this.model.bind('change', this.render, this); | |
this.model.bind('destroy', this.remove, this); | |
}, | |
}); | |
var LanguagesAppView = Backbone.View.extend({ | |
el: $("#languageList"), | |
initialize: function() { | |
LanguagesCollection.add([{}]); | |
LanguagesCollection.at(0).get("languages").bind('add', this.addOne, this); | |
LanguagesCollection.at(0).get("languages").bind('all', this.render, this); | |
}, | |
addOne: function(loc) { | |
var v = new LanguageView({ | |
model: loc | |
}); | |
this.$el.append(v.render().el); | |
} | |
}); | |
LanguagesCollection = new LanguageCollectionList(); | |
var LanguagesAppView = new LanguagesAppView; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment