Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var NotesApp = (function() {
- var App = {
- stores: {}, views: {}
- }
- App.stores.notes = new Store('notes');
- // Note Model
- var Note = Backbone.Model.extend({
- //Local Storage
- localStorage: App.stores.notes,
- initialize: function(){
- if(!this.get('title')){
- this.set({title: "Note at " + Date() })
- };
- if(!this.get('body')){
- this.set({body: "No Body"})
- };
- }
- })
- //Views
- var NewFormView = Backbone.View.extend({
- events: {
- "submit form": "createNote"
- },
- createNote: function(e){
- var attrs = this.getAttributes(),
- note = new Note();
- note.set(attrs);
- note.save();
- },
- getAttributes: function(){
- return {
- title: this.$('form [name=title]').val(),
- body: this.$('form [name=body]').val()
- }
- }
- });
- window.Note = Note;
- $(document).ready(function(){
- App.views.new_form = new NewFormView({
- el: $('#new')
- });
- })
- return App
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement